comparison libinterp/parse-tree/oct-parse.in.yy @ 16195:b52d2f9294b6

use class for reading lexer input * input.h, input.cc (octave_base_input_reader, octave_terminal_reader, octave_file_reader, octave_eval_string_reader): New classes. (octave_gets): Now a member function of octave_base_reader. (get_user_input): Delete function. Move actions to octave_terminal_reader::get_input and octave_eval_string_reader::get_input. function. Call from octave_file_reader::get_input. Don't check whether reading an eval string. (current_eval_string, get_input_from_eval_string): Delete global variables. (get_debug_input): Check CURR_LEXER->input_from_eval_string instead of global get_input_from_eval_string variable. Don't protect get_input_from_eval_string. * lex.h (octave_lexer::input_reader): New data member. (octave_lexer::octave_lexer (void)): Initialize it. (octave_lexer::octave_lexer (const std::string&), octave_lexer::octave_lexer (FILE *)): New constructors. * lex.h, lex.cc (octave_lexer::input_buffer::fill): New function. (octave_lexer::input_buffer::read): Delete. (octave_lexer::read): Rename from octave_read. Call reader to get input, and then hand it to the input_buffer instead of asking the input buffer to read input. Change all callers. (octave_lexer::input_source, octave_lexer::input_from_eval_string): New functions. Call octave_lexer::input_from_eval_string instead of using get_input_from_eval_string. * oct-parse.in.yy (octave_parser::octave_parser (FILE *), octave_parser::octave_parser (const std::string&)): New constructors. (parse_fcn_file): Pass FILE pointer to octave_parser constructor. (eval_string): Pass string to octave_parser constructor instead of setting global current_eval_string variable.
author John W. Eaton <jwe@octave.org>
date Tue, 05 Mar 2013 10:19:51 -0500
parents 490625211945
children 2c5c538be353
comparison
equal deleted inserted replaced
16194:b7ca669af528 16195:b52d2f9294b6
134 { \ 134 { \
135 yyerrok; \ 135 yyerrok; \
136 if (! parser_symtab_context.empty ()) \ 136 if (! parser_symtab_context.empty ()) \
137 parser_symtab_context.pop (); \ 137 parser_symtab_context.pop (); \
138 if ((interactive || forced_interactive) \ 138 if ((interactive || forced_interactive) \
139 && ! get_input_from_eval_string) \ 139 && ! (curr_lexer)->input_from_eval_string ()) \
140 YYACCEPT; \ 140 YYACCEPT; \
141 else \ 141 else \
142 YYABORT; \ 142 YYABORT; \
143 } \ 143 } \
144 while (0) 144 while (0)
1235 "so must all the others"); 1235 "so must all the others");
1236 YYABORT; 1236 YYABORT;
1237 } 1237 }
1238 1238
1239 if (! (reading_fcn_file || reading_script_file 1239 if (! (reading_fcn_file || reading_script_file
1240 || get_input_from_eval_string)) 1240 || (curr_lexer)->input_from_eval_string ()))
1241 { 1241 {
1242 curr_parser.bison_error ("function body open at end of input"); 1242 curr_parser.bison_error ("function body open at end of input");
1243 YYABORT; 1243 YYABORT;
1244 } 1244 }
1245 1245
3397 bool eof; 3397 bool eof;
3398 3398
3399 // octave_parser constructor sets this for us. 3399 // octave_parser constructor sets this for us.
3400 frame.protect_var (CURR_LEXER); 3400 frame.protect_var (CURR_LEXER);
3401 3401
3402 octave_parser curr_parser; 3402 octave_parser curr_parser (ffile);
3403 3403
3404 curr_parser.curr_class_name = dispatch_type; 3404 curr_parser.curr_class_name = dispatch_type;
3405 curr_parser.autoloading = autoload; 3405 curr_parser.autoloading = autoload;
3406 curr_parser.fcn_file_from_relative_lookup = relative_lookup; 3406 curr_parser.fcn_file_from_relative_lookup = relative_lookup;
3407 3407
3416 3416
3417 if (! eof) 3417 if (! eof)
3418 { 3418 {
3419 std::string file_type; 3419 std::string file_type;
3420 3420
3421 frame.protect_var (get_input_from_eval_string);
3422 frame.protect_var (reading_fcn_file); 3421 frame.protect_var (reading_fcn_file);
3423 frame.protect_var (reading_script_file); 3422 frame.protect_var (reading_script_file);
3424 frame.protect_var (reading_classdef_file); 3423 frame.protect_var (reading_classdef_file);
3425 frame.protect_var (Vecho_executing_commands); 3424 frame.protect_var (Vecho_executing_commands);
3426
3427 get_input_from_eval_string = false;
3428 3425
3429 if (! force_script && looking_at_function_keyword (ffile)) 3426 if (! force_script && looking_at_function_keyword (ffile))
3430 { 3427 {
3431 file_type = "function"; 3428 file_type = "function";
3432 3429
4179 4176
4180 return retval; 4177 return retval;
4181 } 4178 }
4182 4179
4183 octave_value_list 4180 octave_value_list
4184 eval_string (const std::string& s, bool silent, int& parse_status, int nargout) 4181 eval_string (const std::string& eval_str, bool silent,
4182 int& parse_status, int nargout)
4185 { 4183 {
4186 octave_value_list retval; 4184 octave_value_list retval;
4187 4185
4188 unwind_protect frame; 4186 unwind_protect frame;
4189 4187
4190 // octave_parser constructor sets this for us. 4188 // octave_parser constructor sets this for us.
4191 frame.protect_var (CURR_LEXER); 4189 frame.protect_var (CURR_LEXER);
4192 4190
4193 octave_parser curr_parser; 4191 octave_parser curr_parser (eval_str);
4194 4192
4195 frame.protect_var (get_input_from_eval_string);
4196 frame.protect_var (line_editing); 4193 frame.protect_var (line_editing);
4197 frame.protect_var (current_eval_string);
4198 frame.protect_var (reading_fcn_file); 4194 frame.protect_var (reading_fcn_file);
4199 frame.protect_var (reading_script_file); 4195 frame.protect_var (reading_script_file);
4200 frame.protect_var (reading_classdef_file); 4196 frame.protect_var (reading_classdef_file);
4201 4197
4202 get_input_from_eval_string = true;
4203 line_editing = false; 4198 line_editing = false;
4204 reading_fcn_file = false; 4199 reading_fcn_file = false;
4205 reading_script_file = false; 4200 reading_script_file = false;
4206 reading_classdef_file = false; 4201 reading_classdef_file = false;
4207
4208 current_eval_string = s;
4209 4202
4210 do 4203 do
4211 { 4204 {
4212 curr_parser.reset (); 4205 curr_parser.reset ();
4213 4206
4276 4269
4277 return retval; 4270 return retval;
4278 } 4271 }
4279 4272
4280 octave_value 4273 octave_value
4281 eval_string (const std::string& s, bool silent, int& parse_status) 4274 eval_string (const std::string& eval_str, bool silent, int& parse_status)
4282 { 4275 {
4283 octave_value retval; 4276 octave_value retval;
4284 4277
4285 octave_value_list tmp = eval_string (s, silent, parse_status, 1); 4278 octave_value_list tmp = eval_string (eval_str, silent, parse_status, 1);
4286 4279
4287 if (! tmp.empty ()) 4280 if (! tmp.empty ())
4288 retval = tmp(0); 4281 retval = tmp(0);
4289 4282
4290 return retval; 4283 return retval;