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

Method parse_strings

crates/ruff_python_parser/src/parser/expression.rs:1366–1392  ·  view source on GitHub ↗

Parses all kinds of strings and implicitly concatenated strings. # Panics If the parser isn't positioned at a `String`, `FStringStart`, or `TStringStart` token. See: (Search "strings:")

(&mut self)

Source from the content-addressed store, hash-verified

1364 ///
1365 /// See: <https://docs.python.org/3/reference/grammar.html> (Search "strings:")
1366 pub(super) fn parse_strings(&mut self) -> Expr {
1367 const STRING_START_SET: TokenSet = TokenSet::new([
1368 TokenKind::String,
1369 TokenKind::FStringStart,
1370 TokenKind::TStringStart,
1371 ]);
1372
1373 let start = self.node_start();
1374 let first = self.parse_string();
1375
1376 if !self.at_ts(STRING_START_SET) {
1377 return first.into();
1378 }
1379
1380 let mut strings = Vec::with_capacity(2);
1381 strings.push(first);
1382
1383 let mut progress = ParserProgress::default();
1384
1385 while self.at_ts(STRING_START_SET) {
1386 progress.assert_progressing(self);
1387 strings.push(self.parse_string());
1388 }
1389
1390 let range = self.node_range(start);
1391 self.handle_implicitly_concatenated_strings(strings, range)
1392 }
1393
1394 /// Parses a single string, byte literal, f-string, or t-string.
1395 fn parse_string(&mut self) -> StringType {

Callers 2

parse_atomMethod · 0.80

Calls 8

node_startMethod · 0.80
at_tsMethod · 0.80
assert_progressingMethod · 0.80
node_rangeMethod · 0.80
defaultFunction · 0.50
parse_stringMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected