MCPcopy Create free account
hub / github.com/astral-sh/ruff / consume_end

Method consume_end

crates/ruff_python_parser/src/lexer.rs:1181–1218  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

1179 }
1180
1181 fn consume_end(&mut self) -> TokenKind {
1182 // We reached end of file.
1183
1184 // First, finish any unterminated interpolated-strings.
1185 while let Some(interpolated_string) = self.interpolated_strings.pop() {
1186 self.nesting = interpolated_string.nesting();
1187 self.push_error(LexicalError::new(
1188 LexicalErrorType::from_interpolated_string_error(
1189 InterpolatedStringErrorType::UnterminatedString,
1190 interpolated_string.kind(),
1191 ),
1192 self.token_range(),
1193 ));
1194 }
1195
1196 // Second, finish all nestings.
1197 // For Mode::ParenthesizedExpression we start with nesting level 1.
1198 // So we check if we end with that level.
1199 let init_nesting = u32::from(self.mode == Mode::ParenthesizedExpression);
1200
1201 if self.nesting > init_nesting {
1202 // Reset the nesting to avoid going into infinite loop.
1203 self.nesting = 0;
1204 return self.push_error(LexicalError::new(LexicalErrorType::Eof, self.token_range()));
1205 }
1206
1207 // Next, insert a trailing newline, if required.
1208 if !self.state.is_new_logical_line() {
1209 self.state = State::AfterNewline;
1210 TokenKind::Newline
1211 }
1212 // Next, flush the indentation stack to zero.
1213 else if self.indentations.dedent().is_some() {
1214 TokenKind::Dedent
1215 } else {
1216 TokenKind::EndOfFile
1217 }
1218 }
1219
1220 /// Re-lex the [`NonLogicalNewline`] token at the given position in the context of a logical
1221 /// line.

Callers 1

lex_tokenMethod · 0.80

Calls 7

push_errorMethod · 0.80
is_new_logical_lineMethod · 0.80
dedentMethod · 0.80
popMethod · 0.45
nestingMethod · 0.45
kindMethod · 0.45
token_rangeMethod · 0.45

Tested by

no test coverage detected