changeset 17283:e6c0ac8ce5b6

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.
author John W. Eaton <jwe@octave.org>
date Tue, 20 Aug 2013 06:42:54 -0400
parents a69dd4b0e571
children c8f94d9d34d0
files libinterp/parse-tree/oct-parse.in.yy libinterp/parse-tree/parse.h test/try.tst
diffstat 3 files changed, 49 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- 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 <tree_expression_type> matrix cell
 %type <tree_expression_type> primary_expr oper_expr
 %type <tree_expression_type> simple_expr colon_expr assign_expr expression
-%type <tree_identifier_type> identifier fcn_name magic_tilde opt_identifier
+%type <tree_identifier_type> identifier fcn_name magic_tilde
 %type <tree_identifier_type> superclass_identifier meta_identifier
 %type <octave_user_function_type> function1 function2 classdef1
 %type <tree_index_expression_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<tree_identifier *> (expr);
+
+                  cleanup_stmts->pop_front ();
+                }
+            }
+        }
+
       retval = new tree_try_catch_command (body, cleanup_stmts, id,
                                            lc, mc, tc, l, c);
     }
--- 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 *
--- 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