@@ -44,9 +44,15 @@ class Context {
4444 using executed_func_type = std::function<void (Context*)>;
4545 void with (const executed_func_type& func) { func (this ); }
4646 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+ }
4752
4853 private:
4954 token::TokenLists token_lists_;
55+ token::Token start_token_;
5056};
5157
5258class ContextTrait {
@@ -115,26 +121,19 @@ class Tree {
115121};
116122
117123struct 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*>;
121124 explicit ParseFunctionOutputs () = default;
122125
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_;
138137
139138 ParseFunctionOutputs (const ParseFunctionOutputs& other) {
140139 SET (this , other);
@@ -157,38 +156,22 @@ struct ParseFunctionOutputs {
157156#undef SET_MOVE
158157#undef SET
159158
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-
168159 void concat (ParseFunctionOutputs&& other, bool opt = true ) {
169160 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- }
174161 this ->work_ = other.work_ ;
175162 }
176163 if (other.work_ ) {
177164 this ->last_token_ = other.last_token_ ;
178165 this ->cur_token_ = other.cur_token_ ;
179166 this ->work_ = other.work_ ;
180- for (auto & a : other.token_list_infos_ ) {
181- this ->token_list_infos_ .append (a);
182- }
167+ len_ += other.len_ ;
183168 }
184169 }
185170
186171 bool work_{false };
187172 token::Token last_token_;
188173 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 };
192175};
193176
194177struct ParseFunctionInputs {
@@ -361,8 +344,7 @@ class ParseFunction : public ContextTrait {
361344
362345 if (output.cur_token_ .kind () != token_kind) {
363346 if (!func->opt ()) {
364- output.diag_record (
365- diag::record (output.cur_token_ , diag_kind, {output.last_token_ }));
347+ // todo(@mxlol233): add diag.
366348 }
367349 output.work_ = false ;
368350 return output;
@@ -372,10 +354,7 @@ class ParseFunction : public ContextTrait {
372354 output.last_token_ = output.cur_token_ ;
373355 output.work_ = true ;
374356 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_ ;
379358 }
380359
381360 return output;
0 commit comments