Mercurial > octave
changeset 27528:e51284fc0a51
eliminate promptflag from the lexer and input reader classes
We can use a much simpler method for determining whether to display
the primary or secondary prompt.
* input.h (base_reader::m_pflag): Delete member variable and all uses.
(base_reader::increment_promptflag, base_reader::decrement_promptflag,
base_reader::promptflag): Delete member functions and all uses.
(input_reader::increment_promptflag, input_reader::decrement_promptflag,
input_reader::promptflag): Delete member functions and all uses.
* interpreter.cc (interpreter::main_loop): For push parser, use
primary prompt on initial call for input, secondary prompt if
parser/lexer is asking for additional input.
* lex.h, lex.ll (base_lexer::increment_promptflag,
base_lexer::decrement_promptflag, base_lexer::promptflag):
Delete member functions and all uses.
(lexer::m_initial_input): New variable.
(lexer::reset): Also reset m_initial_input.
(lexer::fill_flex_buffer): Use primary prompt on initial call for
input, secondary prompt if parser/lexer is asking for additional input.
* parse.h (base_parser::increment_promptflag,
base_parser::decrement_promptflag, base_parser::promptflag):
Delete member functions and all uses.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 18 Oct 2019 11:06:11 -0400 |
parents | 73be3c628eac |
children | 886df2049d81 |
files | libinterp/corefcn/input.h libinterp/corefcn/interpreter.cc libinterp/parse-tree/lex.h libinterp/parse-tree/lex.ll libinterp/parse-tree/parse.h |
diffstat | 5 files changed, 23 insertions(+), 94 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/input.h Fri Oct 18 09:08:06 2019 -0400 +++ b/libinterp/corefcn/input.h Fri Oct 18 11:06:11 2019 -0400 @@ -198,11 +198,11 @@ friend class input_reader; base_reader (interpreter& interp) - : m_interpreter (interp), m_pflag (0) + : m_interpreter (interp) { } base_reader (const base_reader& x) - : m_interpreter (x.m_interpreter), m_pflag (x.m_pflag) + : m_interpreter (x.m_interpreter) { } virtual ~base_reader (void) = default; @@ -211,21 +211,6 @@ virtual std::string input_source (void) const { return s_in_src; } - void reset (void) { promptflag (1); } - - 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 octave_gets (const std::string& prompt, bool& eof); virtual bool input_from_terminal (void) const { return false; } @@ -240,8 +225,6 @@ private: - int m_pflag; - static const std::string s_in_src; }; @@ -261,16 +244,6 @@ ~input_reader (void) = default; - void reset (void) { return m_rep->reset (); } - - void increment_promptflag (void) { m_rep->increment_promptflag (); } - - void decrement_promptflag (void) { m_rep->decrement_promptflag (); } - - int promptflag (void) const { return m_rep->promptflag (); } - - int promptflag (int n) { return m_rep->promptflag (n); } - std::string get_input (const std::string& prompt, bool& eof) { return m_rep->get_input (prompt, eof);
--- a/libinterp/corefcn/interpreter.cc Fri Oct 18 09:08:06 2019 -0400 +++ b/libinterp/corefcn/interpreter.cc Fri Oct 18 11:06:11 2019 -0400 @@ -995,10 +995,6 @@ input_reader reader (*this); - // 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 (*this); #else @@ -1027,16 +1023,11 @@ #if defined (OCTAVE_ENABLE_COMMAND_LINE_PUSH_PARSER) + std::string prompt + = command_editor::decode_prompt_string (m_input_system.PS1 ()); + do { - int promptflag = repl_parser.promptflag (); - - std::string ps - = (promptflag > 0 - ? m_input_system.PS1 () : m_input_system.PS2 ()); - - std::string prompt = command_editor::decode_prompt_string (ps); - bool eof = false; std::string input_line = reader.get_input (prompt, eof); @@ -1047,6 +1038,8 @@ } retval = repl_parser.run (input_line, false); + + prompt = command_editor::decode_prompt_string (m_input_system.PS2 ()); } while (retval < 0);
--- a/libinterp/parse-tree/lex.h Fri Oct 18 09:08:06 2019 -0400 +++ b/libinterp/parse-tree/lex.h Fri Oct 18 11:06:11 2019 -0400 @@ -709,21 +709,6 @@ // Object that collects comment text. comment_buffer m_comment_buf; - int m_promptflag; - - void increment_promptflag (void) { m_promptflag++; } - - void decrement_promptflag (void) { m_promptflag--; } - - int promptflag (void) const { return m_promptflag; } - - int promptflag (int n) - { - int retval = m_promptflag; - m_promptflag = n; - return retval; - } - virtual std::string input_source (void) const { return "unknown"; } virtual bool input_from_terminal (void) const { return false; } @@ -782,15 +767,16 @@ public: lexer (interpreter& interp) - : base_lexer (interp), m_reader (interp) + : base_lexer (interp), m_reader (interp), m_initial_input (true) { } lexer (FILE *file, interpreter& interp) - : base_lexer (interp), m_reader (interp, file) + : base_lexer (interp), m_reader (interp, file), m_initial_input (true) { } lexer (const std::string& eval_string, interpreter& interp) - : base_lexer (interp), m_reader (interp, eval_string) + : base_lexer (interp), m_reader (interp, eval_string), + m_initial_input (true) { } // No copying! @@ -801,7 +787,7 @@ void reset (void) { - m_reader.reset (); + m_initial_input = true; base_lexer::reset (); } @@ -829,6 +815,13 @@ int fill_flex_buffer (char *buf, unsigned int max_size); input_reader m_reader; + + // TRUE means we are filling the input buffer for the first time. + // Otherwise, we are requesting more input to complete the parse + // and, if printing a prompt, should use the secondary prompt + // string. + + bool m_initial_input; }; class
--- a/libinterp/parse-tree/lex.ll Fri Oct 18 09:08:06 2019 -0400 +++ b/libinterp/parse-tree/lex.ll Fri Oct 18 11:06:11 2019 -0400 @@ -245,7 +245,6 @@ #define HANDLE_STRING_CONTINUATION \ do \ { \ - curr_lexer->decrement_promptflag (); \ curr_lexer->m_input_line_number++; \ curr_lexer->m_current_input_column = 1; \ \ @@ -609,8 +608,6 @@ else curr_lexer->m_looking_at_matrix_or_assign_lhs = true; - curr_lexer->decrement_promptflag (); - curr_lexer->m_bracketflag++; curr_lexer->push_start_state (MATRIX_START); @@ -655,8 +652,6 @@ curr_lexer->pop_start_state (); } - curr_lexer->decrement_promptflag (); - curr_lexer->push_start_state (BLOCK_COMMENT_START); } @@ -693,11 +688,7 @@ curr_lexer->m_block_comment_nesting_level--; if (curr_lexer->m_block_comment_nesting_level == 0) - { - curr_lexer->increment_promptflag (); - - curr_lexer->pop_start_state (); - } + curr_lexer->pop_start_state (); } %{ @@ -1679,7 +1670,6 @@ curr_lexer->m_at_beginning_of_statement = false; curr_lexer->m_nesting_level.paren (); - curr_lexer->decrement_promptflag (); return curr_lexer->handle_token ('('); } @@ -1787,8 +1777,6 @@ curr_lexer->m_looking_for_object_index = false; curr_lexer->m_at_beginning_of_statement = false; - curr_lexer->decrement_promptflag (); - curr_lexer->m_braceflag++; curr_lexer->push_start_state (MATRIX_START); @@ -2401,9 +2389,6 @@ m_symtab_context.clear (); - // We do want a prompt by default. - promptflag (1); - // Only ask for input from stdin if we are expecting interactive // input. @@ -2687,25 +2672,21 @@ case for_kw: case parfor_kw: case while_kw: - decrement_promptflag (); m_looping++; break; case do_kw: m_at_beginning_of_statement = true; - decrement_promptflag (); m_looping++; break; case try_kw: case unwind_protect_kw: m_at_beginning_of_statement = true; - decrement_promptflag (); break; case if_kw: case switch_kw: - decrement_promptflag (); break; case get_kw: @@ -2734,8 +2715,6 @@ case classdef_kw: // 'classdef' is always a keyword. - decrement_promptflag (); - if (! m_force_script && m_token_count == 0 && input_from_file ()) { m_reading_classdef_file = true; @@ -2744,8 +2723,6 @@ break; case function_kw: - decrement_promptflag (); - m_defining_func++; m_parsed_function_name.push (false); @@ -2975,7 +2952,6 @@ m_at_beginning_of_statement = saved_bos; } - decrement_promptflag (); m_input_line_number++; m_current_input_column = 1; } @@ -3714,7 +3690,7 @@ input_system& input_sys = m_interpreter.get_input_system (); std::string ps - = promptflag () > 0 ? input_sys.PS1 () : input_sys.PS2 (); + = m_initial_input ? input_sys.PS1 () : input_sys.PS2 (); std::string prompt = command_editor::decode_prompt_string (ps); @@ -3746,6 +3722,8 @@ else status = YY_NULL; + m_initial_input = false; + return status; }
--- a/libinterp/parse-tree/parse.h Fri Oct 18 09:08:06 2019 -0400 +++ b/libinterp/parse-tree/parse.h Fri Oct 18 11:06:11 2019 -0400 @@ -457,14 +457,6 @@ const std::string& package_name, bool require_file, bool force_script, bool autoload, bool relative_lookup); - void increment_promptflag (void) { m_lexer.increment_promptflag (); } - - void decrement_promptflag (void) { m_lexer.decrement_promptflag (); } - - int promptflag (void) const { return m_lexer.promptflag (); } - - int promptflag (int n) { return m_lexer.promptflag (n); } - protected: // Contains error message if Bison-generated parser returns non-zero