@@ -44,9 +44,15 @@ class Context {
44
44
using executed_func_type = std::function<void (Context*)>;
45
45
void with (const executed_func_type& func) { func (this ); }
46
46
token::TokenLists& token_lists () { return token_lists_; }
47
+ const token::Token& start_token () const { return start_token_; }
48
+ void start_token (const token::Token& token) { start_token_ = token; }
49
+ size_t len_from_start (const token::Token& cur_token) {
50
+ return token_lists_.len (start_token_, cur_token);
51
+ }
47
52
48
53
private:
49
54
token::TokenLists token_lists_;
55
+ token::Token start_token_;
50
56
};
51
57
52
58
class ContextTrait {
@@ -115,26 +121,19 @@ class Tree {
115
121
};
116
122
117
123
struct ParseFunctionOutputs {
118
- using diag_input_type = basic::Vector<4 , diag::DiagInputs>;
119
- using token_list_infos_type =
120
- basic::Vector<16 , const token::TokenLists::ele_type*>;
121
124
explicit ParseFunctionOutputs () = default;
122
125
123
- #define SET_MOVE (A, B ) \
124
- (A)->work_ = (B).work_; \
125
- (A)->last_token_ = (B).last_token_; \
126
- (A)->cur_token_ = (B).cur_token_; \
127
- (A)->diag_inputs_ = std::move((B).diag_inputs_); \
128
- (A)->node_ = std::move((B).node_); \
129
- (A)->token_list_infos_ = std::move((B).token_list_infos_);
130
-
131
- #define SET (A, B ) \
132
- (A)->work_ = (B).work_; \
133
- (A)->last_token_ = (B).last_token_; \
134
- (A)->cur_token_ = (B).cur_token_; \
135
- (A)->diag_inputs_ = (B).diag_inputs_; \
136
- (A)->node_ = (B).node_; \
137
- (A)->token_list_infos_ = (B).token_list_infos_;
126
+ #define SET_MOVE (A, B ) \
127
+ (A)->work_ = (B).work_; \
128
+ (A)->last_token_ = (B).last_token_; \
129
+ (A)->cur_token_ = (B).cur_token_; \
130
+ (A)->len_ = (B).len_;
131
+
132
+ #define SET (A, B ) \
133
+ (A)->work_ = (B).work_; \
134
+ (A)->last_token_ = (B).last_token_; \
135
+ (A)->cur_token_ = (B).cur_token_; \
136
+ (A)->len_ = (B).len_;
138
137
139
138
ParseFunctionOutputs (const ParseFunctionOutputs& other) {
140
139
SET (this , other);
@@ -157,38 +156,22 @@ struct ParseFunctionOutputs {
157
156
#undef SET_MOVE
158
157
#undef SET
159
158
160
- [[nodiscard]] size_t len () const {
161
- return token_list_infos_.size ();
162
- }
163
-
164
- void diag_record (diag::DiagInputs&& a) {
165
- diag_inputs_.append (std::move (a));
166
- }
167
-
168
159
void concat (ParseFunctionOutputs&& other, bool opt = true ) {
169
160
if (!opt) {
170
- for (auto & a : other.diag_inputs_ ) {
171
- typename decltype (diag_inputs_)::ele_type b (std::move (a));
172
- this ->diag_inputs_ .append (std::move (b));
173
- }
174
161
this ->work_ = other.work_ ;
175
162
}
176
163
if (other.work_ ) {
177
164
this ->last_token_ = other.last_token_ ;
178
165
this ->cur_token_ = other.cur_token_ ;
179
166
this ->work_ = other.work_ ;
180
- for (auto & a : other.token_list_infos_ ) {
181
- this ->token_list_infos_ .append (a);
182
- }
167
+ len_ += other.len_ ;
183
168
}
184
169
}
185
170
186
171
bool work_{false };
187
172
token::Token last_token_;
188
173
token::Token cur_token_;
189
- diag_input_type diag_inputs_;
190
- token_list_infos_type token_list_infos_;
191
- Tree::Node node_;
174
+ size_t len_{0 };
192
175
};
193
176
194
177
struct ParseFunctionInputs {
@@ -361,8 +344,7 @@ class ParseFunction : public ContextTrait {
361
344
362
345
if (output.cur_token_ .kind () != token_kind) {
363
346
if (!func->opt ()) {
364
- output.diag_record (
365
- diag::record (output.cur_token_ , diag_kind, {output.last_token_ }));
347
+ // todo(@mxlol233): add diag.
366
348
}
367
349
output.work_ = false ;
368
350
return output;
@@ -372,10 +354,7 @@ class ParseFunction : public ContextTrait {
372
354
output.last_token_ = output.cur_token_ ;
373
355
output.work_ = true ;
374
356
output.cur_token_ = next_tok;
375
- if (next_tok.kind () != token::details::TokenKind::unknown) {
376
- output.token_list_infos_ .append (
377
- &(func->context ()->token_lists ().at (next_tok)));
378
- }
357
+ ++output.len_ ;
379
358
}
380
359
381
360
return output;
0 commit comments