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 () { }
69 bool empty (
void)
const {
return m_frame_stack.empty (); }
71 std::size_t
size (
void)
const {
return m_frame_stack.size (); }
77 m_frame_stack.push_front (scope);
109 : m_context (nl.m_context)
125 void bracket (
void) { m_context.push (BRACKET); }
129 return ! m_context.empty () && m_context.top () == BRACKET;
132 void brace (
void) { m_context.push (BRACE); }
136 return ! m_context.empty () && m_context.top () == BRACE;
139 void paren (
void) { m_context.push (PAREN); }
143 return ! m_context.empty () && m_context.top () == PAREN;
150 return ! m_context.empty () && m_context.top () == ANON_FCN_BODY;
155 return (! m_context.empty ()
156 && (m_context.top () == BRACKET || m_context.top () == BRACE));
159 bool none (
void) {
return m_context.empty (); }
163 if (! m_context.empty ())
169 while (! m_context.empty ())
206 m_buffer.push_front (tok);
213 delete m_buffer.back ();
214 m_buffer.pop_back ();
221 return empty () ? nullptr : m_buffer.at (
n);
226 return empty () ? nullptr : m_buffer.at (
n);
232 return empty () ? nullptr : m_buffer.front ();
237 return empty () ? nullptr : m_buffer.front ();
242 return empty () ? nullptr : m_buffer.back ();
247 return empty () ? nullptr : m_buffer.back ();
251 std::size_t
size (
void)
const {
return m_buffer.size (); }
253 bool empty (
void)
const {
return m_buffer.empty (); }
267 : m_interpreter (interp),
268 m_end_of_input (false),
269 m_allow_command_syntax (true),
270 m_at_beginning_of_statement (true),
271 m_looking_at_anon_fcn_args (false),
272 m_looking_at_return_list (false),
273 m_looking_at_parameter_list (false),
274 m_looking_at_decl_list (false),
275 m_looking_at_matrix_or_assign_lhs (false),
276 m_looking_for_object_index (false),
277 m_looking_at_indirect_ref (false),
278 m_arguments_is_keyword (false),
279 m_classdef_element_names_are_keywords (false),
280 m_parsing_anon_fcn_body (false),
281 m_parsing_class_method (false),
282 m_parsing_classdef (false),
283 m_parsing_classdef_decl (false),
284 m_parsing_classdef_superclass (false),
285 m_maybe_classdef_get_set_method (false),
286 m_parsing_classdef_get_method (false),
287 m_parsing_classdef_set_method (false),
288 m_quote_is_transpose (false),
289 m_force_script (false),
290 m_reading_fcn_file (false),
291 m_reading_script_file (false),
292 m_reading_classdef_file (false),
293 m_buffer_function_text (false),
298 m_looking_at_function_handle (0),
299 m_block_comment_nesting_level (0),
300 m_command_arg_paren_count (0),
306 m_current_input_line (),
311 m_fcn_file_full_name (),
314 m_looking_at_object_index (),
315 m_parsed_function_name (),
316 m_symtab_context (interp),
335 int previous_token_value (
void)
const;
337 bool previous_token_value_is (
int tok_val)
const;
339 void mark_previous_token_trailing_space (
void);
341 bool space_follows_previous_token (
void)
const;
343 bool previous_token_is_binop (
void)
const;
345 bool previous_token_is_keyword (
void)
const;
347 bool previous_token_may_be_command (
void)
const;
349 void mark_as_variable (
const std::string& nm);
350 void mark_as_variables (
const std::list<std::string>& lst);
543 : m_buffer (), m_offset (0), m_chars_left (0), m_eof (false)
546 void fill (
const std::string&
input,
bool eof_arg);
549 int copy_chunk (
char *buf, std::size_t max_size,
bool by_lines =
false);
551 bool empty (
void)
const {
return m_chars_left == 0; }
553 bool at_eof (
void)
const {
return m_eof; }
576 if (! m_comment_list)
579 m_comment_list->append (s, t);
588 m_comment_list =
nullptr;
595 delete m_comment_list;
597 m_comment_list =
nullptr;
624 virtual void reset (
void);
626 void prep_for_file (
void);
628 void begin_string (
int state);
636 int handle_end_of_input (
void);
638 char * flex_yytext (
void);
640 int flex_yyleng (
void);
642 int text_yyinput (
void);
644 void xunput (
char c,
char *buf);
646 void xunput (
char c);
648 void update_token_positions (
int tok_len);
650 bool looking_at_space (
void);
652 bool inside_any_object_index (
void);
654 int make_keyword_token (
const std::string& s);
656 bool fq_identifier_contains_keyword (
const std::string& s);
658 bool whitespace_is_significant (
void);
664 void handle_continuation (
void);
670 int handle_close_bracket (
int bracket_type);
672 bool looks_like_command_arg (
void);
674 int handle_superclass_identifier (
void);
676 int handle_meta_identifier (
void);
678 int handle_fq_identifier (
void);
680 int handle_identifier (
void);
682 void maybe_warn_separator_insert (
char sep);
684 void warn_language_extension (
const std::string& msg);
686 void maybe_warn_language_extension_comment (
char c);
688 void warn_language_extension_continuation (
void);
690 void warn_language_extension_operator (
const std::string& op);
692 void warn_deprecated_syntax (
const std::string& msg);
694 void warn_deprecated_operator (
const std::string& deprecated_op,
695 const std::string& recommended_op,
696 const std::string& version);
698 void push_token (
token *);
700 token * current_token (
void);
702 std::size_t pending_token_count (
void)
const;
704 void display_token (
int tok);
706 void fatal_error (
const char *msg);
708 bool debug_flag (
void)
const;
710 bool display_tokens (
void)
const;
712 void increment_token_count (
void);
714 void lexer_debug (
const char *pattern);
733 bool input_from_tmp_history_file (
void);
735 void push_start_state (
int state);
737 void pop_start_state (
void);
739 void clear_start_state (
void);
743 void display_start_state (
void)
const;
745 bool maybe_unput_comma_before_unary_op (
int tok);
747 int handle_op (
int tok,
bool bos =
false,
bool compat =
true);
749 int finish_command_arg (
void);
751 int handle_token (
int tok,
token *tok_val =
nullptr);
753 int count_token (
int tok);
755 int count_token_internal (
int tok);
757 int show_token (
int tok);
770 :
base_lexer (interp), m_reader (interp), m_initial_input (true)
774 :
base_lexer (interp), m_reader (interp, file), m_initial_input (true)
778 :
base_lexer (interp), m_reader (interp, file, encoding),
779 m_initial_input (true)
783 :
base_lexer (interp), m_reader (interp, eval_string),
784 m_initial_input (true)
795 m_initial_input =
true;
802 return m_reader.input_source ();
807 return m_reader.input_from_terminal ();
812 return m_reader.input_from_file ();
817 return m_reader.input_from_eval_string ();
820 int fill_flex_buffer (
char *buf,
unsigned int max_size);
832 template <>
int base_lexer::handle_number<2> ();
833 template <>
int base_lexer::handle_number<10> ();
834 template <>
int base_lexer::handle_number<16> ();
844 append_input (
"",
false);
850 append_input (
input,
false);
856 append_input (
"", eof);
862 append_input (
input, eof);
873 void append_input (
const std::string&
input,
bool eof);
877 int fill_flex_buffer (
char *buf,
unsigned int max_size);
base_lexer(interpreter &interp)
std::stack< int > start_state_stack
comment_buffer m_comment_buf
base_lexer(const base_lexer &)=delete
virtual int fill_flex_buffer(char *buf, unsigned int max_size)=0
virtual bool input_from_eval_string(void) const
int start_state(void) const
virtual bool is_push_lexer(void) const
bool at_end_of_file(void) const
virtual std::string input_source(void) const
virtual bool input_from_file(void) const
bool at_end_of_buffer(void) const
comment_list * get_comment(void)
virtual bool input_from_terminal(void) const
lexer(const lexer &)=delete
lexer(FILE *file, interpreter &interp)
bool input_from_file(void) const
lexer(interpreter &interp)
bool input_from_eval_string(void) const
lexer(FILE *file, interpreter &interp, const std::string &encoding)
lexer(const std::string &eval_string, interpreter &interp)
std::string input_source(void) const
bool input_from_terminal(void) const
bool is_bracket_or_brace(void)
std::stack< int > m_context
bool is_anon_fcn_body(void)
bbp_nesting_level(const bbp_nesting_level &nl)
~bbp_nesting_level(void)=default
std::size_t size(void) const
symbol_table_context(interpreter &interp)
interpreter & m_interpreter
~symbol_table_context(void)
void push(const symbol_scope &scope)
std::deque< symbol_scope > m_frame_stack
const token * front(void) const
token_cache(const token_cache &)=delete
token * at(std::size_t n)
const token * back(void) const
const token * at(std::size_t n) const
std::deque< token * > m_buffer
std::size_t size(void) 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
lexical_feedback(const lexical_feedback &)=delete
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
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)
std::string input_source(void) const
push_lexer(const push_lexer &)=delete
push_lexer(interpreter &interp)
push_lexer(bool eof, interpreter &interp)
bool is_push_lexer(void) const
push_lexer(const std::string &input, interpreter &interp)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
bool iskeyword(const std::string &s)
static int input(yyscan_t yyscanner)
static uint32_t state[624]