Mercurial > hg > octave-nkf
changeset 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 | c8974e28da59 |
files | libinterp/parse-tree/lex.h libinterp/parse-tree/lex.ll libinterp/parse-tree/oct-parse.yy libinterp/parse-tree/parse.h |
diffstat | 4 files changed, 110 insertions(+), 121 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.h +++ b/libinterp/parse-tree/lex.h @@ -72,6 +72,7 @@ looking_at_indirect_ref (false), parsing_class_method (false), maybe_classdef_get_set_method (false), parsing_classdef (false), quote_is_transpose (false), parser_end_of_input (false), + input_line_number (1), current_input_column (1), bracketflag (0), braceflag (0), looping (0), defining_func (0), looking_at_function_handle (0), looking_at_object_index (), parsed_function_name (), @@ -97,6 +98,8 @@ parsing_classdef (lf.parsing_classdef), quote_is_transpose (lf.quote_is_transpose), parser_end_of_input (lf.parser_end_of_input), + input_line_number (lf.input_line_number), + current_input_column (lf.current_input_column), bracketflag (lf.bracketflag), braceflag (lf.braceflag), looping (lf.looping), @@ -127,6 +130,8 @@ parsing_classdef = lf.parsing_classdef; quote_is_transpose = lf.quote_is_transpose; parser_end_of_input = lf.parser_end_of_input; + input_line_number = lf.input_line_number; + current_input_column = lf.current_input_column; bracketflag = lf.bracketflag; braceflag = lf.braceflag; looping = lf.looping; @@ -205,6 +210,12 @@ // TRUE means that we have encountered EOF on the input stream. bool parser_end_of_input; + // The current input line number. + int input_line_number; + + // The column of the current token. + int current_input_column; + // Square bracket level count. int bracketflag;
--- a/libinterp/parse-tree/lex.ll +++ b/libinterp/parse-tree/lex.ll @@ -148,7 +148,7 @@ #define TOK_RETURN(tok) \ do \ { \ - current_input_column += yyleng; \ + lexer_flags.current_input_column += yyleng; \ lexer_flags.quote_is_transpose = false; \ lexer_flags.convert_spaces_to_comma = true; \ COUNT_TOK_AND_RETURN (tok); \ @@ -158,8 +158,8 @@ #define TOK_PUSH_AND_RETURN(name, tok) \ do \ { \ - yylval.tok_val = new token (name, input_line_number, \ - current_input_column); \ + yylval.tok_val = new token (name, lexer_flags.input_line_number, \ + lexer_flags.current_input_column); \ token_stack.push (yylval.tok_val); \ TOK_RETURN (tok); \ } \ @@ -168,9 +168,10 @@ #define BIN_OP_RETURN_INTERNAL(tok, convert, bos, qit) \ do \ { \ - yylval.tok_val = new token (input_line_number, current_input_column); \ + yylval.tok_val = new token (lexer_flags.input_line_number, \ + lexer_flags.current_input_column); \ token_stack.push (yylval.tok_val); \ - current_input_column += yyleng; \ + lexer_flags.current_input_column += yyleng; \ lexer_flags.quote_is_transpose = qit; \ lexer_flags.convert_spaces_to_comma = convert; \ lexer_flags.looking_for_object_index = false; \ @@ -378,8 +379,8 @@ LEXER_DEBUG ("<COMMAND_START>{NL}"); BEGIN (INITIAL); - input_line_number++; - current_input_column = 1; + lexer_flags.input_line_number++; + lexer_flags.current_input_column = 1; lexer_flags.quote_is_transpose = false; lexer_flags.convert_spaces_to_comma = true; @@ -408,7 +409,7 @@ lexer_flags.at_beginning_of_statement = false; - current_input_column++; + lexer_flags.current_input_column++; int tok = handle_string (yytext[0]); COUNT_TOK_AND_RETURN (tok); @@ -496,7 +497,7 @@ <MATRIX_START>{S}*\,{S}* { LEXER_DEBUG ("<MATRIX_START>{S}*\\,{S}*"); - current_input_column += yyleng; + lexer_flags.current_input_column += yyleng; int tmp = eat_continuation (); @@ -528,7 +529,7 @@ <MATRIX_START>{S}+ { LEXER_DEBUG ("<MATRIX_START>{S}+"); - current_input_column += yyleng; + lexer_flags.current_input_column += yyleng; lexer_flags.at_beginning_of_statement = false; @@ -624,7 +625,7 @@ lexer_flags.looking_at_object_index.push_front (false); - current_input_column += yyleng; + lexer_flags.current_input_column += yyleng; lexer_flags.quote_is_transpose = false; lexer_flags.convert_spaces_to_comma = true; lexer_flags.looking_for_object_index = false; @@ -686,7 +687,7 @@ %} {S}* { - current_input_column += yyleng; + lexer_flags.current_input_column += yyleng; } %{ @@ -701,8 +702,8 @@ gripe_matlab_incompatible_continuation (); scan_for_comments (yytext); promptflag--; - input_line_number++; - current_input_column = 1; + lexer_flags.input_line_number++; + lexer_flags.current_input_column = 1; } %{ @@ -719,7 +720,7 @@ if ((reading_fcn_file || reading_script_file || reading_classdef_file) && ! curr_fcn_file_name.empty ()) warning ("near line %d of file '%s.m'", - input_line_number, curr_fcn_file_name.c_str ()); + lexer_flags.input_line_number, curr_fcn_file_name.c_str ()); } TOK_RETURN (END_OF_INPUT); @@ -782,7 +783,7 @@ "@" { LEXER_DEBUG ("@"); - current_input_column++; + lexer_flags.current_input_column++; lexer_flags.quote_is_transpose = false; lexer_flags.convert_spaces_to_comma = false; @@ -803,8 +804,8 @@ {NL} { LEXER_DEBUG ("{NL}"); - input_line_number++; - current_input_column = 1; + lexer_flags.input_line_number++; + lexer_flags.current_input_column = 1; lexer_flags.quote_is_transpose = false; lexer_flags.convert_spaces_to_comma = true; @@ -831,7 +832,7 @@ "'" { LEXER_DEBUG ("'"); - current_input_column++; + lexer_flags.current_input_column++; lexer_flags.convert_spaces_to_comma = true; if (lexer_flags.quote_is_transpose) @@ -853,7 +854,7 @@ \" { LEXER_DEBUG ("\""); - current_input_column++; + lexer_flags.current_input_column++; int tok = handle_string ('"'); COUNT_TOK_AND_RETURN (tok); @@ -888,8 +889,8 @@ lexer_flags.looking_for_object_index = false; - input_line_number++; - current_input_column = 1; + lexer_flags.input_line_number++; + lexer_flags.current_input_column = 1; block_comment_nesting_level++; promptflag--; @@ -971,7 +972,7 @@ LEXER_DEBUG (")"); nesting_level.remove (); - current_input_column++; + lexer_flags.current_input_column++; lexer_flags.looking_at_object_index.pop_front (); @@ -1024,7 +1025,7 @@ lexer_flags.looking_at_object_index.push_front (lexer_flags.looking_for_object_index); - current_input_column += yyleng; + lexer_flags.current_input_column += yyleng; lexer_flags.quote_is_transpose = false; lexer_flags.convert_spaces_to_comma = true; lexer_flags.looking_for_object_index = false; @@ -1064,11 +1065,11 @@ if (c != EOF) { - current_input_column++; + lexer_flags.current_input_column++; error ("invalid character '%s' (ASCII %d) near line %d, column %d", undo_string_escape (static_cast<char> (c)), c, - input_line_number, current_input_column); + lexer_flags.input_line_number, lexer_flags.current_input_column); return LEXICAL_ERROR; } @@ -1128,13 +1129,6 @@ token_stack.pop (); } - // Can be reset by defining a function. - if (! (reading_script_file || reading_fcn_file || reading_classdef_file)) - { - current_input_column = 1; - input_line_number = command_editor::current_command_number (); - } - // Only ask for input from stdin if we are expecting interactive // input. @@ -1334,7 +1328,7 @@ } if (c == '\n') - input_line_number++; + lexer_flags.input_line_number++; return c; } @@ -1350,7 +1344,7 @@ } if (c == '\n') - input_line_number--; + lexer_flags.input_line_number--; yyunput (c, buf); } @@ -1366,11 +1360,11 @@ { if (c == '\n') { - input_line_number++; - current_input_column = 1; + lexer_flags.input_line_number++; + lexer_flags.current_input_column = 1; } else - current_input_column++; + lexer_flags.current_input_column++; } } @@ -1473,8 +1467,8 @@ static int is_keyword_token (const std::string& s) { - int l = input_line_number; - int c = current_input_column; + int l = lexer_flags.input_line_number; + int c = lexer_flags.current_input_column; int len = s.length (); @@ -1502,12 +1496,12 @@ && ! curr_fcn_file_full_name.empty ()) warning_with_id ("Octave:deprecated-keyword", "the 'static' keyword is obsolete and will be removed from a future version of Octave; please use 'persistent' instead; near line %d of file '%s'", - input_line_number, + lexer_flags.input_line_number, curr_fcn_file_full_name.c_str ()); else warning_with_id ("Octave:deprecated-keyword", "the 'static' keyword is obsolete and will be removed from a future version of Octave; please use 'persistent' instead; near line %d", - input_line_number); + lexer_flags.input_line_number); // fall through ... case persistent_kw: @@ -1652,7 +1646,7 @@ if (! (reading_fcn_file || reading_script_file || reading_classdef_file)) - input_line_number = 1; + lexer_flags.input_line_number = 1; break; case magic_file_kw: @@ -1707,7 +1701,7 @@ while ((c = reader.getc ()) != EOF) { - current_input_column++; + lexer_flags.current_input_column++; if (look_for_marker) { @@ -1724,7 +1718,7 @@ while ((c = reader.getc ()) != EOF && ! done) { - current_input_column++; + lexer_flags.current_input_column++; switch (c) { @@ -1735,7 +1729,7 @@ case '\n': { - current_input_column = 0; + lexer_flags.current_input_column = 0; at_bol = true; done = true; @@ -1787,7 +1781,7 @@ if (c == '\n') { - current_input_column = 0; + lexer_flags.current_input_column = 0; at_bol = true; } } @@ -1817,7 +1811,7 @@ while ((c = reader.getc ()) != EOF) { - current_input_column++; + lexer_flags.current_input_column++; if (begin_comment) { @@ -1834,7 +1828,7 @@ while ((c = reader.getc ()) != EOF && ! done) { - current_input_column++; + lexer_flags.current_input_column++; switch (c) { @@ -1845,7 +1839,7 @@ case '\n': { - current_input_column = 0; + lexer_flags.current_input_column = 0; at_bol = true; done = true; @@ -1884,7 +1878,7 @@ if (c == '\n') { at_bol = true; - current_input_column = 0; + lexer_flags.current_input_column = 0; in_comment = false; // FIXME -- bailing out here prevents things like @@ -1924,7 +1918,7 @@ break; default: - current_input_column--; + lexer_flags.current_input_column--; reader.ungetc (c); goto done; } @@ -1991,7 +1985,7 @@ octave_comment_buffer::append (txt); - current_input_column = 1; + lexer_flags.current_input_column = 1; lexer_flags.quote_is_transpose = false; lexer_flags.convert_spaces_to_comma = true; lexer_flags.at_beginning_of_statement = true; @@ -2302,7 +2296,7 @@ while ((c = text_yyinput ()) != EOF) { - current_input_column++; + lexer_flags.current_input_column++; switch (c) { @@ -2326,7 +2320,7 @@ in_comment = false; beginning_of_comment = false; } - current_input_column = 0; + lexer_flags.current_input_column = 0; break; case '#': @@ -2391,7 +2385,7 @@ done: xunput (c, yytext); - current_input_column--; + lexer_flags.current_input_column--; return retval; } @@ -2438,12 +2432,12 @@ lexer_flags.looking_for_object_index = false; lexer_flags.at_beginning_of_statement = false; - yylval.tok_val = new token (value, yytext, input_line_number, - current_input_column); + yylval.tok_val = new token (value, yytext, lexer_flags.input_line_number, + lexer_flags.current_input_column); token_stack.push (yylval.tok_val); - current_input_column += yyleng; + lexer_flags.current_input_column += yyleng; do_comma_insert_check (); } @@ -2512,7 +2506,7 @@ comment_buf += static_cast<char> (c); octave_comment_buffer::append (comment_buf); } - current_input_column = 0; + lexer_flags.current_input_column = 0; promptflag--; gripe_matlab_incompatible_continuation (); return true; @@ -2594,15 +2588,15 @@ { std::ostringstream buf; - int bos_line = input_line_number; - int bos_col = current_input_column; + int bos_line = lexer_flags.input_line_number; + int bos_col = lexer_flags.current_input_column; int c; int escape_pending = 0; while ((c = text_yyinput ()) != EOF) { - current_input_column++; + lexer_flags.current_input_column++; if (c == '\\') { @@ -3174,11 +3168,12 @@ = new token (meth.empty () ? 0 : &(symbol_table::insert (meth)), cls.empty () ? 0 : &(symbol_table::insert (cls)), pkg.empty () ? 0 : &(symbol_table::insert (pkg)), - input_line_number, current_input_column); + lexer_flags.input_line_number, + lexer_flags.current_input_column); token_stack.push (yylval.tok_val); lexer_flags.convert_spaces_to_comma = true; - current_input_column += yyleng; + lexer_flags.current_input_column += yyleng; return SUPERCLASSREF; } @@ -3208,12 +3203,13 @@ yylval.tok_val = new token (cls.empty () ? 0 : &(symbol_table::insert (cls)), pkg.empty () ? 0 : &(symbol_table::insert (pkg)), - input_line_number, current_input_column); + lexer_flags.input_line_number, + lexer_flags.current_input_column); token_stack.push (yylval.tok_val); lexer_flags.convert_spaces_to_comma = true; - current_input_column += yyleng; + lexer_flags.current_input_column += yyleng; return METAQUERY; } @@ -3246,8 +3242,8 @@ maybe_unput_comma (spc_gobbled); - yylval.tok_val = new token (tok, input_line_number, - current_input_column); + yylval.tok_val = new token (tok, lexer_flags.input_line_number, + lexer_flags.current_input_column); token_stack.push (yylval.tok_val); @@ -3255,7 +3251,7 @@ lexer_flags.convert_spaces_to_comma = true; lexer_flags.looking_for_object_index = true; - current_input_column += yyleng; + lexer_flags.current_input_column += yyleng; return STRUCT_ELT; } @@ -3283,12 +3279,12 @@ } else { - yylval.tok_val = new token (tok, input_line_number, - current_input_column); + yylval.tok_val = new token (tok, lexer_flags.input_line_number, + lexer_flags.current_input_column); token_stack.push (yylval.tok_val); - current_input_column += yyleng; + lexer_flags.current_input_column += yyleng; lexer_flags.quote_is_transpose = false; lexer_flags.convert_spaces_to_comma = true; lexer_flags.looking_for_object_index = true; @@ -3304,7 +3300,7 @@ { if (kw_token >= 0) { - current_input_column += yyleng; + lexer_flags.current_input_column += yyleng; lexer_flags.quote_is_transpose = false; lexer_flags.convert_spaces_to_comma = true; lexer_flags.looking_for_object_index = false; @@ -3367,7 +3363,8 @@ tok = "__end__"; yylval.tok_val = new token (&(symbol_table::insert (tok)), - input_line_number, current_input_column); + lexer_flags.input_line_number, + lexer_flags.current_input_column); token_stack.push (yylval.tok_val); @@ -3385,7 +3382,7 @@ maybe_unput_comma (spc_gobbled); } - current_input_column += yyleng; + lexer_flags.current_input_column += yyleng; if (tok != "__end__") lexer_flags.looking_for_object_index = true; @@ -3547,11 +3544,11 @@ if (nm.empty ()) warning_with_id ("Octave:separator-insert", "potential auto-insertion of '%c' near line %d", - sep, input_line_number); + sep, lexer_flags.input_line_number); else warning_with_id ("Octave:separator-insert", "potential auto-insertion of '%c' near line %d of file %s", - sep, input_line_number, nm.c_str ()); + sep, lexer_flags.input_line_number, nm.c_str ()); } static void @@ -3562,11 +3559,11 @@ if (nm.empty ()) warning_with_id ("Octave:single-quote-string", "single quote delimited string near line %d", - input_line_number); + lexer_flags.input_line_number); else warning_with_id ("Octave:single-quote-string", "single quote delimited string near line %d of file %s", - input_line_number, nm.c_str ()); + lexer_flags.input_line_number, nm.c_str ()); } static void @@ -3581,7 +3578,7 @@ else warning_with_id ("Octave:matlab-incompatible", "potential Matlab compatibility problem: %s near line %d offile %s", - msg.c_str (), input_line_number, nm.c_str ()); + msg.c_str (), lexer_flags.input_line_number, nm.c_str ()); } static void
--- 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;
--- a/libinterp/parse-tree/parse.h +++ b/libinterp/parse-tree/parse.h @@ -44,12 +44,6 @@ // Nonzero means print parser debugging info (-d). extern int octave_debug; -// The current input line number. -extern int input_line_number; - -// The column of the current token. -extern int current_input_column; - // Buffer for help text snagged from function files. extern std::stack<std::string> help_buf;