# HG changeset patch # User John W. Eaton # Date 1361840804 18000 # Node ID 8d19626b38ae22de6d9a5efab3291fa20c2f66be # Parent 6b26e18d1dcb075d433c84212a98a051b3089c9b provide copy contructor and operator = for lexical_feedback class. * lex.h, lex.ll (lexical_feedback::lexical_feedback): Provide copy constructor. Correctly initialize looking_at_anon_fcn_args to false. (lexical_feedback::operator=): New function. (lexical_feedback::init): Simplify. (reset_parser): Assign new lexical_feedback object to global lexer_flags instead of calling init on existing object. diff -r 6b26e18d1dcb -r 8d19626b38ae libinterp/parse-tree/lex.h --- a/libinterp/parse-tree/lex.h Mon Feb 25 19:45:46 2013 -0500 +++ b/libinterp/parse-tree/lex.h Mon Feb 25 20:06:44 2013 -0500 @@ -24,6 +24,7 @@ #define octave_lex_h 1 #include +#include #include // FIXME -- these input buffer things should be members of a @@ -63,7 +64,7 @@ lexical_feedback (void) : convert_spaces_to_comma (true), do_comma_insert (false), at_beginning_of_statement (true), - looking_at_anon_fcn_args (true), looking_at_return_list (false), + looking_at_anon_fcn_args (false), 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), @@ -74,13 +75,76 @@ looping (0), defining_func (0), looking_at_function_handle (0), looking_at_object_index (), parsed_function_name (), pending_local_variables () - { - init (); - } + { + init (); + } + + lexical_feedback (const lexical_feedback& lf) + : convert_spaces_to_comma (lf.convert_spaces_to_comma), + do_comma_insert (lf.do_comma_insert), + at_beginning_of_statement (lf.at_beginning_of_statement), + looking_at_anon_fcn_args (lf.looking_at_anon_fcn_args), + looking_at_return_list (lf.looking_at_return_list), + looking_at_parameter_list (lf.looking_at_parameter_list), + looking_at_decl_list (lf.looking_at_decl_list), + looking_at_initializer_expression (lf.looking_at_initializer_expression), + looking_at_matrix_or_assign_lhs (lf.looking_at_matrix_or_assign_lhs), + looking_for_object_index (lf.looking_for_object_index), + looking_at_indirect_ref (lf.looking_at_indirect_ref), + parsing_class_method (lf.parsing_class_method), + maybe_classdef_get_set_method (lf.maybe_classdef_get_set_method), + parsing_classdef (lf.parsing_classdef), + quote_is_transpose (lf.quote_is_transpose), + bracketflag (lf.bracketflag), + braceflag (lf.braceflag), + looping (lf.looping), + defining_func (lf.defining_func), + looking_at_function_handle (lf.looking_at_function_handle), + looking_at_object_index (lf.looking_at_object_index), + parsed_function_name (lf.parsed_function_name), + pending_local_variables (lf.pending_local_variables) + { } + + lexical_feedback& operator = (const lexical_feedback& lf) + { + if (&lf != this) + { + convert_spaces_to_comma = lf.convert_spaces_to_comma; + do_comma_insert = lf.do_comma_insert; + at_beginning_of_statement = lf.at_beginning_of_statement; + looking_at_anon_fcn_args = lf.looking_at_anon_fcn_args; + looking_at_return_list = lf.looking_at_return_list; + looking_at_parameter_list = lf.looking_at_parameter_list; + looking_at_decl_list = lf.looking_at_decl_list; + looking_at_initializer_expression = lf.looking_at_initializer_expression; + looking_at_matrix_or_assign_lhs = lf.looking_at_matrix_or_assign_lhs; + looking_for_object_index = lf.looking_for_object_index; + looking_at_indirect_ref = lf.looking_at_indirect_ref; + parsing_class_method = lf.parsing_class_method; + maybe_classdef_get_set_method = lf.maybe_classdef_get_set_method; + parsing_classdef = lf.parsing_classdef; + quote_is_transpose = lf.quote_is_transpose; + bracketflag = lf.bracketflag; + braceflag = lf.braceflag; + looping = lf.looping; + defining_func = lf.defining_func; + looking_at_function_handle = lf.looking_at_function_handle; + looking_at_object_index = lf.looking_at_object_index; + parsed_function_name = lf.parsed_function_name; + pending_local_variables = lf.pending_local_variables; + } + + return *this; + } ~lexical_feedback (void) { } - void init (void); + void init (void) + { + // The closest paren, brace, or bracket nesting is not an object + // index. + looking_at_object_index.push_front (false); + } // TRUE means that we should convert spaces to a comma inside a // matrix definition. @@ -161,12 +225,6 @@ // Set of identifiers that might be local variable names. std::set pending_local_variables; - -private: - - lexical_feedback (const lexical_feedback&); - - lexical_feedback& operator = (const lexical_feedback&); }; class diff -r 6b26e18d1dcb -r 8d19626b38ae libinterp/parse-tree/lex.ll --- a/libinterp/parse-tree/lex.ll Mon Feb 25 19:45:46 2013 -0500 +++ b/libinterp/parse-tree/lex.ll Mon Feb 25 20:06:44 2013 -0500 @@ -1157,7 +1157,7 @@ help_buf.pop (); // Reset other flags. - lexer_flags.init (); + lexer_flags = lexical_feedback (); } static void @@ -3398,79 +3398,6 @@ return NAME; } -void -lexical_feedback::init (void) -{ - // No need to do comma insert or convert spaces to comma at - // beginning of input. - convert_spaces_to_comma = true; - do_comma_insert = false; - - // Yes, we are at the beginning of a statement. - at_beginning_of_statement = true; - - // Not initiallly looking at an anonymous function argument list. - looking_at_anon_fcn_args = false; - - // Not parsing a function return, parameter, or declaration list. - looking_at_return_list = false; - looking_at_parameter_list = false; - looking_at_decl_list = false; - - // Not looking at an argument list initializer expression. - looking_at_initializer_expression = false; - - // Not parsing a matrix or the left hand side of multi-value - // assignment statement. - looking_at_matrix_or_assign_lhs = false; - - // Object index not possible until we've seen something. - looking_for_object_index = false; - - // Not initially looking at indirect references. - looking_at_indirect_ref = false; - - // Not initially parsing a class method. - parsing_class_method = false; - - // Not initially defining a class with classdef. - maybe_classdef_get_set_method = false; - parsing_classdef = false; - - // Quote marks strings intially. - quote_is_transpose = false; - - // Not initially defining a matrix list. - bracketflag = 0; - - // Not initially defining a cell array list. - braceflag = 0; - - // Not initially inside a loop or if statement. - looping = 0; - - // Not initially defining a function. - defining_func = 0; - - // Not initiallly looking at a function handle. - looking_at_function_handle = 0; - - // Not parsing an object index. - while (! looking_at_object_index.empty ()) - looking_at_object_index.pop_front (); - - // Not parsing an object index. - while (! parsed_function_name.empty ()) - parsed_function_name.pop (); - - // The closest paren, brace, or bracket nesting is not an object - // index. - looking_at_object_index.push_front (false); - - // Set of identifiers that might be local variable names is empty. - pending_local_variables.clear (); -} - bool is_keyword (const std::string& s) {