aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMu Qiao <qiaomuf@gentoo.org>2011-07-22 21:16:45 +0800
committerMu Qiao <qiaomuf@gentoo.org>2011-08-02 15:52:18 +0800
commitf3e50b21917905fa908000a9bcb8f2fdff451f63 (patch)
treec22316bcf9f1cc59171ee8fe69a48e46458f43ae
parentParser: allow white spaces around array index (diff)
downloadlibbash-f3e50b21917905fa908000a9bcb8f2fdff451f63.tar.gz
libbash-f3e50b21917905fa908000a9bcb8f2fdff451f63.tar.bz2
libbash-f3e50b21917905fa908000a9bcb8f2fdff451f63.zip
Parser: improve here document and here string
Here document and here string can be combined with bash redirection. Now this is supported.
-rw-r--r--bashast/bashast.g6
-rw-r--r--bashast/gunit/redir.gunit5
2 files changed, 8 insertions, 3 deletions
diff --git a/bashast/bashast.g b/bashast/bashast.g
index a6b2e59..39e6d54 100644
--- a/bashast/bashast.g
+++ b/bashast/bashast.g
@@ -255,7 +255,8 @@ redirection
: redirection_atom+;
redirection_atom
: redirection_operator BLANK? redirection_destination -> ^(REDIR redirection_operator redirection_destination)
- | BLANK!? process_substitution;
+ | BLANK!? process_substitution
+ | here_string;
process_substitution
: (dir=LESS_THAN|dir=GREATER_THAN)LPAREN BLANK* command_list BLANK* RPAREN
@@ -339,9 +340,8 @@ redirection_operator
command
: command_atom
(
- redirection -> ^(COMMAND command_atom redirection)
+ redirection here_document? -> ^(COMMAND command_atom redirection here_document?)
| here_document -> ^(COMMAND command_atom here_document)
- | here_string -> ^(COMMAND command_atom here_string)
| -> ^(COMMAND command_atom)
);
diff --git a/bashast/gunit/redir.gunit b/bashast/gunit/redir.gunit
index 882290f..d6aa599 100644
--- a/bashast/gunit/redir.gunit
+++ b/bashast/gunit/redir.gunit
@@ -28,6 +28,7 @@ redirection:
"< this.is.1input" -> (REDIR < (STRING this . is . 1 input))
" 3< \"input from file\"" -> (REDIR 3 < (STRING (DOUBLE_QUOTED_STRING input from file)))
" 2<&0" -> (REDIR 2 <& (FILE_DESCRIPTOR 0))
+"<<<\"#include <pthread.h>\" >& /dev/null" -> (<<< (STRING (DOUBLE_QUOTED_STRING # include < pthread . h >))) (REDIR >& (STRING / dev / null))
here_string:
"<<< herestring" -> (<<< (STRING herestring))
@@ -47,3 +48,7 @@ _EOF_.abc
" -> (LIST (COMMAND (STRING cat) (<< (STRING blah
blah
) (REDIR > (STRING / dev / null)))))
+"cat > /dev/null <<-END_LDSCRIPT
+GNU...
+END_LDSCRIPT" -> (LIST (COMMAND (STRING cat) (REDIR > (STRING / dev / null)) (<<- (STRING GNU .. .
+))))