MCPcopy Create free account
hub / github.com/Glyphack/enderpy / advance

Method advance

parser/src/parser/parser.rs:174–210  ·  view source on GitHub ↗

Move to the next token count_in_offset: if true, the offset will be increased by the length of the current token so prev_token_end is adjusted

(&mut self, count_in_offset: bool)

Source from the content-addressed store, hash-verified

172 /// Move to the next token
173 /// count_in_offset: if true, the offset will be increased by the length of the current token so prev_token_end is adjusted
174 fn advance(&mut self, count_in_offset: bool) {
175 let token = self.lexer.next_token();
176 if matches!(token.kind, Kind::Identifier | Kind::Match | Kind::Type) {
177 self.identifiers_start_offset.push((
178 token.start,
179 token.end,
180 token.to_string(self.source),
181 ));
182 }
183
184 match token.kind {
185 Kind::LeftParen | Kind::LeftBrace | Kind::LeftBracket => {
186 self.nested_expression_list += 1
187 }
188 Kind::RightParen | Kind::RightBrace | Kind::RightBracket => {
189 self.nested_expression_list -= 1
190 }
191 _ => {}
192 }
193
194 if count_in_offset {
195 self.prev_token_end = self.cur_token.end;
196 }
197 if !matches!(
198 self.cur_token.kind,
199 Kind::WhiteSpace | Kind::NewLine | Kind::Dedent
200 ) {
201 self.prev_nonwhitespace_token_end = self.prev_token_end;
202 }
203 self.cur_token = token;
204 if matches!(self.cur_kind(), Kind::Comment | Kind::NL) {
205 self.advance(false);
206 }
207 if self.nested_expression_list > 0 {
208 self.consume_whitespace_and_newline();
209 }
210 }
211
212 /// Expect a `Kind` or return error
213 pub fn expect(&mut self, kind: Kind) -> Result<(), ParsingError> {

Callers 4

bumpMethod · 0.80
bump_anyMethod · 0.80
eatMethod · 0.80

Calls 3

next_tokenMethod · 0.80
to_stringMethod · 0.80

Tested by

no test coverage detected