26#if ! defined (octave_token_h)
27#define octave_token_h 1
29#include "octave-config.h"
79 : m_type_tag (invalid_token)
83 : m_beg_pos (beg_pos), m_end_pos (end_pos), m_tok_id (id), m_leading_comments (lst)
87 : m_beg_pos (beg_pos), m_end_pos (end_pos), m_tok_id (id), m_type_tag (is_kw ? keyword_token : generic_token), m_leading_comments (lst)
91 : m_beg_pos (beg_pos), m_end_pos (end_pos), m_tok_id (id), m_type_tag (string_token), m_tok_info (s), m_leading_comments (lst)
95 : m_beg_pos (beg_pos), m_end_pos (end_pos), m_tok_id (id), m_type_tag (string_token), m_tok_info (s), m_leading_comments (lst)
99 : m_beg_pos (beg_pos), m_end_pos (end_pos), m_tok_id (id), m_type_tag (numeric_token), m_tok_info (val), m_orig_text (s), m_leading_comments (lst)
103 : m_beg_pos (beg_pos), m_end_pos (end_pos), m_tok_id (id), m_type_tag (ettype_token), m_tok_info (t), m_leading_comments (lst)
107 : m_beg_pos (beg_pos), m_end_pos (end_pos), m_tok_id (id), m_type_tag (scls_name_token), m_tok_info (meth, cls), m_leading_comments (lst)
110 OCTAVE_DEFAULT_COPY_MOVE_DELETE (
token)
112 void mark_may_be_command () { m_maybe_cmd =
true; }
118 operator bool ()
const {
return m_type_tag != invalid_token; }
122 bool token_is (
int id)
const {
return m_tok_id == id; }
125 return tok ? token_is (tok->
token_id ()) :
false;
141 int line ()
const {
return m_beg_pos.line (); }
142 int column ()
const {
return m_beg_pos.column (); }
146 return m_type_tag == keyword_token || m_type_tag == ettype_token;
149 bool isstring ()
const {
return m_type_tag == string_token; }
151 std::string
text ()
const {
return m_tok_info.text (); }
159 std::string
text_rep ()
const {
return m_orig_text; }
163 bool m_maybe_cmd {
false};
172 token_type m_type_tag {generic_token};
174 class superclass_info
178 superclass_info (
const std::string& meth,
const std::string& cls)
179 : m_method_name (meth), m_class_name (cls)
182 OCTAVE_DEFAULT_COPY_MOVE_DELETE (superclass_info)
184 std::string method_name ()
const {
return m_method_name; }
186 std::string class_name ()
const {
return m_class_name; }
194 std::string m_method_name;
198 std::string m_class_name;
205 tok_info (
const char *s) : m_value (std::string (s)) { }
207 tok_info (
const std::string& str) : m_value (str) { }
211 tok_info (end_tok_type et) : m_value (et) { }
213 tok_info (
const std::string& meth,
const std::string& cls) : m_value (superclass_info (meth, cls)) { }
215 OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE_DELETE (tok_info)
217 std::string text ()
const
219 panic_unless (std::holds_alternative<std::string> (m_value));
220 return std::get<std::string> (m_value);
225 panic_unless (std::holds_alternative<octave_value> (m_value));
226 return std::get<octave_value> (m_value);
231 panic_unless (std::holds_alternative<end_tok_type> (m_value));
232 return std::get<end_tok_type> (m_value);
236 superclass_method_name ()
const
238 panic_unless (std::holds_alternative<superclass_info> (m_value));
239 return std::get<superclass_info> (m_value).method_name ();
243 superclass_class_name ()
const
245 panic_unless (std::holds_alternative<superclass_info> (m_value));
246 return std::get<superclass_info> (m_value).class_name ();
251 std::variant<std::string, octave_value, end_tok_type, superclass_info> m_value;
256 std::string m_orig_text;
266OCTAVE_END_NAMESPACE(octave)
void trailing_comments(const comment_list &lst)
std::string text_rep() const
std::string superclass_class_name() const
token(int id, bool is_kw, const filepos &beg_pos, const filepos &end_pos, const comment_list &lst=comment_list())
comment_list leading_comments() const
void mark_trailing_space()
void leading_comments(const comment_list &lst)
token(int id, const octave_value &val, const std::string &s, const filepos &beg_pos, const filepos &end_pos, const comment_list &lst=comment_list())
bool token_is(const token *tok) const
token(int id, const std::string &s, const filepos &beg_pos, const filepos &end_pos, const comment_list &lst=comment_list())
void end_pos(const filepos &pos)
std::string superclass_method_name() const
end_tok_type ettype() const
comment_list trailing_comments() const
token(int id, end_tok_type t, const filepos &beg_pos, const filepos &end_pos, const comment_list &lst=comment_list())
void beg_pos(const filepos &pos)
token(int id, const std::string &meth, const std::string &cls, const filepos &beg_pos, const filepos &end_pos, const comment_list &lst=comment_list())
token(int id, const char *s, const filepos &beg_pos, const filepos &end_pos, const comment_list &lst=comment_list())
token(int id, const filepos &beg_pos, const filepos &end_pos, const comment_list &lst=comment_list())
bool token_is(int id) const
bool may_be_command() const
octave_value number() const
bool space_follows_token() const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define panic_unless(cond)