# HG changeset patch # User John W. Eaton # Date 1363026639 14400 # Node ID 36e01847694fe8f95da4a82e8147fd76d2f1a426 # Parent 6077d13ddb3bc284017be59110ad644ee52198d3# Parent 71ee3afedb694ab9dd886960bf2f7cc4b9c5a379 maint: periodic merge of default to classdef diff --git a/libinterp/parse-tree/lex.h b/libinterp/parse-tree/lex.h --- a/libinterp/parse-tree/lex.h +++ b/libinterp/parse-tree/lex.h @@ -73,7 +73,8 @@ { BRACKET = 1, BRACE = 2, - PAREN = 3 + PAREN = 3, + ANON_FCN_BODY = 4 }; public: @@ -119,6 +120,13 @@ return ! context.empty () && context.top () == PAREN; } + void anon_fcn_body (void) { context.push (ANON_FCN_BODY); } + + bool is_anon_fcn_body (void) + { + return ! context.empty () && context.top () == ANON_FCN_BODY; + } + bool is_bracket_or_brace (void) { return (! context.empty () @@ -393,8 +401,8 @@ // set of identifiers that might be local variable names. std::set pending_local_variables; - // is the closest nesting level a square bracket, squiggly brace or - // a paren? + // is the closest nesting level a square bracket, squiggly brace, + // a paren, or an anonymous function body? bbp_nesting_level nesting_level; // Tokens generated by the lexer. diff --git a/libinterp/parse-tree/lex.ll b/libinterp/parse-tree/lex.ll --- a/libinterp/parse-tree/lex.ll +++ b/libinterp/parse-tree/lex.ll @@ -821,7 +821,14 @@ "||" { return curr_lexer->handle_op ("||", EXPR_OR_OR); } "<<" { return curr_lexer->handle_incompatible_op ("<<", LSHIFT); } ">>" { return curr_lexer->handle_incompatible_op (">>", RSHIFT); } -";" { return curr_lexer->handle_op (";", ';', true, true); } + +";" { + bool at_beginning_of_statement + = (! (curr_lexer->whitespace_is_significant () + || curr_lexer->looking_at_object_index.front ())); + + return curr_lexer->handle_op (";", ';', true, at_beginning_of_statement); + } "+" { int tok = curr_lexer->handle_unary_op ("+", '+'); @@ -887,8 +894,12 @@ } "," { + bool at_beginning_of_statement + = (! (curr_lexer->whitespace_is_significant () + || curr_lexer->looking_at_object_index.front ())); + return curr_lexer->handle_op - (",", ',', true, ! curr_lexer->looking_at_object_index.front ()); + (",", ',', true, at_beginning_of_statement); } ".'" { @@ -974,7 +985,10 @@ curr_lexer->at_beginning_of_statement = false; if (curr_lexer->looking_at_anon_fcn_args) - curr_lexer->looking_at_anon_fcn_args = false; + { + curr_lexer->looking_at_anon_fcn_args = false; + curr_lexer->nesting_level.anon_fcn_body (); + } return curr_lexer->count_token (')'); } diff --git a/libinterp/parse-tree/oct-parse.in.yy b/libinterp/parse-tree/oct-parse.in.yy --- a/libinterp/parse-tree/oct-parse.in.yy +++ b/libinterp/parse-tree/oct-parse.in.yy @@ -542,7 +542,10 @@ ; anon_fcn_handle : '@' param_list statement - { $$ = curr_parser.make_anon_fcn_handle ($2, $3); } + { + $$ = curr_parser.make_anon_fcn_handle ($2, $3); + curr_lexer->nesting_level.remove (); + } ; primary_expr : identifier