# HG changeset patch # User John W. Eaton # Date 1361911196 18000 # Node ID 210039e91ad6d0a4b8c6004348307b906d0cca3c # Parent f7eb13f1432008812759a341b1717dbbc63cd550 localize use of yytext with lexical_feedback member function * lex.h, lex.ll (lexical_feedback::flex_yytext): New function. * lex.ll (lexical_feedback::xunput, lexical_feedback::process_comment, lexical_feedback::handle_number, lexical_feedback::handle_identifier, lexical_feedback::handle_meta_identifier, lexical_feedback::handle_superclass_identifier): Use it instead of accessing yytext directly. diff -r f7eb13f14320 -r 210039e91ad6 libinterp/parse-tree/lex.h --- a/libinterp/parse-tree/lex.h Tue Feb 26 15:23:27 2013 -0500 +++ b/libinterp/parse-tree/lex.h Tue Feb 26 15:39:56 2013 -0500 @@ -210,6 +210,8 @@ int octave_read (char *buf, unsigned int max_size); + char *flex_yytext (void); + void do_comma_insert_check (void); int text_yyinput (void); diff -r f7eb13f14320 -r 210039e91ad6 libinterp/parse-tree/lex.ll --- a/libinterp/parse-tree/lex.ll Tue Feb 26 15:23:27 2013 -0500 +++ b/libinterp/parse-tree/lex.ll Tue Feb 26 15:39:56 2013 -0500 @@ -1485,6 +1485,12 @@ return status; } +char * +lexical_feedback::flex_yytext (void) +{ + return yytext; +} + // GAG. // // If we're reading a matrix and the next character is '[', make sure @@ -1563,7 +1569,8 @@ void lexical_feedback::xunput (char c) { - xunput (c, yytext); + char *yytxt = flex_yytext (); + xunput (c, yytxt); } // If we read some newlines, we need figure out what column we're @@ -2084,7 +2091,8 @@ if (! help_buf.empty ()) help_txt = help_buf.top (); - flex_stream_reader flex_reader (this, yytext); + char *yytxt = flex_yytext (); + flex_stream_reader flex_reader (this, yytxt); // process_comment is only supposed to be called when we are not // initially looking at a block comment. @@ -2470,17 +2478,19 @@ double value = 0.0; int nread = 0; - if (looks_like_hex (yytext, strlen (yytext))) + char *yytxt = flex_yytext (); + + if (looks_like_hex (yytxt, strlen (yytxt))) { unsigned long ival; - nread = sscanf (yytext, "%lx", &ival); + nread = sscanf (yytxt, "%lx", &ival); value = static_cast (ival); } else { - char *tmp = strsave (yytext); + char *tmp = strsave (yytxt); char *idx = strpbrk (tmp, "Dd"); @@ -2501,7 +2511,7 @@ looking_for_object_index = false; at_beginning_of_statement = false; - curr_lexer->push_token (new token (value, yytext, input_line_number, + curr_lexer->push_token (new token (value, yytxt, input_line_number, current_input_column)); current_input_column += yyleng; @@ -3208,7 +3218,8 @@ eat_continuation (); std::string pkg; - std::string meth = strip_trailing_whitespace (yytext); + char *yytxt = flex_yytext (); + std::string meth = strip_trailing_whitespace (yytxt); size_t pos = meth.find ("@"); std::string cls = meth.substr (pos).substr (1); meth = meth.substr (0, pos - 1); @@ -3246,7 +3257,8 @@ eat_continuation (); std::string pkg; - std::string cls = strip_trailing_whitespace (yytext).substr (1); + char *yytxt = flex_yytext (); + std::string cls = strip_trailing_whitespace (yytxt).substr (1); size_t pos = cls.find ("."); if (pos != std::string::npos) @@ -3282,9 +3294,11 @@ { bool at_bos = at_beginning_of_statement; - std::string tok = strip_trailing_whitespace (yytext); - - int c = yytext[yyleng-1]; + char *yytxt = flex_yytext (); + + std::string tok = strip_trailing_whitespace (yytxt); + + int c = yytxt[yyleng-1]; bool cont_is_spc = (eat_continuation () != lexical_feedback::NO_WHITESPACE);