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

Method parse_strings

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

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