GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
token.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1993-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_token_h)
27#define octave_token_h 1
28
29#include "octave-config.h"
30
31#include <string>
32
33#include "filepos.h"
34#include "ov.h"
35
36namespace octave
37{
38 class token
39 {
40 public:
41
43 {
50 };
51
53 {
70 };
71
72 token (int tv, const filepos& beg_pos, const filepos& end_pos);
73
74 token (int tv, bool is_keyword, const filepos& beg_pos
75 , const filepos& end_pos);
76
77 token (int tv, const char *s, const filepos& beg_pos,
78 const filepos& end_pos);
79
80 token (int tv, const std::string& s, const filepos& beg_pos,
81 const filepos& end_pos);
82
83 token (int tv, const octave_value& val, const std::string& s,
84 const filepos& beg_pos, const filepos& end_pos);
85
86 token (int tv, end_tok_type t, const filepos& beg_pos,
87 const filepos& end_pos);
88
89 token (int tv, const std::string& mth, const std::string& cls,
90 const filepos& beg_pos, const filepos& end_pos);
91
92 // No copying!
93
94 token (const token&) = delete;
95
96 token& operator = (const token&) = delete;
97
98 ~token (void);
99
100 void mark_may_be_command (void) { m_maybe_cmd = true; }
101 bool may_be_command (void) const { return m_maybe_cmd; }
102
103 void mark_trailing_space (void) { m_tspc = true; }
104 bool space_follows_token (void) const { return m_tspc; }
105
106 int token_value (void) const { return m_tok_val; }
107 bool token_value_is (int tv) const { return tv == m_tok_val; }
108
109 filepos beg_pos (void) const { return m_beg_pos; }
110 filepos end_pos (void) const { return m_end_pos; }
111
112 void beg_pos (const filepos& pos) { m_beg_pos = pos; }
113 void end_pos (const filepos& pos) { m_end_pos = pos; }
114
115 // These will probably be removed.
116 int line (void) const { return m_beg_pos.line (); }
117 int column (void) const { return m_beg_pos.column (); }
118
119 bool iskeyword (void) const
120 {
122 }
123
124 bool isstring (void) const { return m_type_tag == string_token; }
125
126 std::string text (void) const;
127 octave_value number (void) const;
128 token_type ttype (void) const;
129 end_tok_type ettype (void) const;
130
131 std::string superclass_method_name (void) const;
132 std::string superclass_class_name (void) const;
133
134 std::string text_rep (void) const;
135
136 private:
137
139
140 bool m_tspc;
141
144
146
148
150 {
151 tok_info (void) { }
152
153 tok_info (const char *s) : m_str (new std::string (s)) { }
154
155 tok_info (const std::string& str) : m_str (new std::string (str)) { }
156
157 tok_info (const octave_value& num) : m_num (new octave_value (num)) { }
158
159 tok_info (end_tok_type et) : m_et (et) { }
160
161 tok_info (const std::string& meth, const std::string& cls)
162 : m_superclass_info (new superclass_info (meth, cls))
163 { }
164
165 tok_info (const tok_info&) = delete;
166
167 tok_info& operator = (const tok_info&) = delete;
168
169 ~tok_info (void) { }
170
171 std::string *m_str;
172
174
176
178 {
179 public:
180 superclass_info (const std::string& meth, const std::string& cls)
181 : m_method_name (meth), m_class_name (cls)
182 { }
183
184 superclass_info (void) = delete;
185
187
189
190 ~superclass_info (void) = default;
191
192 //--------
193
194 // The name of the method to call. This is the text before the
195 // "@" and may be of the form "object.method".
196 std::string m_method_name;
197
198 // The name of the superclass. This is the text after the "@"
199 // and may be of the form "object.method".
200 std::string m_class_name;
201 };
202
204 };
205
207
208 std::string m_orig_text;
209 };
210}
211
212#endif
void line(int l)
Definition: filepos.h:49
void column(int c)
Definition: filepos.h:50
std::string superclass_class_name(void) const
Definition: token.cc:130
end_tok_type ettype(void) const
Definition: token.cc:116
token_type ttype(void) const
Definition: token.cc:110
bool token_value_is(int tv) const
Definition: token.h:107
void beg_pos(const filepos &pos)
Definition: token.h:112
filepos m_beg_pos
Definition: token.h:142
tok_info m_tok_info
Definition: token.h:206
int line(void) const
Definition: token.h:116
token(int tv, const filepos &beg_pos, const filepos &end_pos)
Definition: token.cc:36
void mark_trailing_space(void)
Definition: token.h:103
std::string superclass_method_name(void) const
Definition: token.cc:123
token(const token &)=delete
octave_value number(void) const
Definition: token.cc:103
bool space_follows_token(void) const
Definition: token.h:104
token_type m_type_tag
Definition: token.h:147
@ try_catch_end
Definition: token.h:66
@ unwind_protect_end
Definition: token.h:67
@ while_end
Definition: token.h:69
@ parfor_end
Definition: token.h:63
@ switch_end
Definition: token.h:65
@ classdef_end
Definition: token.h:56
@ events_end
Definition: token.h:58
@ methods_end
Definition: token.h:62
@ function_end
Definition: token.h:60
@ arguments_end
Definition: token.h:55
@ spmd_end
Definition: token.h:68
@ simple_end
Definition: token.h:54
@ properties_end
Definition: token.h:64
@ enumeration_end
Definition: token.h:57
std::string text(void) const
Definition: token.cc:96
bool iskeyword(void) const
Definition: token.h:119
void mark_may_be_command(void)
Definition: token.h:100
bool may_be_command(void) const
Definition: token.h:101
bool m_maybe_cmd
Definition: token.h:138
int m_tok_val
Definition: token.h:145
~token(void)
Definition: token.cc:85
@ ettype_token
Definition: token.h:48
@ numeric_token
Definition: token.h:47
@ string_token
Definition: token.h:46
@ keyword_token
Definition: token.h:45
@ generic_token
Definition: token.h:44
@ scls_name_token
Definition: token.h:49
int column(void) const
Definition: token.h:117
bool isstring(void) const
Definition: token.h:124
void end_pos(const filepos &pos)
Definition: token.h:113
std::string m_orig_text
Definition: token.h:208
int token_value(void) const
Definition: token.h:106
filepos beg_pos(void) const
Definition: token.h:109
bool m_tspc
Definition: token.h:140
token & operator=(const token &)=delete
filepos m_end_pos
Definition: token.h:143
filepos end_pos(void) const
Definition: token.h:110
std::string text_rep(void) const
Definition: token.cc:137
STL namespace.
superclass_info(const superclass_info &)=delete
superclass_info & operator=(const superclass_info &)=delete
superclass_info(const std::string &meth, const std::string &cls)
Definition: token.h:180
std::string * m_str
Definition: token.h:171
tok_info(const std::string &meth, const std::string &cls)
Definition: token.h:161
tok_info(end_tok_type et)
Definition: token.h:159
tok_info & operator=(const tok_info &)=delete
end_tok_type m_et
Definition: token.h:175
tok_info(const std::string &str)
Definition: token.h:155
tok_info(const char *s)
Definition: token.h:153
octave_value * m_num
Definition: token.h:173
tok_info(const octave_value &num)
Definition: token.h:157
tok_info(const tok_info &)=delete
superclass_info * m_superclass_info
Definition: token.h:203