# HG changeset patch # User John W. Eaton # Date 1317108168 14400 # Node ID 1bfca2bbea8b8d50976723c2dd3c5902508b774d # Parent 8bb526fb3349dafba5c47ea11fd44094b210e98d fix parsing of anonymous functions inside cell array lists. * lex.h (lexer_flags::looking_at_anon_fcn_args): New data member. (lexer_flags::lexer_flags): Initialize it. Initialize looking_at_function_handle to 0, not false. * lex.ll (lexer_flags::init): Reset looking_at_anon_fcn_args to 0. * oct-parse.yy (param_list_beg): Set lexer_flags.looking_at_anon_fcn_args to true if lexer_flags.looking_at_function_handle is non-zero. (")"): Set lexer_flags.looking_at_anon_fcn_args to false. * test_parser.m: New tests. diff -r 8bb526fb3349 -r 1bfca2bbea8b src/lex.h --- a/src/lex.h Tue Sep 27 02:06:41 2011 -0400 +++ b/src/lex.h Tue Sep 27 03:22:48 2011 -0400 @@ -60,7 +60,8 @@ : bracketflag (0), braceflag (0), looping (0), convert_spaces_to_comma (true), at_beginning_of_statement (true), - defining_func (0), looking_at_function_handle (false), + defining_func (0), looking_at_function_handle (0), + looking_at_anon_fcn_args (true), looking_at_return_list (false), looking_at_parameter_list (false), looking_at_decl_list (false), looking_at_initializer_expression (false), looking_at_matrix_or_assign_lhs (false), looking_at_object_index (), @@ -101,6 +102,9 @@ // Nonzero means we are parsing a function handle. int looking_at_function_handle; + // TRUE means we are parsing an anonymous function argument list. + bool looking_at_anon_fcn_args; + // TRUE means we're parsing the return list for a function. bool looking_at_return_list; diff -r 8bb526fb3349 -r 1bfca2bbea8b src/lex.ll --- a/src/lex.ll Tue Sep 27 02:06:41 2011 -0400 +++ b/src/lex.ll Tue Sep 27 03:22:48 2011 -0400 @@ -976,10 +976,15 @@ lexer_flags.looking_at_object_index.pop_front (); lexer_flags.quote_is_transpose = true; - lexer_flags.convert_spaces_to_comma = nesting_level.is_bracket_or_brace (); + lexer_flags.convert_spaces_to_comma + = (nesting_level.is_bracket_or_brace () + && ! lexer_flags.looking_at_anon_fcn_args); lexer_flags.looking_for_object_index = true; lexer_flags.at_beginning_of_statement = false; + if (lexer_flags.looking_at_anon_fcn_args) + lexer_flags.looking_at_anon_fcn_args = false; + do_comma_insert_check (); COUNT_TOK_AND_RETURN (')'); @@ -3368,6 +3373,9 @@ // Not initiallly looking at a function handle. looking_at_function_handle = 0; + // Not initiallly looking at an anonymous function argument list. + looking_at_anon_fcn_args = 0; + // Not parsing a function return, parameter, or declaration list. looking_at_return_list = false; looking_at_parameter_list = false; diff -r 8bb526fb3349 -r 1bfca2bbea8b src/oct-parse.yy --- a/src/oct-parse.yy Tue Sep 27 02:06:41 2011 -0400 +++ b/src/oct-parse.yy Tue Sep 27 03:22:48 2011 -0400 @@ -735,7 +735,10 @@ ; anon_fcn_handle : '@' param_list statement - { $$ = make_anon_fcn_handle ($2, $3); } + { + lexer_flags.quote_is_transpose = false; + $$ = make_anon_fcn_handle ($2, $3); + } ; primary_expr : identifier @@ -1230,6 +1233,7 @@ symtab_context.push (symbol_table::current_scope ()); symbol_table::set_scope (symbol_table::alloc_scope ()); lexer_flags.looking_at_function_handle--; + lexer_flags.looking_at_anon_fcn_args = true; } } ; diff -r 8bb526fb3349 -r 1bfca2bbea8b test/test_parser.m --- a/test/test_parser.m Tue Sep 27 02:06:41 2011 -0400 +++ b/test/test_parser.m Tue Sep 27 03:22:48 2011 -0400 @@ -247,3 +247,10 @@ %! assert (a += b *= c += 1, 42) %! assert (b == 40 && c == 8) +%!test +%! af_in_cell = {@(x) [1 2]}; +%! assert (af_in_cell{1}(), [1, 2]); + +%!test +%! R = @(rot) [cos(rot) -sin(rot); sin(rot) cos(rot)]; +%! assert (R(pi/2), [cos(pi/2), -sin(pi/2); sin(pi/2),cos(pi/2)]);