Mercurial > hg > octave-lojdl
changeset 13237:1bfca2bbea8b
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.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 27 Sep 2011 03:22:48 -0400 |
parents | 8bb526fb3349 |
children | 7467e90271f4 |
files | src/lex.h src/lex.ll src/oct-parse.yy test/test_parser.m |
diffstat | 4 files changed, 26 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lex.h +++ b/src/lex.h @@ -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;
--- a/src/lex.ll +++ b/src/lex.ll @@ -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;
--- a/src/oct-parse.yy +++ b/src/oct-parse.yy @@ -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; } } ;
--- a/test/test_parser.m +++ b/test/test_parser.m @@ -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)]);