changeset 33121:ee1868ed6aa1

revamp handling meta and fully-qualified identifiers in the lexer * lex.h, lex.ll (base_lexer::make_meta_identifier_token): Rename from handle_meta_identifier. Return token instead of token ID. Don't push token on token stack. Do set m_looking_for_object_index. Update use. (base_lexer::make_fq_identifier_token): Rename from handle_fq_identifier. Return token instead of token ID. Don't push token on token stack. Do set m_looking_for_object_index. Update use.
author John W. Eaton <jwe@octave.org>
date Sat, 02 Mar 2024 15:15:12 -0500
parents b8919be4c931
children 2b736846a81d
files libinterp/parse-tree/lex.h libinterp/parse-tree/lex.ll
diffstat 2 files changed, 42 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.h	Sat Mar 02 15:00:54 2024 -0500
+++ b/libinterp/parse-tree/lex.h	Sat Mar 02 15:15:12 2024 -0500
@@ -669,9 +669,9 @@
 
   int handle_superclass_identifier ();
 
-  int handle_meta_identifier ();
+  token * make_meta_identifier_token ();
 
-  int handle_fq_identifier ();
+  token * make_fq_identifier_token ();
 
   int handle_identifier ();
 
--- a/libinterp/parse-tree/lex.ll	Sat Mar 02 15:00:54 2024 -0500
+++ b/libinterp/parse-tree/lex.ll	Sat Mar 02 15:15:12 2024 -0500
@@ -1194,14 +1194,11 @@
 
     curr_lexer->update_token_positions (yyleng);
 
-    int tok_id = curr_lexer->handle_fq_identifier ();
-
-    if (tok_id >= 0)
-      {
-        curr_lexer->m_looking_for_object_index = true;
-
-        return curr_lexer->count_token_internal (tok_id);
-      }
+    octave::token *tok = curr_lexer->make_fq_identifier_token ();
+
+    curr_lexer->push_token (tok);
+
+    return curr_lexer->count_token_internal (tok->token_id ());
   }
 
 <FQ_IDENT_START>{S}+ {
@@ -1355,14 +1352,11 @@
       {
         curr_lexer->update_token_positions (yyleng);
 
-        int tok_id = curr_lexer->handle_meta_identifier ();
-
-        if (tok_id >= 0)
-          {
-            curr_lexer->m_looking_for_object_index = true;
-
-            return curr_lexer->count_token_internal (tok_id);
-          }
+        octave::token *tok = curr_lexer->make_meta_identifier_token ();
+
+        curr_lexer->push_token (tok);
+
+        return curr_lexer->count_token_internal (tok->token_id ());
       }
   }
 
@@ -3420,8 +3414,8 @@
     return count_token_internal (SUPERCLASSREF);
   }
 
-  int
-  base_lexer::handle_meta_identifier ()
+  token *
+  base_lexer::make_meta_identifier_token ()
   {
     std::string txt = flex_yytext ();
 
@@ -3434,25 +3428,27 @@
     // Token positions should have already been updated before this
     // function is called.
 
+    token *tok;
+
     if (fq_identifier_contains_keyword (cls))
       {
         std::string msg {"class and package names may not be keywords"};
-        token *tok = new token (LEXICAL_ERROR, msg, m_tok_beg, m_tok_end);
-
-        push_token (tok);
-
-        return count_token_internal (LEXICAL_ERROR);
+        tok = new token (LEXICAL_ERROR, msg, m_tok_beg, m_tok_end);
       }
-
-    push_token (new token (METAQUERY, cls, m_tok_beg, m_tok_end));
-
-    m_filepos.increment_column (flex_yyleng ());
-
-    return METAQUERY;
+    else
+      {
+        m_looking_for_object_index = true;
+
+        tok = new token (METAQUERY, cls, m_tok_beg, m_tok_end);
+
+        m_filepos.increment_column (flex_yyleng ());
+      }
+
+    return tok;
   }
 
-  int
-  base_lexer::handle_fq_identifier ()
+  token *
+  base_lexer::make_fq_identifier_token ()
   {
     std::string txt = flex_yytext ();
 
@@ -3462,21 +3458,23 @@
     // Token positions should have already been updated before this
     // function is called.
 
+    token *tok;
+
     if (fq_identifier_contains_keyword (txt))
       {
         std::string msg {"function, method, class, and package names may not be keywords"};
-        token *tok = new token (LEXICAL_ERROR, msg, m_tok_beg, m_tok_end);
-
-        push_token (tok);
-
-        return count_token_internal (LEXICAL_ERROR);
+        tok = new token (LEXICAL_ERROR, msg, m_tok_beg, m_tok_end);
       }
-
-    push_token (new token (FQ_IDENT, txt, m_tok_beg, m_tok_end));
-
-    m_filepos.increment_column (flex_yyleng ());
-
-    return FQ_IDENT;
+    else
+      {
+        m_looking_for_object_index = true;
+
+        tok = new token (FQ_IDENT, txt, m_tok_beg, m_tok_end);
+
+        m_filepos.increment_column (flex_yyleng ());
+      }
+
+    return tok;
   }
 
   // Figure out exactly what kind of token to return when we have seen