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

Method parse_strings

crates/ruff_python_parser/src/parser/expression.rs:1369–1395  ·  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

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