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

Method parse_strings

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

1288 ///
1289 /// See: <https://docs.python.org/3/reference/grammar.html> (Search "strings:")
1290 pub(super) fn parse_strings(&mut self) -> Expr {
1291 const STRING_START_SET: TokenSet = TokenSet::new([
1292 TokenKind::String,
1293 TokenKind::FStringStart,
1294 TokenKind::TStringStart,
1295 ]);
1296
1297 let start = self.node_start();
1298 let first = self.parse_string();
1299
1300 if !self.at_ts(STRING_START_SET) {
1301 return first.into();
1302 }
1303
1304 let mut strings = Vec::with_capacity(2);
1305 strings.push(first);
1306
1307 let mut progress = ParserProgress::default();
1308
1309 while self.at_ts(STRING_START_SET) {
1310 progress.assert_progressing(self);
1311 strings.push(self.parse_string());
1312 }
1313
1314 let range = self.node_range(start);
1315 self.handle_implicitly_concatenated_strings(strings, range)
1316 }
1317
1318 /// Parses a single string, byte literal, f-string, or t-string.
1319 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