26 #if ! defined (octave_lex_h)
27 #define octave_lex_h 1
29 #include "octave-config.h"
47 extern bool iskeyword (
const std::string& s);
63 : m_interpreter (interp), m_frame_stack () { }
71 bool empty ()
const {
return m_frame_stack.empty (); }
73 std::size_t
size ()
const {
return m_frame_stack.size (); }
79 m_frame_stack.push_front (scope);
89 std::deque<symbol_scope> m_frame_stack;
111 : m_context (nl.m_context)
117 m_context = nl.m_context;
131 return ! m_context.empty () && m_context.top () == BRACKET;
134 void brace () { m_context.push (BRACE); }
138 return ! m_context.empty () && m_context.top () == BRACE;
141 void paren () { m_context.push (PAREN); }
145 return ! m_context.empty () && m_context.top () == PAREN;
152 return ! m_context.empty () && m_context.top () == ANON_FCN_BODY;
157 return (! m_context.empty ()
158 && (m_context.top () == BRACKET || m_context.top () == BRACE));
161 bool none () {
return m_context.empty (); }
165 if (! m_context.empty ())
171 while (! m_context.empty ())
177 std::stack<int> m_context;
204 m_buffer.push_front (tok);
211 delete m_buffer.back ();
212 m_buffer.pop_back ();
219 return empty () ? nullptr : m_buffer.at (
n);
224 return empty () ? nullptr : m_buffer.at (
n);
230 return empty () ? nullptr : m_buffer.front ();
235 return empty () ? nullptr : m_buffer.front ();
240 return empty () ? nullptr : m_buffer.back ();
245 return empty () ? nullptr : m_buffer.back ();
249 std::size_t
size ()
const {
return m_buffer.size (); }
251 bool empty ()
const {
return m_buffer.empty (); }
261 std::deque<token *> m_buffer;
265 : m_interpreter (interp),
266 m_end_of_input (false),
267 m_allow_command_syntax (true),
268 m_at_beginning_of_statement (true),
269 m_looking_at_anon_fcn_args (false),
270 m_looking_at_return_list (false),
271 m_looking_at_parameter_list (false),
272 m_looking_at_decl_list (false),
273 m_looking_at_matrix_or_assign_lhs (false),
274 m_looking_for_object_index (false),
275 m_looking_at_indirect_ref (false),
276 m_arguments_is_keyword (false),
277 m_classdef_element_names_are_keywords (false),
278 m_parsing_anon_fcn_body (false),
279 m_parsing_class_method (false),
280 m_parsing_classdef (false),
281 m_parsing_classdef_decl (false),
282 m_parsing_classdef_superclass (false),
283 m_maybe_classdef_get_set_method (false),
284 m_parsing_classdef_get_method (false),
285 m_parsing_classdef_set_method (false),
286 m_quote_is_transpose (false),
287 m_force_script (false),
288 m_reading_fcn_file (false),
289 m_reading_script_file (false),
290 m_reading_classdef_file (false),
291 m_buffer_function_text (false),
292 m_comment_uses_hash_char (false),
297 m_looking_at_function_handle (0),
298 m_block_comment_nesting_level (0),
299 m_command_arg_paren_count (0),
305 m_current_input_line (),
309 m_fcn_file_full_name (),
312 m_looking_at_object_index (),
313 m_parsed_function_name (),
314 m_symtab_context (interp),
329 int previous_token_value ()
const;
331 bool previous_token_value_is (
int tok_val)
const;
333 void mark_previous_token_trailing_space ();
335 bool space_follows_previous_token ()
const;
337 bool previous_token_is_binop ()
const;
339 bool previous_token_is_keyword ()
const;
341 bool previous_token_may_be_command ()
const;
343 void mark_as_variable (
const std::string& nm);
344 void mark_as_variables (
const std::list<std::string>& lst);
539 : m_buffer (), m_offset (0), m_chars_left (0), m_eof (false)
544 void fill (
const std::string& input,
bool eof_arg);
547 int copy_chunk (
char *buf, std::size_t max_size,
bool by_lines =
false);
549 bool empty ()
const {
return m_chars_left == 0; }
555 std::string m_buffer;
556 std::size_t m_offset;
557 std::size_t m_chars_left;
576 if (! m_comment_list)
579 m_comment_list->append (s, t, uses_hash_char);
588 m_comment_list =
nullptr;
595 delete m_comment_list;
597 m_comment_list =
nullptr;
612 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (
base_lexer)
620 virtual void reset ();
622 void prep_for_file ();
624 void begin_string (
int state);
632 int handle_end_of_input ();
634 char * flex_yytext ();
640 void xunput (
char c,
char *buf);
642 void xunput (
char c);
644 void update_token_positions (
int tok_len);
646 bool looking_at_space ();
648 bool inside_any_object_index ();
650 int make_keyword_token (
const std::string& s);
652 bool fq_identifier_contains_keyword (
const std::string& s);
654 bool whitespace_is_significant ();
660 void handle_continuation ();
666 int handle_close_bracket (
int bracket_type);
668 bool looks_like_command_arg ();
670 int handle_superclass_identifier ();
672 int handle_meta_identifier ();
674 int handle_fq_identifier ();
676 int handle_identifier ();
678 void check_comment_for_hash_char (
const char *txt, std::size_t
len);
680 void maybe_warn_separator_insert (
char sep);
682 void warn_language_extension (
const std::string& msg);
684 void maybe_warn_language_extension_comment (
char c);
686 void warn_language_extension_continuation ();
688 void warn_language_extension_operator (
const std::string& op);
690 void warn_deprecated_syntax (
const std::string& msg);
692 void push_token (
token *);
694 token * current_token ();
696 std::size_t pending_token_count ()
const;
698 void display_token (
int tok);
700 void fatal_error (
const char *msg);
702 bool debug_flag ()
const;
704 bool display_tokens ()
const;
706 void increment_token_count ();
708 void lexer_debug (
const char *pattern);
727 bool input_from_tmp_history_file ();
729 void push_start_state (
int state);
731 void pop_start_state ();
733 void clear_start_state ();
737 void display_start_state ()
const;
739 bool maybe_unput_comma_before_unary_op (
int tok);
741 int handle_op (
int tok,
bool bos =
false,
bool compat =
true);
743 int finish_command_arg ();
745 int handle_token (
int tok,
token *tok_val =
nullptr);
747 int count_token (
int tok);
749 int count_token_internal (
int tok);
751 int show_token (
int tok);
764 :
base_lexer (interp), m_reader (interp), m_initial_input (true)
768 :
base_lexer (interp), m_reader (interp, file), m_initial_input (true)
772 :
base_lexer (interp), m_reader (interp, file, encoding),
773 m_initial_input (true)
777 :
base_lexer (interp), m_reader (interp, eval_string),
778 m_initial_input (true)
781 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (
lexer)
787 m_initial_input =
true;
794 return m_reader.input_source ();
799 return m_reader.input_from_terminal ();
804 return m_reader.input_from_file ();
809 return m_reader.input_from_eval_string ();
812 int fill_flex_buffer (
char *buf,
unsigned int max_size);
824 template <>
int base_lexer::handle_number<2> ();
825 template <>
int base_lexer::handle_number<10> ();
826 template <>
int base_lexer::handle_number<16> ();
836 append_input (
"",
false);
842 append_input (input,
false);
848 append_input (
"", eof);
854 append_input (input, eof);
857 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (
push_lexer)
863 void append_input (
const std::string& input,
bool eof);
867 int fill_flex_buffer (
char *buf,
unsigned int max_size);
870 OCTAVE_END_NAMESPACE(
octave)
base_lexer(interpreter &interp)
bool at_end_of_buffer() const
std::stack< int > start_state_stack
virtual bool is_push_lexer() const
comment_buffer m_comment_buf
bool at_end_of_file() const
virtual int fill_flex_buffer(char *buf, unsigned int max_size)=0
virtual bool input_from_terminal() const
comment_list * get_comment()
virtual bool input_from_file() const
virtual std::string input_source() const
virtual bool input_from_eval_string() const
bool input_from_eval_string() const
lexer(FILE *file, interpreter &interp)
bool input_from_file() const
std::string input_source() const
lexer(interpreter &interp)
lexer(FILE *file, interpreter &interp, const std::string &encoding)
lexer(const std::string &eval_string, interpreter &interp)
bool input_from_terminal() const
bool is_bracket_or_brace()
bbp_nesting_level(const bbp_nesting_level &nl)
~bbp_nesting_level()=default
symbol_table_context(interpreter &interp)
void push(const symbol_scope &scope)
token * at(std::size_t n)
const token * back() const
const token * front() const
const token * at(std::size_t n) const
bool m_looking_at_parameter_list
bool m_reading_classdef_file
bool m_looking_at_anon_fcn_args
std::string m_package_name
bool m_arguments_is_keyword
std::string m_current_input_line
bool m_allow_command_syntax
bool m_parsing_classdef_set_method
bool m_parsing_anon_fcn_body
std::string m_comment_text
std::stack< bool > m_parsed_function_name
bool m_at_beginning_of_statement
int m_block_comment_nesting_level
int m_command_arg_paren_count
std::string m_fcn_file_full_name
bool m_looking_at_return_list
bool m_parsing_classdef_get_method
std::string m_string_text
std::list< bool > m_looking_at_object_index
bool m_parsing_classdef_decl
bool m_looking_at_matrix_or_assign_lhs
bool m_parsing_classdef_superclass
lexical_feedback(interpreter &interp)
bool m_looking_for_object_index
interpreter & m_interpreter
bbp_nesting_level m_nesting_level
bool m_reading_script_file
bool m_classdef_element_names_are_keywords
std::size_t m_token_count
std::string m_function_text
bool m_comment_uses_hash_char
std::string m_fcn_file_name
bool m_looking_at_decl_list
symbol_table_context m_symtab_context
bool m_quote_is_transpose
bool m_parsing_class_method
bool m_buffer_function_text
bool m_maybe_classdef_get_set_method
bool m_looking_at_indirect_ref
int m_looking_at_function_handle
push_lexer(const std::string &input, bool eof, interpreter &interp)
push_lexer(interpreter &interp)
push_lexer(bool eof, interpreter &interp)
bool is_push_lexer() const
std::string input_source() const
push_lexer(const std::string &input, interpreter &interp)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
bool iskeyword(const std::string &s)