comparison libinterp/parse-tree/lex.ll @ 27777:3b6920ee4383

eliminate COMMAND_ARG_FINISH macro in lexer * lex.h, lex.ll (base_lexer::finish_command_arg): New function to do part of the work of the COMMAND_ARG_FINISH macro. (COMMAND_ARG_FINISH): Delete macro. Replace all uses with some inline code and a call to curr_lexer->finish_command_arg. (base_lexer::handle_token (const std::string&, int)): Delete function.
author John W. Eaton <jwe@octave.org>
date Thu, 05 Dec 2019 22:01:02 -0600
parents cd566153edd6
children 2f8559459314
comparison
equal deleted inserted replaced
27776:881efe2c4c0f 27777:3b6920ee4383
254 \ 254 \
255 if (curr_lexer->at_end_of_file ()) \ 255 if (curr_lexer->at_end_of_file ()) \
256 return curr_lexer->handle_end_of_input (); \ 256 return curr_lexer->handle_end_of_input (); \
257 } \ 257 } \
258 } \ 258 } \
259 while (0)
260
261 // When a command argument boundary is detected, push out the
262 // current argument being built. This one seems like a good
263 // candidate for a function call.
264
265 #define COMMAND_ARG_FINISH \
266 do \
267 { \
268 if (curr_lexer->m_string_text.empty ()) \
269 break; \
270 \
271 int retval = curr_lexer->handle_token (curr_lexer->m_string_text, \
272 SQ_STRING); \
273 \
274 curr_lexer->m_string_text = ""; \
275 curr_lexer->m_command_arg_paren_count = 0; \
276 \
277 yyless (0); \
278 \
279 return retval; \
280 } \
281 while (0) 259 while (0)
282 260
283 #define HANDLE_IDENTIFIER(pattern, get_set) \ 261 #define HANDLE_IDENTIFIER(pattern, get_set) \
284 do \ 262 do \
285 { \ 263 { \
394 %} 372 %}
395 373
396 <COMMAND_START>(\.\.\.){ANY_EXCEPT_NL}*{NL} { 374 <COMMAND_START>(\.\.\.){ANY_EXCEPT_NL}*{NL} {
397 curr_lexer->lexer_debug ("<COMMAND_START>(\\.\\.\\.){ANY_EXCEPT_NL}*{NL}"); 375 curr_lexer->lexer_debug ("<COMMAND_START>(\\.\\.\\.){ANY_EXCEPT_NL}*{NL}");
398 376
399 COMMAND_ARG_FINISH; 377 if (! curr_lexer->m_string_text.empty ())
378 {
379 yyless (0);
380
381 return curr_lexer->finish_command_arg ();
382 }
400 383
401 HANDLE_STRING_CONTINUATION; 384 HANDLE_STRING_CONTINUATION;
402 } 385 }
403 386
404 %{ 387 %{
406 %} 389 %}
407 390
408 <COMMAND_START>({CCHAR}{ANY_EXCEPT_NL}*)?{NL} { 391 <COMMAND_START>({CCHAR}{ANY_EXCEPT_NL}*)?{NL} {
409 curr_lexer->lexer_debug ("<COMMAND_START>({CCHAR}{ANY_EXCEPT_NL}*)?{NL}"); 392 curr_lexer->lexer_debug ("<COMMAND_START>({CCHAR}{ANY_EXCEPT_NL}*)?{NL}");
410 393
411 COMMAND_ARG_FINISH; 394 if (! curr_lexer->m_string_text.empty ())
395 {
396 yyless (0);
397
398 return curr_lexer->finish_command_arg ();
399 }
412 400
413 curr_lexer->m_filepos.next_line (); 401 curr_lexer->m_filepos.next_line ();
414 curr_lexer->m_looking_for_object_index = false; 402 curr_lexer->m_looking_for_object_index = false;
415 curr_lexer->m_at_beginning_of_statement = true; 403 curr_lexer->m_at_beginning_of_statement = true;
416 curr_lexer->pop_start_state (); 404 curr_lexer->pop_start_state ();
421 <COMMAND_START>[\,\;] { 409 <COMMAND_START>[\,\;] {
422 curr_lexer->lexer_debug ("<COMMAND_START>[\\,\\;]"); 410 curr_lexer->lexer_debug ("<COMMAND_START>[\\,\\;]");
423 411
424 if (yytext[0] != ',' || curr_lexer->m_command_arg_paren_count == 0) 412 if (yytext[0] != ',' || curr_lexer->m_command_arg_paren_count == 0)
425 { 413 {
426 COMMAND_ARG_FINISH; 414 if (! curr_lexer->m_string_text.empty ())
415 {
416 yyless (0);
417
418 return curr_lexer->finish_command_arg ();
419 }
420
427 curr_lexer->m_looking_for_object_index = false; 421 curr_lexer->m_looking_for_object_index = false;
428 curr_lexer->m_at_beginning_of_statement = true; 422 curr_lexer->m_at_beginning_of_statement = true;
429 curr_lexer->pop_start_state (); 423 curr_lexer->pop_start_state ();
424
430 return curr_lexer->handle_token (yytext[0]); 425 return curr_lexer->handle_token (yytext[0]);
431 } 426 }
432 else 427 else
433 curr_lexer->m_string_text += yytext; 428 curr_lexer->m_string_text += yytext;
434 429
489 484
490 <COMMAND_START>{S}* { 485 <COMMAND_START>{S}* {
491 curr_lexer->lexer_debug ("<COMMAND_START>{S}*"); 486 curr_lexer->lexer_debug ("<COMMAND_START>{S}*");
492 487
493 if (curr_lexer->m_command_arg_paren_count == 0) 488 if (curr_lexer->m_command_arg_paren_count == 0)
494 COMMAND_ARG_FINISH; 489 {
490 if (! curr_lexer->m_string_text.empty ())
491 {
492 yyless (0);
493
494 return curr_lexer->finish_command_arg ();
495 }
496 }
495 else 497 else
496 curr_lexer->m_string_text += yytext; 498 curr_lexer->m_string_text += yytext;
497 499
498 curr_lexer->m_filepos.increment_column (yyleng); 500 curr_lexer->m_filepos.increment_column (yyleng);
499 } 501 }
3624 } 3626 }
3625 3627
3626 return count_token_internal (tok); 3628 return count_token_internal (tok);
3627 } 3629 }
3628 3630
3631 // When a command argument boundary is detected, push out the current
3632 // argument being built. This one seems like a good candidate for a
3633 // function call.
3634
3629 int 3635 int
3630 base_lexer::handle_token (const std::string& name, int tok) 3636 base_lexer::finish_command_arg (void)
3631 { 3637 {
3632 token *tok_val = new token (tok, name, m_filepos, m_filepos); 3638 int tok = SQ_STRING;
3639
3640 token *tok_val = new token (tok, m_string_text, m_filepos, m_filepos);
3641
3642 m_string_text = "";
3643 m_command_arg_paren_count = 0;
3633 3644
3634 return handle_token (tok, tok_val); 3645 return handle_token (tok, tok_val);
3635 } 3646 }
3636 3647
3637 int 3648 int