Mercurial > octave
changeset 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 | 881efe2c4c0f |
children | 2f8559459314 |
files | libinterp/parse-tree/lex.h libinterp/parse-tree/lex.ll |
diffstat | 2 files changed, 40 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- 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);
--- 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 @@ <COMMAND_START>(\.\.\.){ANY_EXCEPT_NL}*{NL} { curr_lexer->lexer_debug ("<COMMAND_START>(\\.\\.\\.){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 @@ <COMMAND_START>({CCHAR}{ANY_EXCEPT_NL}*)?{NL} { curr_lexer->lexer_debug ("<COMMAND_START>({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 ("<COMMAND_START>{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); }