Mercurial > hg > octave-nkf
diff libinterp/parse-tree/lex.h @ 16183:359d56094efa
handle lexer input buffering with class
* lex.h, lex.ll (octave_lexer::input_buffer): New class.
(octave_lexer::input_buf): New data member.
(octave_lexer::octave_lexer): Initialize it.
(octave_lexer::octave_read): Use input_buf to simplify function and
replace static data.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 03 Mar 2013 14:02:41 -0500 |
parents | c5bfdc4c0963 |
children | e810e7d941a1 |
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.h +++ b/libinterp/parse-tree/lex.h @@ -153,6 +153,34 @@ std::stack<int> context; }; + // Handle buffering of input for lexer. + + class input_buffer + { + public: + + input_buffer (void) + : buffer (), pos (0), chars_left (0), eof (false) + { } + + // Grab more input from the current input source. + void read (void); + + // Copy at most max_size characters to buf. + int copy_chunk (char *buf, size_t max_size); + + bool empty (void) const { return chars_left == 0; } + + bool at_eof (void) const { return eof; } + + private: + + std::string buffer; + const char *pos; + size_t chars_left; + bool eof; + }; + octave_lexer (void) : scanner (0), end_of_input (false), convert_spaces_to_comma (true), do_comma_insert (false), at_beginning_of_statement (true), @@ -169,7 +197,7 @@ looping (0), defining_func (0), looking_at_function_handle (0), block_comment_nesting_level (0), looking_at_object_index (), parsed_function_name (), - pending_local_variables (), nesting_level () + pending_local_variables (), nesting_level (), input_buf () { init (); } @@ -374,6 +402,9 @@ // a paren? bbp_nesting_level nesting_level; + // Object that reads and buffers input. + input_buffer input_buf; + // For unwind protect. static void cleanup (octave_lexer *lexer) { delete lexer; }