# HG changeset patch # User John W. Eaton # Date 1575604862 21600 # Node ID 3b6920ee4383e65e16e72b6687bd41925a6cb9d2 # Parent 881efe2c4c0f397c01e693281f581e97922d7c28 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. diff -r 881efe2c4c0f -r 3b6920ee4383 libinterp/parse-tree/lex.h --- a/libinterp/parse-tree/lex.h Thu Dec 05 21:01:08 2019 -0600 +++ b/libinterp/parse-tree/lex.h Thu Dec 05 22:01:02 2019 -0600 @@ -747,7 +747,7 @@ int handle_op_internal (int tok, bool bos, bool compat); - int handle_token (const std::string& name, int tok); + int finish_command_arg (void); int handle_token (int tok, token *tok_val = nullptr); diff -r 881efe2c4c0f -r 3b6920ee4383 libinterp/parse-tree/lex.ll --- a/libinterp/parse-tree/lex.ll Thu Dec 05 21:01:08 2019 -0600 +++ b/libinterp/parse-tree/lex.ll Thu Dec 05 22:01:02 2019 -0600 @@ -258,28 +258,6 @@ } \ while (0) -// When a command argument boundary is detected, push out the -// current argument being built. This one seems like a good -// candidate for a function call. - -#define COMMAND_ARG_FINISH \ - do \ - { \ - if (curr_lexer->m_string_text.empty ()) \ - break; \ - \ - int retval = curr_lexer->handle_token (curr_lexer->m_string_text, \ - SQ_STRING); \ - \ - curr_lexer->m_string_text = ""; \ - curr_lexer->m_command_arg_paren_count = 0; \ - \ - yyless (0); \ - \ - return retval; \ - } \ - while (0) - #define HANDLE_IDENTIFIER(pattern, get_set) \ do \ { \ @@ -396,7 +374,12 @@ (\.\.\.){ANY_EXCEPT_NL}*{NL} { curr_lexer->lexer_debug ("(\\.\\.\\.){ANY_EXCEPT_NL}*{NL}"); - COMMAND_ARG_FINISH; + if (! curr_lexer->m_string_text.empty ()) + { + yyless (0); + + return curr_lexer->finish_command_arg (); + } HANDLE_STRING_CONTINUATION; } @@ -408,7 +391,12 @@ ({CCHAR}{ANY_EXCEPT_NL}*)?{NL} { curr_lexer->lexer_debug ("({CCHAR}{ANY_EXCEPT_NL}*)?{NL}"); - COMMAND_ARG_FINISH; + if (! curr_lexer->m_string_text.empty ()) + { + yyless (0); + + return curr_lexer->finish_command_arg (); + } curr_lexer->m_filepos.next_line (); curr_lexer->m_looking_for_object_index = false; @@ -423,10 +411,17 @@ if (yytext[0] != ',' || curr_lexer->m_command_arg_paren_count == 0) { - COMMAND_ARG_FINISH; + if (! curr_lexer->m_string_text.empty ()) + { + yyless (0); + + return curr_lexer->finish_command_arg (); + } + curr_lexer->m_looking_for_object_index = false; curr_lexer->m_at_beginning_of_statement = true; curr_lexer->pop_start_state (); + return curr_lexer->handle_token (yytext[0]); } else @@ -491,7 +486,14 @@ curr_lexer->lexer_debug ("{S}*"); if (curr_lexer->m_command_arg_paren_count == 0) - COMMAND_ARG_FINISH; + { + if (! curr_lexer->m_string_text.empty ()) + { + yyless (0); + + return curr_lexer->finish_command_arg (); + } + } else curr_lexer->m_string_text += yytext; @@ -3626,10 +3628,19 @@ return count_token_internal (tok); } + // When a command argument boundary is detected, push out the current + // argument being built. This one seems like a good candidate for a + // function call. + int - base_lexer::handle_token (const std::string& name, int tok) + base_lexer::finish_command_arg (void) { - token *tok_val = new token (tok, name, m_filepos, m_filepos); + int tok = SQ_STRING; + + token *tok_val = new token (tok, m_string_text, m_filepos, m_filepos); + + m_string_text = ""; + m_command_arg_paren_count = 0; return handle_token (tok, tok_val); }