# HG changeset patch # User John W. Eaton # Date 1376995374 14400 # Node ID e6c0ac8ce5b67c0f18a695ff29bd48a93572c641 # Parent a69dd4b0e5713e714cad7984175763f90de392d0 eliminate parse conflicts introduced by changeset 923ce8b42db2 * oct-parse.in.yy (opt_identifier): Delete. (TRY): Simplify grammar. (octave_base_parser::make_try_command): Pass separator token instead of exception identifier. Handle exception identifier here based on context instead of in grammar rules. * parse.h (octave_base_parser::make_try_command): Fix decl. * try.tst: New tests. diff -r a69dd4b0e571 -r e6c0ac8ce5b6 libinterp/parse-tree/oct-parse.in.yy --- a/libinterp/parse-tree/oct-parse.in.yy Mon Aug 19 22:24:05 2013 -0700 +++ b/libinterp/parse-tree/oct-parse.in.yy Tue Aug 20 06:42:54 2013 -0400 @@ -240,7 +240,7 @@ %type matrix cell %type primary_expr oper_expr %type simple_expr colon_expr assign_expr expression -%type identifier fcn_name magic_tilde opt_identifier +%type identifier fcn_name magic_tilde %type superclass_identifier meta_identifier %type function1 function2 classdef1 %type word_list_cmd @@ -975,15 +975,10 @@ if (! ($$ = parser.make_unwind_command ($1, $4, $8, $9, $2, $6))) ABORT_PARSE; } - | TRY stash_comment opt_sep opt_list CATCH list END + | TRY stash_comment opt_sep opt_list CATCH stash_comment + opt_sep opt_list END { - if (! ($$ = parser.make_try_command ($1, $4, $6, 0, $7, $2, 0))) - ABORT_PARSE; - } - | TRY stash_comment opt_sep opt_list CATCH opt_identifier - stash_comment opt_sep opt_list END - { - if (! ($$ = parser.make_try_command ($1, $4, $9, $6, $10, $2, $7))) + if (! ($$ = parser.make_try_command ($1, $4, $7, $8, $9, $2, $6))) ABORT_PARSE; } | TRY stash_comment opt_sep opt_list END @@ -993,12 +988,6 @@ } ; -opt_identifier: // empty - { $$ = 0; } - | identifier sep - { $$ = $1; } - ; - // =========================================== // Some 'subroutines' for function definitions // =========================================== @@ -2201,8 +2190,8 @@ tree_command * octave_base_parser::make_try_command (token *try_tok, tree_statement_list *body, + char catch_sep, tree_statement_list *cleanup_stmts, - tree_identifier *id, token *end_tok, octave_comment_list *lc, octave_comment_list *mc) @@ -2216,6 +2205,25 @@ int l = try_tok->line (); int c = try_tok->column (); + tree_identifier *id = 0; + + if (! catch_sep && cleanup_stmts && ! cleanup_stmts->empty ()) + { + tree_statement *stmt = cleanup_stmts->front (); + + if (stmt) + { + tree_expression *expr = stmt->expression (); + + if (expr && expr->is_identifier ()) + { + id = dynamic_cast (expr); + + cleanup_stmts->pop_front (); + } + } + } + retval = new tree_try_catch_command (body, cleanup_stmts, id, lc, mc, tc, l, c); } diff -r a69dd4b0e571 -r e6c0ac8ce5b6 libinterp/parse-tree/parse.h --- a/libinterp/parse-tree/parse.h Mon Aug 19 22:24:05 2013 -0700 +++ b/libinterp/parse-tree/parse.h Tue Aug 20 06:42:54 2013 -0400 @@ -201,8 +201,9 @@ // Build a try-catch command. tree_command * make_try_command (token *try_tok, tree_statement_list *body, - tree_statement_list *cleanup, tree_identifier *id, token *end_tok, - octave_comment_list *lc, octave_comment_list *mc); + char catch_sep, tree_statement_list *cleanup, + token *end_tok, octave_comment_list *lc, + octave_comment_list *mc); // Build a while command. tree_command * diff -r a69dd4b0e571 -r e6c0ac8ce5b6 test/try.tst --- a/test/try.tst Mon Aug 19 22:24:05 2013 -0700 +++ b/test/try.tst Tue Aug 20 06:42:54 2013 -0400 @@ -158,3 +158,25 @@ %! assert (myerr1.message, myerr2.message); %! assert (myerr1.identifier, myerr2.identifier); %! end_try_catch + +%!test +%! x = 1; +%! try error ("foo"); catch x; assert (x.message, "foo"); end_try_catch + +%!test +%! x = 1; +%! try error ("foo"); catch x end_try_catch +%! assert (x.message, "foo"); + +%!test +%! x = 1; +%! try error ("foo"); catch, x; assert (x, 1); end_try_catch + +%!test +%! x = 1; +%! try error ("foo"); catch; x; assert (x, 1); end_try_catch + +%!test +%! x = 1; +%! try error ("foo"); catch +%! x; assert (x, 1); end_try_catch