Mercurial > hg > octave-nkf
diff libinterp/parse-tree/lex.h @ 16203:127cccb037bf
move more global parser and lexer variables to classes
* pt-check.h, pt-check.cc (tree_checker::file_name): New data member.
(tree_checker::gripe): Use it instead of curr_fcn_file_name.
* input.h, input.cc, octave.cc (input_from_command_line_file):
Delete global variable and all uses.
* parse.h, oct-parse.in.yy (input_from_startup_file): Delete global
variable and all uses.
* input.h, input.cc, lex.h, lex.ll (curr_fcn_file_name,
curr_fcn_file_full_name): Declare as members of lexical_feedback
class. Rename to fcn_file_name and fcn_file_full_name. Change all
uses.
* oct-parse.in.yy (parse_fcn_file): New arg, file. Set
curr_lexer->fcn_file_name and curr_lexer->fcn_file_full_name here.
(load_fcn_from_file): Pass short file name to parse_fcn_file.
* octave.cc (execute_command_line_file): Not here.
* lex.h, lex.ll (lexical_feedback::force_script): New data member.
* oct-parse.in.yy (parse_fcn_file): Set it here.
* lex.h, lex.ll (lexical_feedback::input_from_terminal,
lexical_feedback::input_from_file): New functions.
* lex.ll (octave_lexer::handle_keyword): Set reading_fcn_file,
reading_classdef_file, and reading_script_file.
* lex.h, lex.ll (lexical_feedback::token_count): New variable.
(COUNT_TOK_AND_RETURN): Increment it here. Don't count '\n' as a
token.
* lex.h, lex.ll (lexical_feedback::help_text):
New variable.
* parse.h, parse.in.yy (help_buf): Delete global variable and all uses.
(octave_parser::frob_function, octave_parser::make_script): Use help_text.
* lex.ll (octave_lexer::process_comment): Cache doc string directly in
help_text variable.
(looks_like_copyright): Move here from parse.in.yy.
* lex.h, lex.ll (octave_lexer::prep_for_file): New function.
(octave_lexer::prep_for_function_file,
octave_lexer::prep_for_script_file): Delete.
* parse.in.yy (INPUT_FILE_BEGIN): New start state. Delete
SCRIPT_FILE_BEGIN and FCN_FILE_BEGIN. Tentatively set
curr_lexer->reading_script_file to true.
(parse_fcn_file): Call curr_lexer->prep_for_file.
Don't call gobble_leading_whitespace. Don't attempt to determine
function script, or classdef file status here.
* parse.in.yy (INPUT_FILE): New token.
(SCRIPT_FILE, FUNCTION_FILE): Delete.
* lex.ll (octave_lexer::display_token): Update.
* parse.in.yy (nl, opt_nl): New non-terminals.
(function_file): Delete rule.
(file): Rename from script_file. Allow opt_nl before opt_list.
Don't make script if reading fcn file.
* parse.in.yy (text_getc, class stdio_stream_reader, skip_white_space,
looking_at_classdef_keyword, gobble_leading_white_space,
looking_at_function_keyword): Delete.
(get_help_from_file): Parse file to get help instead of calling
gobble_leading_white_space
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 06 Mar 2013 14:36:19 -0500 |
parents | 810a71122c25 |
children | a8f9eb92fa6e 0467d68ca891 |
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.h +++ b/libinterp/parse-tree/lex.h @@ -170,12 +170,14 @@ looking_for_object_index (false), looking_at_indirect_ref (false), parsing_class_method (false), maybe_classdef_get_set_method (false), parsing_classdef (false), - quote_is_transpose (false), reading_fcn_file (false), - reading_script_file (false), reading_classdef_file (false), + quote_is_transpose (false), force_script (false), + reading_fcn_file (false), reading_script_file (false), + reading_classdef_file (false), input_line_number (1), current_input_column (1), bracketflag (0), braceflag (0), looping (0), defining_func (0), looking_at_function_handle (0), - block_comment_nesting_level (0), + block_comment_nesting_level (0), token_count (0), + help_text (), fcn_file_name (), fcn_file_full_name (), looking_at_object_index (), parsed_function_name (), pending_local_variables (), nesting_level (), token_stack () { @@ -244,6 +246,10 @@ // return transpose or start a string? bool quote_is_transpose; + // TRUE means treat the current file as a script even if the first + // token is "function" or "classdef". + bool force_script; + // TRUE means we're parsing a function file. bool reading_fcn_file; @@ -277,6 +283,19 @@ // nestng level for blcok comments. int block_comment_nesting_level; + // Count of tokens recognized by this lexer since initialized or + // since the last reset. + size_t token_count; + + // The current help text. + std::string help_text; + + // Simple name of function file we are reading. + std::string fcn_file_name; + + // Full name of file we are reading. + std::string fcn_file_full_name; + // if the front of the list is true, the closest paren, brace, or // bracket nesting is an index for an object. std::list<bool> looking_at_object_index; @@ -372,9 +391,7 @@ void reset (void); - void prep_for_script_file (void); - - void prep_for_function_file (void); + void prep_for_file (void); int read (char *buf, unsigned int max_size); @@ -480,6 +497,16 @@ return input_reader.input_source (); } + bool input_from_terminal (void) const + { + return input_source () == "terminal"; + } + + bool input_from_file (void) const + { + return input_source () == "file"; + } + bool input_from_eval_string (void) const { return input_source () == "eval_string";