case support
This commit is contained in:
parent
9795722992
commit
cb204e16c0
16
sh/peg.scm
16
sh/peg.scm
|
@ -31,8 +31,9 @@
|
||||||
compound-command <-- brace-group / subshell / for-clause / case-clause / if-clause / while-clause / until-clause
|
compound-command <-- brace-group / subshell / for-clause / case-clause / if-clause / while-clause / until-clause
|
||||||
subshell <-- '(' compound-list ')'
|
subshell <-- '(' compound-list ')'
|
||||||
compound-list <-- ws* term (separator term)* separator?
|
compound-list <-- ws* term (separator term)* separator?
|
||||||
case-clause <-- 'case' sp+ word ws* 'in' ws* (case-item sp)* 'esac'
|
case-clause <-- 'case' sp+ word ws+ 'in' ws+ case-item* 'esac'
|
||||||
case-item <-- '('? sp* pattern sp* ')' ((ws ';;' ws) / ((compound-list sp* ';;'?)? ws))
|
case-item <-- sp* pattern sp* ')' compound-list? ws* case-sep ws
|
||||||
|
case-sep < ';;'
|
||||||
pattern <-- word (sp* '|' sp* word)*
|
pattern <-- word (sp* '|' sp* word)*
|
||||||
for-clause <-- 'for' sp+ identifier ws+ ('in' (sp+ word)* sp* sequential-sep)? do-group
|
for-clause <-- 'for' sp+ identifier ws+ ('in' (sp+ word)* sp* sequential-sep)? do-group
|
||||||
do-group <-- 'do' compound-list 'done'
|
do-group <-- 'do' compound-list 'done'
|
||||||
|
@ -53,7 +54,8 @@
|
||||||
filename <-- word
|
filename <-- word
|
||||||
name <-- identifier
|
name <-- identifier
|
||||||
identifier <- [_a-zA-Z][_a-zA-Z0-9]*
|
identifier <- [_a-zA-Z][_a-zA-Z0-9]*
|
||||||
word <-- test / substitution / assignment / literal
|
word <-- test / substitution / assignment / literal / number
|
||||||
|
number <-- [0-9]+
|
||||||
test <-- ltest (!rtest .)* rtest
|
test <-- ltest (!rtest .)* rtest
|
||||||
ltest < '[ '
|
ltest < '[ '
|
||||||
rtest < ' ]'
|
rtest < ' ]'
|
||||||
|
@ -63,9 +65,10 @@
|
||||||
literal <-- (subst / delim / (![0-9] (![()] !io-op !sp !nl !break !pipe !assign .)+) / ([0-9]+ &separator)) literal*
|
literal <-- (subst / delim / (![0-9] (![()] !io-op !sp !nl !break !pipe !assign .)+) / ([0-9]+ &separator)) literal*
|
||||||
subst <-- '$' ('$' / '*' / '@' / [0-9] / identifier / ([{] (![}] .)+ [}]))
|
subst <-- '$' ('$' / '*' / '@' / [0-9] / identifier / ([{] (![}] .)+ [}]))
|
||||||
delim <- (['] (!['] .)* [']) / ([\"] (![\"] .)* [\"]) / ([`] (![`] .)* [`])
|
delim <- (['] (!['] .)* [']) / ([\"] (![\"] .)* [\"]) / ([`] (![`] .)* [`])
|
||||||
separator <-- (sp* break ws*) / ws*
|
separator <-- (sp* break !semi ws*) / ws*
|
||||||
break <-- '&' / ';'
|
break <-- amp / semi
|
||||||
sequential-sep <-- (semi ws*) / ws+
|
sequential-sep <-- (semi ws*) / ws+
|
||||||
|
amp < '&'
|
||||||
semi < ';'
|
semi < ';'
|
||||||
nl < '\n'
|
nl < '\n'
|
||||||
sp < [\t ]
|
sp < [\t ]
|
||||||
|
@ -77,7 +80,8 @@
|
||||||
(let ((tree (peg:tree match)))
|
(let ((tree (peg:tree match)))
|
||||||
(pretty-print (peg:tree match))
|
(pretty-print (peg:tree match))
|
||||||
(pretty-print "parse error" (current-error-port))
|
(pretty-print "parse error" (current-error-port))
|
||||||
(pretty-print (peg:end match)))
|
(pretty-print (peg:end match))
|
||||||
|
#f)
|
||||||
(peg:tree match))))
|
(peg:tree match))))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue