diff libinterp/parse-tree/lex.h @ 27527:73be3c628eac

refactor input_reader class and its use in lexer * input.h, input.cc (base_reader::get_input, file_reader::get_input, terminal_reader::get_input, eval_string_reader::get_input): Accept prompt as argument. Change all uses. (base_reader::octave_gets): Accept prompt as argument instead of getting it from input_system. Change all uses. * interpreter.cc (interpreter::main_loop): Get promptflag from parser, prompt string from input_system, decode it here, and pass to the input reader. * lex.h, lex.ll (base_lexer::m_promptflag): New data member. (base_lexer::reset): Also reset m_promptflag. (base_lexer::increment_promptflag, base_lexer::decrement_promptflag, base_lexer::promptflag): No longer virtual. (lexer::increment_promptflag, lexer::decrement_promptflag, lexer::promptflag): Delete. (push_lexer::m_pflag): Delete. (push_lexer::increment_promptflag, push_lexer::decrement_promptflag, push_lexer::promptflag): Delete. (push_lexer::reset): Delete. (lexer::fill_flex_buffer): Get prompt string from input_system, decode it here, and pass to the input reader. * parse.h (base_parser::increment_promptflag, base_parser::decrement_promptflag, base_parser::promptflag): New convenience functions.
author John W. Eaton <jwe@octave.org>
date Fri, 18 Oct 2019 09:08:06 -0400
parents cb964b74d8a0
children e51284fc0a51
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.h	Fri Oct 18 07:41:02 2019 -0400
+++ b/libinterp/parse-tree/lex.h	Fri Oct 18 09:08:06 2019 -0400
@@ -709,13 +709,20 @@
     // Object that collects comment text.
     comment_buffer m_comment_buf;
 
-    virtual void increment_promptflag (void) = 0;
+    int m_promptflag;
 
-    virtual void decrement_promptflag (void) = 0;
+    void increment_promptflag (void) { m_promptflag++; }
+
+    void decrement_promptflag (void) { m_promptflag--; }
 
-    virtual int promptflag (void) const = 0;
+    int promptflag (void) const { return m_promptflag; }
 
-    virtual int promptflag (int) = 0;
+    int promptflag (int n)
+    {
+      int retval = m_promptflag;
+      m_promptflag = n;
+      return retval;
+    }
 
     virtual std::string input_source (void) const { return "unknown"; }
 
@@ -799,14 +806,6 @@
       base_lexer::reset ();
     }
 
-    void increment_promptflag (void) { m_reader.increment_promptflag (); }
-
-    void decrement_promptflag (void) { m_reader.decrement_promptflag (); }
-
-    int promptflag (void) const { return m_reader.promptflag (); }
-
-    int promptflag (int n) { return m_reader.promptflag (n); }
-
     std::string input_source (void) const
     {
       return m_reader.input_source ();
@@ -838,25 +837,25 @@
   public:
 
     push_lexer (interpreter& interp)
-      : base_lexer (interp), m_pflag (1)
+      : base_lexer (interp)
     {
       append_input ("", false);
     }
 
     push_lexer (const std::string& input, interpreter& interp)
-      : base_lexer (interp), m_pflag (1)
+      : base_lexer (interp)
     {
       append_input (input, false);
     }
 
     push_lexer (bool eof, interpreter& interp)
-      : base_lexer (interp), m_pflag (1)
+      : base_lexer (interp)
     {
       append_input ("", eof);
     }
 
     push_lexer (const std::string& input, bool eof, interpreter& interp)
-      : base_lexer (interp), m_pflag (1)
+      : base_lexer (interp)
     {
       append_input (input, eof);
     }
@@ -869,35 +868,11 @@
 
     bool is_push_lexer (void) const { return true; }
 
-    void reset (void)
-    {
-      promptflag (1);
-
-      base_lexer::reset ();
-    }
-
     void append_input (const std::string& input, bool eof);
 
-    void increment_promptflag (void) { m_pflag++; }
-
-    void decrement_promptflag (void) { m_pflag--; }
-
-    int promptflag (void) const { return m_pflag; }
-
-    int promptflag (int n)
-    {
-      int retval = m_pflag;
-      m_pflag = n;
-      return retval;
-    }
-
     std::string input_source (void) const { return "push buffer"; }
 
     int fill_flex_buffer (char *buf, unsigned int max_size);
-
-  protected:
-
-    int m_pflag;
   };
 }