From 8f87f7dffaf23b83c22234274de45ce0bc49d20f Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 4 Nov 2018 19:33:57 +0100 Subject: [PATCH] Support io-here. --- gash/peg.scm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gash/peg.scm b/gash/peg.scm index db9881e..a65dcb2 100644 --- a/gash/peg.scm +++ b/gash/peg.scm @@ -170,7 +170,7 @@ function-body <- compound-command io-redirect* io-redirect <-- [0-9]* sp* (io-here / io-file) - io-file <-- ('<&' / '>&' / '>>' / '>' / '<>'/ '<' / '>|') sp* ([0-9]+ / filename) + io-file <-- ('<&' / '>&' / '>>' / '>' / '<>'/ '<' / '>|') sp* ([0-9]+ / file-name) io-here <- ('<<' / '<<-') io-suffix here-document io-op < '<<-' / '<<' / '<&' / '>&' / '>>' / '>' / '<>'/ '<' / '>|' io-suffix <- sp* here-label sp* nl @@ -209,7 +209,7 @@ until-keyword < 'until' until-clause <-- until-keyword ws* compound-list separator do-group - filename <-- word + file-name <-- word name <-- identifier identifier <- [_a-zA-Z][_a-zA-Z0-9]* word <-- assignment / (delim / number / variable / variable-and-or / literal)+ @@ -304,6 +304,9 @@ (('pipeline ('command command ('io-redirect ('io-file ">" file-name)))) (transform `(pipeline (command ,@(transform command)) (lambda _ (with-output-to-file ,(transform file-name) (lambda _ (display (read-string)))))))) + (('pipeline ('command command ('io-redirect "<<" ('here-document here-document)))) + (transform `(pipeline (lambda _ (display ,here-document)) (command ,(transform command))))) + (('pipeline o ...) (let ((commands (map transform o))) `(pipeline ,@(cons (trace commands) commands))))