Mercurial > octave-nkf
comparison libinterp/parse-tree/lex.ll @ 16128:210039e91ad6
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.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 26 Feb 2013 15:39:56 -0500 |
parents | 5c885c13bfa3 |
children | 053b0364b507 |
comparison
equal
deleted
inserted
replaced
16127:f7eb13f14320 | 16128:210039e91ad6 |
---|---|
1483 } | 1483 } |
1484 | 1484 |
1485 return status; | 1485 return status; |
1486 } | 1486 } |
1487 | 1487 |
1488 char * | |
1489 lexical_feedback::flex_yytext (void) | |
1490 { | |
1491 return yytext; | |
1492 } | |
1493 | |
1488 // GAG. | 1494 // GAG. |
1489 // | 1495 // |
1490 // If we're reading a matrix and the next character is '[', make sure | 1496 // If we're reading a matrix and the next character is '[', make sure |
1491 // that we insert a comma ahead of it. | 1497 // that we insert a comma ahead of it. |
1492 | 1498 |
1561 } | 1567 } |
1562 | 1568 |
1563 void | 1569 void |
1564 lexical_feedback::xunput (char c) | 1570 lexical_feedback::xunput (char c) |
1565 { | 1571 { |
1566 xunput (c, yytext); | 1572 char *yytxt = flex_yytext (); |
1573 xunput (c, yytxt); | |
1567 } | 1574 } |
1568 | 1575 |
1569 // If we read some newlines, we need figure out what column we're | 1576 // If we read some newlines, we need figure out what column we're |
1570 // really looking at. | 1577 // really looking at. |
1571 | 1578 |
2082 std::string help_txt; | 2089 std::string help_txt; |
2083 | 2090 |
2084 if (! help_buf.empty ()) | 2091 if (! help_buf.empty ()) |
2085 help_txt = help_buf.top (); | 2092 help_txt = help_buf.top (); |
2086 | 2093 |
2087 flex_stream_reader flex_reader (this, yytext); | 2094 char *yytxt = flex_yytext (); |
2095 flex_stream_reader flex_reader (this, yytxt); | |
2088 | 2096 |
2089 // process_comment is only supposed to be called when we are not | 2097 // process_comment is only supposed to be called when we are not |
2090 // initially looking at a block comment. | 2098 // initially looking at a block comment. |
2091 | 2099 |
2092 std::string txt = start_in_block | 2100 std::string txt = start_in_block |
2468 lexical_feedback::handle_number (void) | 2476 lexical_feedback::handle_number (void) |
2469 { | 2477 { |
2470 double value = 0.0; | 2478 double value = 0.0; |
2471 int nread = 0; | 2479 int nread = 0; |
2472 | 2480 |
2473 if (looks_like_hex (yytext, strlen (yytext))) | 2481 char *yytxt = flex_yytext (); |
2482 | |
2483 if (looks_like_hex (yytxt, strlen (yytxt))) | |
2474 { | 2484 { |
2475 unsigned long ival; | 2485 unsigned long ival; |
2476 | 2486 |
2477 nread = sscanf (yytext, "%lx", &ival); | 2487 nread = sscanf (yytxt, "%lx", &ival); |
2478 | 2488 |
2479 value = static_cast<double> (ival); | 2489 value = static_cast<double> (ival); |
2480 } | 2490 } |
2481 else | 2491 else |
2482 { | 2492 { |
2483 char *tmp = strsave (yytext); | 2493 char *tmp = strsave (yytxt); |
2484 | 2494 |
2485 char *idx = strpbrk (tmp, "Dd"); | 2495 char *idx = strpbrk (tmp, "Dd"); |
2486 | 2496 |
2487 if (idx) | 2497 if (idx) |
2488 *idx = 'e'; | 2498 *idx = 'e'; |
2499 quote_is_transpose = true; | 2509 quote_is_transpose = true; |
2500 convert_spaces_to_comma = true; | 2510 convert_spaces_to_comma = true; |
2501 looking_for_object_index = false; | 2511 looking_for_object_index = false; |
2502 at_beginning_of_statement = false; | 2512 at_beginning_of_statement = false; |
2503 | 2513 |
2504 curr_lexer->push_token (new token (value, yytext, input_line_number, | 2514 curr_lexer->push_token (new token (value, yytxt, input_line_number, |
2505 current_input_column)); | 2515 current_input_column)); |
2506 | 2516 |
2507 current_input_column += yyleng; | 2517 current_input_column += yyleng; |
2508 | 2518 |
2509 do_comma_insert_check (); | 2519 do_comma_insert_check (); |
3206 lexical_feedback::handle_superclass_identifier (void) | 3216 lexical_feedback::handle_superclass_identifier (void) |
3207 { | 3217 { |
3208 eat_continuation (); | 3218 eat_continuation (); |
3209 | 3219 |
3210 std::string pkg; | 3220 std::string pkg; |
3211 std::string meth = strip_trailing_whitespace (yytext); | 3221 char *yytxt = flex_yytext (); |
3222 std::string meth = strip_trailing_whitespace (yytxt); | |
3212 size_t pos = meth.find ("@"); | 3223 size_t pos = meth.find ("@"); |
3213 std::string cls = meth.substr (pos).substr (1); | 3224 std::string cls = meth.substr (pos).substr (1); |
3214 meth = meth.substr (0, pos - 1); | 3225 meth = meth.substr (0, pos - 1); |
3215 | 3226 |
3216 pos = cls.find ("."); | 3227 pos = cls.find ("."); |
3244 lexical_feedback::handle_meta_identifier (void) | 3255 lexical_feedback::handle_meta_identifier (void) |
3245 { | 3256 { |
3246 eat_continuation (); | 3257 eat_continuation (); |
3247 | 3258 |
3248 std::string pkg; | 3259 std::string pkg; |
3249 std::string cls = strip_trailing_whitespace (yytext).substr (1); | 3260 char *yytxt = flex_yytext (); |
3261 std::string cls = strip_trailing_whitespace (yytxt).substr (1); | |
3250 size_t pos = cls.find ("."); | 3262 size_t pos = cls.find ("."); |
3251 | 3263 |
3252 if (pos != std::string::npos) | 3264 if (pos != std::string::npos) |
3253 { | 3265 { |
3254 pkg = cls.substr (pos).substr (1); | 3266 pkg = cls.substr (pos).substr (1); |
3280 int | 3292 int |
3281 lexical_feedback::handle_identifier (void) | 3293 lexical_feedback::handle_identifier (void) |
3282 { | 3294 { |
3283 bool at_bos = at_beginning_of_statement; | 3295 bool at_bos = at_beginning_of_statement; |
3284 | 3296 |
3285 std::string tok = strip_trailing_whitespace (yytext); | 3297 char *yytxt = flex_yytext (); |
3286 | 3298 |
3287 int c = yytext[yyleng-1]; | 3299 std::string tok = strip_trailing_whitespace (yytxt); |
3300 | |
3301 int c = yytxt[yyleng-1]; | |
3288 | 3302 |
3289 bool cont_is_spc = (eat_continuation () != lexical_feedback::NO_WHITESPACE); | 3303 bool cont_is_spc = (eat_continuation () != lexical_feedback::NO_WHITESPACE); |
3290 | 3304 |
3291 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); | 3305 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
3292 | 3306 |