changeset 27514:cc023f049dbf

use Bison's push parser interface in the command line REPL Using the push parser interface moves reading input and lexical analysis outside of the parser. This change shows how we might also use this arrangement to allow the GUI terminal widget to be fully in control of gathering user input. A new configure option allows this change to be reverted so that Octave will use the pull parser interface that has been used in all previous versions of Octave. * pt-eval.cc (tree_evaluator::repl): Use conditional compilation to choose either push or pull parser. * configure.ac (--disable-commnad-line-push-parser): New option. Report option setting in summary message.
author John W. Eaton <jwe@octave.org>
date Fri, 11 Oct 2019 13:07:10 -0400
parents 28ed77ca1e4a
children 466e61c5fb4b
files configure.ac libinterp/parse-tree/pt-eval.cc
diffstat 2 files changed, 51 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Wed Oct 16 10:16:17 2019 -0400
+++ b/configure.ac	Fri Oct 11 13:07:10 2019 -0400
@@ -1326,6 +1326,18 @@
 ## Find a termlib to use.
 OCTAVE_CHECK_LIB_TERMLIB
 
+### Use push parser by default now.
+
+ENABLE_COMMAND_LINE_PUSH_PARSER=yes
+AC_ARG_ENABLE([command-line-push-parser],
+  [AS_HELP_STRING([--disable-command-line-push-parser],
+    [don't use Bison's push parser interface in the command line REPL])],
+  [if test "$enableval" = no; then ENABLE_COMMAND_LINE_PUSH_PARSER=no; fi], [])
+if test $ENABLE_COMMAND_LINE_PUSH_PARSER = yes; then
+  AC_DEFINE(OCTAVE_ENABLE_COMMAND_LINE_PUSH_PARSER, 1,
+    [Define to 1 to use Bison's push parser interface in the command line REPL.])
+fi
+
 ### Check for ZLIB library.
 
 OCTAVE_CHECK_LIB(z, ZLIB,
@@ -3113,6 +3125,7 @@
   Build shared libraries:               $SHARED_LIBS
   Dynamic Linking API:                  $DL_API_MSG
   Include support for GNU readline:     $USE_READLINE
+  Use push parser in comand line REPL:  $ENABLE_COMMAND_LINE_PUSH_PARSER
   64-bit array dims and indexing:       $ENABLE_64
   64-bit BLAS array dims and indexing:  $HAVE_64_BIT_BLAS
   OpenMP SMP multithreading:            $ENABLE_OPENMP
--- a/libinterp/parse-tree/pt-eval.cc	Wed Oct 16 10:16:17 2019 -0400
+++ b/libinterp/parse-tree/pt-eval.cc	Fri Oct 11 13:07:10 2019 -0400
@@ -363,13 +363,27 @@
   {
     int retval = 0;
 
-    // The parser takes ownership of the lexer and will delete it when
-    // the parser goes out of scope.
+#if defined (OCTAVE_ENABLE_COMMAND_LINE_PUSH_PARSER)
+
+    input_reader reader (m_interpreter);
+
+    // Attach input_reader object to parser so that the promptflag can
+    // be adjusted automatically when we are parsing multi-line
+    // commands.
+
+    push_parser repl_parser (m_interpreter, &reader);
+
+#else
+
+    // The pull parser takes ownership of the lexer and will delete it
+    // when the parser goes out of scope.
 
     parser repl_parser (interactive
                         ? new lexer (m_interpreter)
                         : new lexer (stdin, m_interpreter));
 
+#endif
+
     error_system& es = m_interpreter.get_error_system ();
 
     do
@@ -386,8 +400,30 @@
                 reset_debug_state ();
               }
 
+#if defined (OCTAVE_ENABLE_COMMAND_LINE_PUSH_PARSER)
+
+            do
+              {
+                bool eof;
+
+                std::string input_line = reader.get_input (eof);
+
+                if (eof)
+                  {
+                    retval = EOF;
+                    break;
+                  }
+
+                retval = repl_parser.run (input_line, false);
+              }
+            while (retval < 0);
+
+#else
+
             retval = repl_parser.run ();
 
+#endif
+
             if (retval == 0)
               {
                 std::shared_ptr<tree_statement_list> stmt_list