nesting delimited

This commit is contained in:
Rutger van Beusekom 2016-09-19 22:07:46 +02:00
parent d1c268cd6a
commit 8b1a499d74
5 changed files with 17 additions and 4 deletions

View File

@ -102,7 +102,13 @@ copyleft.
(('simple-command ('word s)) (list (transform s)))
(('simple-command ('word s1) ('word s2)) (list (transform s1) (transform s2)))
(('simple-command ('word s1) (('word s2) ...)) (cons (transform s1) (map transform s2)))
(('literal s) s)
(('literal s) (transform s))
(('singlequotes s) (string-concatenate (list "'" s "'")))
(('doublequotes s) (string-concatenate (list "\"" s "\"")))
(('backticks s) (string-concatenate (list "`" s "`")))
(('delim ('singlequotes s ...)) (string-concatenate (map transform s)))
(('delim ('doublequotes s ...)) (string-concatenate (map transform s)))
(('delim ('backticks s ...)) (string-concatenate (map transform s)))
((('pipe _) command ...) (map transform command))
(((('pipe _) command) ...) (map transform command))
((_ o) (transform o))

View File

@ -64,7 +64,13 @@
assign < '='
literal <-- (subst / delim / (![0-9] (![()] !io-op !sp !nl !break !pipe !assign .)+) / ([0-9]+ &separator)) literal*
subst <-- '$' ('$' / '*' / '@' / [0-9] / identifier / ([{] (![}] .)+ [}]))
delim <- (['] (!['] .)* [']) / ([\"] (![\"] .)* [\"]) / ([`] (![`] .)* [`])
delim <-- singlequotes / doublequotes / backticks
sq < [']
dq < [\"]
bt < [`]
singlequotes <-- (sq (doublequotes / backticks / (!sq .))* sq)
doublequotes <-- (dq (singlequotes / backticks / (!dq .))* dq)
backticks <-- (bt (singlequotes / doublequotes / (!bt .))* bt)
separator <-- (sp* break !semi ws*) / ws*
break <-- amp / semi
sequential-sep <-- (semi ws*) / ws+

1
test/nesting Normal file
View File

@ -0,0 +1 @@
echo 'foo "bar"'

View File

@ -1 +1 @@
echo a b c | grep -v a | cat
echo -e 'a\nb\nc' | grep -v b | cat

View File

@ -1 +1 @@
$(ls)
echo "$(ls)"