From e306f833d0da3644460a28a0d9bc7f3eea37a584 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sat, 20 Feb 2016 10:18:25 -0500 Subject: Fix command separation `foo bar ( baz )` no longer gets parsed as `foo bar` and `( baz )`. Also restrict function names. --- diff --git a/parsing/parse.sh b/parsing/parse.sh index 66506b4..6f3018e 100644 --- a/parsing/parse.sh +++ b/parsing/parse.sh @@ -29,10 +29,8 @@ list() { dbg 'list()' if and_or; then - while separator_op; do - if ! and_or; then - return 1 - fi + while separator && and_or; do + : done return 0 fi @@ -291,6 +289,7 @@ until_clause() function_body() { + dbg 'function_body()' if compound_command; then redirect_list fi @@ -323,7 +322,7 @@ simple_command() cmd_suffix fi return 0 - elif cmd_name; then + elif accept T_FNAME; then if accept T_LPAREN; then expect T_RPAREN if linebreak && function_body; then @@ -333,6 +332,9 @@ simple_command() cmd_suffix return 0 fi + elif cmd_name; then + cmd_suffix + return 0 fi return 1 } @@ -359,6 +361,7 @@ cmd_word() cmd_prefix() { + dbg 'cmd_prefix()' if io_redirect || accept T_ASSIGNMENT_WORD; then while io_redirect || accept T_ASSIGNMENT_WORD; do : @@ -370,6 +373,7 @@ cmd_prefix() cmd_suffix() { + dbg 'cmd_suffix()' if io_redirect || accept T_WORD; then while io_redirect || accept T_WORD; do : @@ -381,6 +385,7 @@ cmd_suffix() redirect_list() { + dbg 'redirect_list()' if io_redirect; then while io_redirect; do : @@ -392,6 +397,7 @@ redirect_list() io_redirect() { + dbg 'io_redirect()' if io_file || io_here; then return 0 fi @@ -492,9 +498,10 @@ parse() init_lexer "${fn}" # If this returns (does not exit), there are no errors. - while ! accept T_EOF; do - complete_command - done + complete_command + if ! accept T_EOF; then + synexp '' + fi get_tokens @@ -541,5 +548,6 @@ try() #try 'if ; then ; fi' #try 'while foo; do bar; done' #try 'while ; do ; done' -try 'foo(){ bar; }' +#try 'foo(){ bar; }' #try 'case foo in bar) baz;; (qux) quux;; quux);; esac' +try 'foo bar ( baz )' -- cgit v0.9.1