changeset 27771:cd566153edd6

split base_lexer::is_keyword_token into two functions * lex.h, lex.ll (base_lexer::is_keyword_token): Only check whether given string is a keyword. (base_lexer::make_keyword_token): Create a token object if a the given string is a keyword.
author John W. Eaton <jwe@octave.org>
date Mon, 02 Dec 2019 23:37:39 -0600
parents 7a06e352ac61
children 54767f6a93f5
files libinterp/parse-tree/lex.h libinterp/parse-tree/lex.ll
diffstat 2 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.h	Mon Dec 02 23:09:08 2019 -0600
+++ b/libinterp/parse-tree/lex.h	Mon Dec 02 23:37:39 2019 -0600
@@ -645,7 +645,9 @@
 
     bool is_variable (const std::string& name, const symbol_scope& scope);
 
-    int is_keyword_token (const std::string& s);
+    bool is_keyword_token (const std::string& s);
+
+    int make_keyword_token (const std::string& s);
 
     bool fq_identifier_contains_keyword (const std::string& s);
 
--- a/libinterp/parse-tree/lex.ll	Mon Dec 02 23:09:08 2019 -0600
+++ b/libinterp/parse-tree/lex.ll	Mon Dec 02 23:37:39 2019 -0600
@@ -1363,7 +1363,7 @@
                 ident.erase (std::remove_if (ident.begin (), ident.end (),
                                              is_space_or_tab), ident.end ());
 
-                int kw_token = curr_lexer->is_keyword_token (ident);
+                bool kw_token = curr_lexer->is_keyword_token (ident);
 
                 octave::token *tok;
 
@@ -2531,8 +2531,16 @@
 
   // Handle keywords.  Return -1 if the keyword should be ignored.
 
+  bool
+  base_lexer::is_keyword_token (const std::string& s)
+  {
+    int len = s.length ();
+
+    return octave_kw_hash::in_word_set (s.c_str (), len);
+  }
+
   int
-  base_lexer::is_keyword_token (const std::string& s)
+  base_lexer::make_keyword_token (const std::string& s)
   {
     int len = s.length ();
 
@@ -3132,7 +3140,7 @@
     // m_at_beginning_of_statement.  For example, if tok is an IF
     // token, then m_at_beginning_of_statement will be false.
 
-    int kw_token = is_keyword_token (ident);
+    int kw_token = make_keyword_token (ident);
 
     // If we have a regular keyword, return it.
     // Keywords can be followed by identifiers.
@@ -3145,7 +3153,7 @@
             m_looking_for_object_index = false;
           }
 
-        // The call to is_keyword_token set m_at_beginning_of_statement.
+        // The call to make_keyword_token set m_at_beginning_of_statement.
 
         return kw_token;
       }
@@ -3728,7 +3736,7 @@
     // FIXME: input may contain more than one line, so how can we
     // properly start buffering input for command-line functions?
     //
-    // Currently, base_lexer::is_keyword_token starts buffering text
+    // Currently, base_lexer::make_keyword_token starts buffering text
     // for command-line functions by setting the initial value of
     // m_function_text to m_current_input_line when function_kw is
     // recognized.  To make that work, we need to do something like