Parses a Python expression from a string annotation. # Example Parsing a string annotation: ``` use ruff_python_parser::parse_string_annotation; use ruff_python_ast::{StringLiteral, StringLiteralFlags, AtomicNodeIndex}; use ruff_text_size::{TextRange, TextSize}; let string = StringLiteral { value: "'''\n int | str'''".to_string().into_boxed_str(), flags: StringLiteralFlags::empty(), range: Tex
(
source: &str,
string: &StringLiteral,
)
| 217 | /// assert!(!parsed.is_ok()); |
| 218 | /// ``` |
| 219 | pub fn parse_string_annotation( |
| 220 | source: &str, |
| 221 | string: &StringLiteral, |
| 222 | ) -> Result<Parsed<ModExpression>, ParseError> { |
| 223 | let range = string |
| 224 | .range() |
| 225 | .add_start(string.flags.opener_len()) |
| 226 | .sub_end(string.flags.closer_len()); |
| 227 | let source = &source[..range.end().to_usize()]; |
| 228 | if string.flags.is_triple_quoted() { |
| 229 | parse_parenthesized_expression_range(source, range) |
| 230 | } else { |
| 231 | parse_expression_range(source, range) |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | /// Parse the given Python source code using the specified [`ParseOptions`]. |
| 236 | /// |
no test coverage detected