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

Method parse_strings

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

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

Callers 2

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