Mercurial > hg > octave-nkf
diff libinterp/parse-tree/oct-parse.in.yy @ 16681:d3619d4d267c
recognize character string at beginning of statement (bug #38926, #38958)
* lex.ll ("'"): Always begin a character string if at the beginning of
a statement.
* oct-parse.in.yy (stmt_begin): New non-terminal.
(anon_fcn_handle, if_cmd_list1, elseif_clause, switch_case,
loop_command): Use it.
* pt-fcn-handle.cc, for.tst, if.tst, switch.tst, while.tst:
New tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 18 May 2013 16:21:32 -0400 |
parents | de91b1621260 |
children | e1c6ad54259f 2f63d2f3ff11 |
line wrap: on
line diff
--- a/libinterp/parse-tree/oct-parse.in.yy +++ b/libinterp/parse-tree/oct-parse.in.yy @@ -488,9 +488,9 @@ } ; -anon_fcn_handle : '@' param_list statement +anon_fcn_handle : '@' param_list stmt_begin statement { - $$ = parser.make_anon_fcn_handle ($2, $3); + $$ = parser.make_anon_fcn_handle ($2, $4); lexer.nesting_level.remove (); } ; @@ -831,11 +831,11 @@ } ; -if_cmd_list1 : expression opt_sep opt_list +if_cmd_list1 : expression stmt_begin opt_sep opt_list { $1->mark_braindead_shortcircuit (lexer.fcn_file_full_name); - $$ = parser.start_if_command ($1, $3); + $$ = parser.start_if_command ($1, $4); } | if_cmd_list1 elseif_clause { @@ -844,11 +844,11 @@ } ; -elseif_clause : ELSEIF stash_comment opt_sep expression opt_sep opt_list +elseif_clause : ELSEIF stash_comment opt_sep expression stmt_begin opt_sep opt_list { $4->mark_braindead_shortcircuit (lexer.fcn_file_full_name); - $$ = parser.make_elseif_clause ($1, $4, $6, $2); + $$ = parser.make_elseif_clause ($1, $4, $7, $2); } ; @@ -889,8 +889,8 @@ } ; -switch_case : CASE stash_comment opt_sep expression opt_sep opt_list - { $$ = parser.make_switch_case ($1, $4, $6, $2); } +switch_case : CASE stash_comment opt_sep expression stmt_begin opt_sep opt_list + { $$ = parser.make_switch_case ($1, $4, $7, $2); } ; default_case : OTHERWISE stash_comment opt_sep opt_list @@ -903,11 +903,11 @@ // Looping // ======= -loop_command : WHILE stash_comment expression opt_sep opt_list END +loop_command : WHILE stash_comment expression stmt_begin opt_sep opt_list END { $3->mark_braindead_shortcircuit (lexer.fcn_file_full_name); - if (! ($$ = parser.make_while_command ($1, $3, $5, $6, $2))) + if (! ($$ = parser.make_while_command ($1, $3, $6, $7, $2))) ABORT_PARSE; } | DO stash_comment opt_sep opt_list UNTIL expression @@ -915,10 +915,10 @@ if (! ($$ = parser.make_do_until_command ($5, $4, $6, $2))) ABORT_PARSE; } - | FOR stash_comment assign_lhs '=' expression opt_sep opt_list END + | FOR stash_comment assign_lhs '=' expression stmt_begin opt_sep opt_list END { if (! ($$ = parser.make_for_command (FOR, $1, $3, $5, 0, - $7, $8, $2))) + $8, $9, $2))) ABORT_PARSE; } | FOR stash_comment '(' assign_lhs '=' expression ')' opt_sep opt_list END @@ -927,10 +927,10 @@ $9, $10, $2))) ABORT_PARSE; } - | PARFOR stash_comment assign_lhs '=' expression opt_sep opt_list END + | PARFOR stash_comment assign_lhs '=' expression stmt_begin opt_sep opt_list END { if (! ($$ = parser.make_for_command (PARFOR, $1, $3, $5, - 0, $7, $8, $2))) + 0, $8, $9, $2))) ABORT_PARSE; } | PARFOR stash_comment '(' assign_lhs '=' expression ',' expression ')' opt_sep opt_list END @@ -1406,6 +1406,10 @@ // Miscellaneous // ============= +stmt_begin : // empty + { lexer.at_beginning_of_statement = true; } + ; + stash_comment : // empty { $$ = octave_comment_buffer::get_comment (); } ;