Mercurial > octave
comparison libinterp/parse-tree/lex.ll @ 23730:85f1d31956c0
make echo work for command-line functions
* file-info.h (file_info::file_info): New constructor from program
text and time when text was processed.
* ov-usr-fcn.h, ov-usr-fcn.cc (octave_user_code::get_file_info):
New function.
(octave_user_code::get_code_line, octave_user_code::get_code_lines):
Use get_file_info to update m_file_info if it is not already defined.
(octave_user_code::cache_function_text): New function.
* lex.h, lex.ll (base_lexer::lexical_feedback::buffer_function_text,
base_lexer::lexical_feedback::function_text): New variables.
(base_lexer::is_keyword_token, lexer::fill_flex_buffer):
Handle buffering of function text command-line functions.
* oct-parse.in.yy (base_parser::finish_function): Cache function text
for command-line functions.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 05 Jul 2017 15:24:55 -0400 |
parents | 08036a7f3660 |
children | ea879bc55272 |
comparison
equal
deleted
inserted
replaced
23729:06b3d1d54054 | 23730:85f1d31956c0 |
---|---|
2159 quote_is_transpose = false; | 2159 quote_is_transpose = false; |
2160 force_script = false; | 2160 force_script = false; |
2161 reading_fcn_file = false; | 2161 reading_fcn_file = false; |
2162 reading_script_file = false; | 2162 reading_script_file = false; |
2163 reading_classdef_file = false; | 2163 reading_classdef_file = false; |
2164 buffer_function_text = false; | |
2164 input_line_number = 1; | 2165 input_line_number = 1; |
2165 current_input_column = 1; | 2166 current_input_column = 1; |
2166 bracketflag = 0; | 2167 bracketflag = 0; |
2167 braceflag = 0; | 2168 braceflag = 0; |
2168 looping = 0; | 2169 looping = 0; |
2172 command_arg_paren_count = 0; | 2173 command_arg_paren_count = 0; |
2173 token_count = 0; | 2174 token_count = 0; |
2174 current_input_line = ""; | 2175 current_input_line = ""; |
2175 comment_text = ""; | 2176 comment_text = ""; |
2176 help_text = ""; | 2177 help_text = ""; |
2178 function_text = ""; | |
2177 string_text = ""; | 2179 string_text = ""; |
2178 string_line = 0; | 2180 string_line = 0; |
2179 string_column = 0; | 2181 string_column = 0; |
2180 fcn_file_name = ""; | 2182 fcn_file_name = ""; |
2181 fcn_file_full_name = ""; | 2183 fcn_file_full_name = ""; |
2728 reading_script_file = false; | 2730 reading_script_file = false; |
2729 } | 2731 } |
2730 | 2732 |
2731 if (! (reading_fcn_file || reading_script_file | 2733 if (! (reading_fcn_file || reading_script_file |
2732 || reading_classdef_file)) | 2734 || reading_classdef_file)) |
2733 input_line_number = 1; | 2735 { |
2736 // Input must be coming from the terminal or stdin? | |
2737 buffer_function_text = true; | |
2738 function_text += (current_input_line + "\n"); | |
2739 | |
2740 input_line_number = 1; | |
2741 } | |
2734 break; | 2742 break; |
2735 | 2743 |
2736 case magic_file_kw: | 2744 case magic_file_kw: |
2737 { | 2745 { |
2738 if ((reading_fcn_file || reading_script_file | 2746 if ((reading_fcn_file || reading_script_file |
3641 | 3649 |
3642 if (input_buf.empty ()) | 3650 if (input_buf.empty ()) |
3643 { | 3651 { |
3644 bool eof = false; | 3652 bool eof = false; |
3645 current_input_line = reader.get_input (eof); | 3653 current_input_line = reader.get_input (eof); |
3654 | |
3646 input_buf.fill (current_input_line, eof); | 3655 input_buf.fill (current_input_line, eof); |
3656 | |
3657 // Attempt to capture text for functions defined on the | |
3658 // command line. | |
3659 // | |
3660 // FIXME: the handling of newline here seems a bit clumsy. | |
3661 // | |
3662 // See also comments in push_lexer::append_input. | |
3663 | |
3664 if (buffer_function_text) | |
3665 { | |
3666 function_text += current_input_line; | |
3667 if (current_input_line[current_input_line.length () - 1] != '\n') | |
3668 function_text += "\n"; | |
3669 } | |
3647 } | 3670 } |
3648 | 3671 |
3649 if (! input_buf.empty ()) | 3672 if (! input_buf.empty ()) |
3650 status = input_buf.copy_chunk (buf, max_size); | 3673 status = input_buf.copy_chunk (buf, max_size); |
3651 else | 3674 else |
3652 status = YY_NULL; | 3675 status = YY_NULL; |
3653 | 3676 |
3654 return status; | 3677 return status; |
3655 } | 3678 } |
3656 | 3679 |
3680 void | |
3681 push_lexer::append_input (const std::string& input, bool eof) | |
3682 { | |
3683 // FIXME: input may contain more than one line, so how can we | |
3684 // properly start buffering input for command-line functions? | |
3685 // | |
3686 // Currently, base_lexer::is_keyword_token starts buffering text | |
3687 // for command-line functions by setting the initial value of | |
3688 // function_text to current_input_line when function_kw is | |
3689 // recognized. To make that work, we need to do something like | |
3690 // maintain a queue of input strings and pass them to the flex | |
3691 // buffer one line at a time, while also setting | |
3692 // current_input_line. Some care will be needed if a single line | |
3693 // of input arrives in multiple calls to append_input. | |
3694 | |
3695 input_buf.fill (input, eof); | |
3696 } | |
3697 | |
3657 int | 3698 int |
3658 push_lexer::fill_flex_buffer (char *buf, unsigned max_size) | 3699 push_lexer::fill_flex_buffer (char *buf, unsigned max_size) |
3659 { | 3700 { |
3660 int status = 0; | 3701 int status = 0; |
3661 | 3702 |