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

Method parse_strings

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

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