changeset 29915:28a39ddabbfc

allow unrecognized characters to begin command-style function call parsing * lex.ll (.): Instead of always producing a lexical error, allow an otherwise unrecognized character to trigger command-style function call parsing if the previous token may be a token and is followed by a space.
author John W. Eaton <jwe@octave.org>
date Fri, 23 Jul 2021 11:59:40 -0400
parents daf351544539
children 0bf14f708dc6
files libinterp/parse-tree/lex.ll
diffstat 1 files changed, 38 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.ll	Fri Jul 23 09:26:35 2021 +0200
+++ b/libinterp/parse-tree/lex.ll	Fri Jul 23 11:59:40 2021 -0400
@@ -1880,40 +1880,52 @@
   }
 
 %{
-// Unrecognized input is a lexical error.
+// Unrecognized input.  If the previous token may be a command and is
+// followed by a space, parse the remainder of this statement as a
+// command-style function call.  Otherwise, unrecognized input is a
+// lexical error.
 %}
 
 . {
     curr_lexer->lexer_debug (".");
 
-    curr_lexer->xunput (yytext[0]);
-
-    int c = curr_lexer->text_yyinput ();
-
-    if (c == 1)
-      return -1;
-    else if (c == EOF)
-      return curr_lexer->handle_end_of_input ();
+    if (curr_lexer->previous_token_may_be_command ()
+        && curr_lexer->space_follows_previous_token ())
+      {
+        yyless (0);
+        curr_lexer->push_start_state (COMMAND_START);
+      }
     else
       {
-        std::ostringstream buf;
-
-        buf << "invalid character '"
-            << octave::undo_string_escape (static_cast<char> (c))
-            << "' (ASCII " << c << ")";
-
-        // Use current file position for error token.
-        octave::token *tok
-          = new octave::token (LEXICAL_ERROR, buf.str (),
-                               curr_lexer->m_filepos, curr_lexer->m_filepos);
-
-        curr_lexer->push_token (tok);
-
-        curr_lexer->m_filepos.increment_column ();
-
-        return curr_lexer->count_token_internal (LEXICAL_ERROR);
+        curr_lexer->xunput (yytext[0]);
+
+        int c = curr_lexer->text_yyinput ();
+
+        if (c == 1)
+          return -1;
+        else if (c == EOF)
+          return curr_lexer->handle_end_of_input ();
+        else
+          {
+            std::ostringstream buf;
+
+            buf << "invalid character '"
+                << octave::undo_string_escape (static_cast<char> (c))
+                << "' (ASCII " << c << ")";
+
+            // Use current file position for error token.
+            octave::token *tok
+              = new octave::token (LEXICAL_ERROR, buf.str (),
+                                   curr_lexer->m_filepos, curr_lexer->m_filepos);
+
+            curr_lexer->push_token (tok);
+
+            curr_lexer->m_filepos.increment_column ();
+
+            return curr_lexer->count_token_internal (LEXICAL_ERROR);
+          }
       }
-  }
+}
 
 %{
 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)