Mercurial > hg > octave-nkf
diff libinterp/parse-tree/oct-parse.yy @ 16103:6434f70f0ee0
move input_line_number and current_input_column to lexical_feedback class
* lex.h, lex.ll (input_line_number, current_input_column): Move global
variables to lexical_feedback class. Change all uses.
(reset_parser): Don't reset input_line_number or current_input_column.
* oct-parse.yy (eval_string, parse_fcn_file): Don't protect
input_line_number or current_input_column here.
(parse_fcn_file): Protect lexer_flags prior to calling
gobble_leading_whitespace. Use reset_parser to reset lexer_flags.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 25 Feb 2013 21:30:51 -0500 |
parents | 679a54d274d9 |
children | 229eb14653fd |
line wrap: on
line diff
--- a/libinterp/parse-tree/oct-parse.yy +++ b/libinterp/parse-tree/oct-parse.yy @@ -86,12 +86,6 @@ #define malloc GNULIB_NAMESPACE::malloc #endif -// The current input line number. -int input_line_number = 1; - -// The column of the current token. -int current_input_column = 1; - // Buffer for help text snagged from function files. std::stack<std::string> help_buf; @@ -1345,8 +1339,8 @@ script_file : SCRIPT_FILE opt_list END_OF_INPUT { tree_statement *end_of_script - = make_end ("endscript", input_line_number, - current_input_column); + = make_end ("endscript", lexer_flags.input_line_number, + lexer_flags.current_input_column); make_script ($2, end_of_script); @@ -1469,8 +1463,8 @@ YYABORT; } - $$ = make_end ("endfunction", input_line_number, - current_input_column); + $$ = make_end ("endfunction", lexer_flags.input_line_number, + lexer_flags.current_input_column); } ; @@ -1693,12 +1687,12 @@ static void yyerror (const char *s) { - int err_col = current_input_column - 1; + int err_col = lexer_flags.current_input_column - 1; std::ostringstream output_buf; if (reading_fcn_file || reading_script_file || reading_classdef_file) - output_buf << "parse error near line " << input_line_number + output_buf << "parse error near line " << lexer_flags.input_line_number << " of file " << curr_fcn_file_full_name; else output_buf << "parse error:"; @@ -2130,8 +2124,8 @@ make_anon_fcn_handle (tree_parameter_list *param_list, tree_statement *stmt) { // FIXME -- need to get these from the location of the @ symbol. - int l = input_line_number; - int c = current_input_column; + int l = lexer_flags.input_line_number; + int c = lexer_flags.current_input_column; tree_parameter_list *ret_list = 0; @@ -2909,7 +2903,8 @@ } fcn->stash_function_name (id_name); - fcn->stash_fcn_location (input_line_number, current_input_column); + fcn->stash_fcn_location (lexer_flags.input_line_number, + lexer_flags.current_input_column); if (! help_buf.empty () && current_function_depth == 1 && ! parsing_subfunctions) @@ -3318,7 +3313,7 @@ } if (c == '\n') - input_line_number++; + lexer_flags.input_line_number++; return c; } @@ -3333,7 +3328,7 @@ int ungetc (int c) { if (c == '\n') - input_line_number--; + lexer_flags.input_line_number--; return ::ungetc (c, f); } @@ -3359,11 +3354,11 @@ { case ' ': case '\t': - current_input_column++; + lexer_flags.current_input_column++; break; case '\n': - current_input_column = 1; + lexer_flags.current_input_column = 1; break; default: @@ -3473,8 +3468,6 @@ frame.protect_var (ff_instream); - frame.protect_var (input_line_number); - frame.protect_var (current_input_column); frame.protect_var (reading_fcn_file); frame.protect_var (line_editing); frame.protect_var (current_class_name); @@ -3484,8 +3477,6 @@ frame.protect_var (parsing_subfunctions); frame.protect_var (endfunction_found); - input_line_number = 1; - current_input_column = 1; reading_fcn_file = true; line_editing = false; current_class_name = dispatch_type; @@ -3508,6 +3499,11 @@ { bool eof; + frame.protect_var (lexer_flags); + + // Also resets lexer_flags. + reset_parser (); + std::string help_txt = gobble_leading_white_space (ffile, eof); if (! help_txt.empty ()) @@ -3517,16 +3513,12 @@ { std::string file_type; - frame.protect_var (lexer_flags); - frame.protect_var (get_input_from_eval_string); frame.protect_var (reading_fcn_file); frame.protect_var (reading_script_file); frame.protect_var (reading_classdef_file); frame.protect_var (Vecho_executing_commands); - lexer_flags = lexical_feedback (); - get_input_from_eval_string = false; if (! force_script && looking_at_function_keyword (ffile)) @@ -3575,8 +3567,6 @@ frame.protect_var (primary_fcn_ptr); primary_fcn_ptr = 0; - reset_parser (); - // Do this with an unwind-protect cleanup function so that // the forced variables will be unmarked in the event of an // interrupt. @@ -3614,7 +3604,8 @@ else { tree_statement *end_of_script - = make_end ("endscript", input_line_number, current_input_column); + = make_end ("endscript", lexer_flags.input_line_number, + lexer_flags.current_input_column); make_script (0, end_of_script); @@ -4315,8 +4306,6 @@ frame.protect_var (lexer_flags); - frame.protect_var (input_line_number); - frame.protect_var (current_input_column); frame.protect_var (get_input_from_eval_string); frame.protect_var (line_editing); frame.protect_var (current_eval_string); @@ -4331,8 +4320,6 @@ lexer_flags = lexical_feedback (); - input_line_number = 1; - current_input_column = 1; get_input_from_eval_string = true; line_editing = false; current_function_depth = 0;