Mercurial > octave
changeset 16164:c5bfdc4c0963
move end_of_input flag from octve_parser class to octave_lexer class
* lex.h, lex.ll, parse.h, oct-parse.yy, toplev.cc
(octave_lexer::end_of_input): Move data member from octave_parser.
Change all uses.
* lex.h, lex.ll (octave_lexer::handle_end_of_input): New function.
(<<EOF>>): Use it.
({CCHAR}, .): USe it instead of simply returning END_OF_INPUT token.
* lex.ll (octave_lexer::xunput): Don't unput EOF.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 01 Mar 2013 07:10:31 -0500 |
parents | 34898b3fc32a |
children | fbc8f7afb193 |
files | libinterp/interpfcn/toplev.cc libinterp/parse-tree/lex.h libinterp/parse-tree/lex.ll libinterp/parse-tree/oct-parse.yy libinterp/parse-tree/parse.h |
diffstat | 5 files changed, 47 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/interpfcn/toplev.cc Thu Feb 28 12:07:23 2013 -0800 +++ b/libinterp/interpfcn/toplev.cc Fri Mar 01 07:10:31 2013 -0500 @@ -639,7 +639,7 @@ command_editor::increment_current_command_number (); } } - else if (curr_parser->end_of_input) + else if (curr_parser->curr_lexer->end_of_input) break; } }
--- a/libinterp/parse-tree/lex.h Thu Feb 28 12:07:23 2013 -0800 +++ b/libinterp/parse-tree/lex.h Fri Mar 01 07:10:31 2013 -0500 @@ -154,7 +154,7 @@ }; octave_lexer (void) - : scanner (0), convert_spaces_to_comma (true), + : scanner (0), end_of_input (false), convert_spaces_to_comma (true), do_comma_insert (false), at_beginning_of_statement (true), looking_at_anon_fcn_args (false), looking_at_return_list (false), looking_at_parameter_list (false), looking_at_decl_list (false), @@ -186,6 +186,8 @@ int octave_read (char *buf, unsigned int max_size); + int handle_end_of_input (void); + char *flex_yytext (void); int flex_yyleng (void); @@ -276,6 +278,9 @@ // Internal state of the flex-generated lexer. void *scanner; + // TRUE means that we have encountered EOF on the input stream. + bool end_of_input; + // TRUE means that we should convert spaces to a comma inside a // matrix definition. bool convert_spaces_to_comma;
--- a/libinterp/parse-tree/lex.ll Thu Feb 28 12:07:23 2013 -0800 +++ b/libinterp/parse-tree/lex.ll Fri Mar 01 07:10:31 2013 -0500 @@ -612,19 +612,7 @@ %} <<EOF>> { - LEXER_DEBUG ("<<EOF>>"); - - if (curr_lexer->block_comment_nesting_level != 0) - { - warning ("block comment open at end of input"); - - if ((reading_fcn_file || reading_script_file || reading_classdef_file) - && ! curr_fcn_file_name.empty ()) - warning ("near line %d of file '%s.m'", - curr_lexer->input_line_number, curr_fcn_file_name.c_str ()); - } - - TOK_RETURN (END_OF_INPUT); + return curr_lexer->handle_end_of_input (); } %{ @@ -776,7 +764,7 @@ int tok = curr_lexer->process_comment (false, eof); if (eof) - TOK_RETURN (END_OF_INPUT); + return curr_lexer->handle_end_of_input (); else if (tok > 0) COUNT_TOK_AND_RETURN (tok); } @@ -975,7 +963,7 @@ return LEXICAL_ERROR; } else - TOK_RETURN (END_OF_INPUT); + return curr_lexer->handle_end_of_input (); } %% @@ -1451,6 +1439,28 @@ return status; } +int +octave_lexer::handle_end_of_input (void) +{ + // FIXME -- we need this because of the way TOK_RETURN is defined. DO + // something better than that... + OCTAVE_YYG; + + LEXER_DEBUG ("<<EOF>>"); + + if (block_comment_nesting_level != 0) + { + warning ("block comment open at end of input"); + + if ((reading_fcn_file || reading_script_file || reading_classdef_file) + && ! curr_fcn_file_name.empty ()) + warning ("near line %d of file '%s.m'", + input_line_number, curr_fcn_file_name.c_str ()); + } + + TOK_RETURN (END_OF_INPUT); +} + char * octave_lexer::flex_yytext (void) { @@ -1525,17 +1535,20 @@ void octave_lexer::xunput (char c, char *buf) { - if (lexer_debug_flag) + if (c != EOF) { - std::cerr << "U: "; - display_character (c); - std::cerr << std::endl; + if (lexer_debug_flag) + { + std::cerr << "U: "; + display_character (c); + std::cerr << std::endl; + } + + if (c == '\n') + input_line_number--; + + yyunput (c, buf, scanner); } - - if (c == '\n') - input_line_number--; - - yyunput (c, buf, scanner); } void
--- a/libinterp/parse-tree/oct-parse.yy Thu Feb 28 12:07:23 2013 -0800 +++ b/libinterp/parse-tree/oct-parse.yy Fri Mar 01 07:10:31 2013 -0500 @@ -342,7 +342,7 @@ { $$ = 0; } | END_OF_INPUT { - curr_parser->end_of_input = true; + curr_lexer->end_of_input = true; $$ = 0; } | simple_list @@ -4301,7 +4301,7 @@ || tree_continue_command::continuing) break; } - else if (curr_parser->end_of_input) + else if (curr_parser->curr_lexer->end_of_input) break; } }
--- a/libinterp/parse-tree/parse.h Thu Feb 28 12:07:23 2013 -0800 +++ b/libinterp/parse-tree/parse.h Fri Mar 01 07:10:31 2013 -0500 @@ -139,7 +139,7 @@ public: octave_parser (void) - : end_of_input (false), endfunction_found (false), + : endfunction_found (false), autoloading (false), fcn_file_from_relative_lookup (false), parsing_subfunctions (false), max_fcn_depth (0), curr_fcn_depth (0), primary_fcn_scope (-1), @@ -341,9 +341,6 @@ // Generic error messages. void bison_error (const char *s); - // TRUE means that we have encountered EOF on the input stream. - bool end_of_input; - // Have we found an explicit end to a function? bool endfunction_found;