Expand description
String literal parser for PromQL.
PromQL supports three string literal formats:
- Double-quoted:
"hello \"world\"" - Single-quoted:
'hello \'world\'' - Raw/backtick:
`no escapes here`
§Escape Sequences
Double and single-quoted strings support these escape sequences:
| Escape | Description |
|---|---|
\a | Bell |
\b | Backspace |
\f | Form feed |
\n | Newline |
\r | Carriage return |
\t | Tab |
\v | Vertical tab |
\\ | Backslash |
\" | Double quote |
\' | Single quote |
\xNN | Hex (2 digits) |
\NNN | Octal (3 digits) |
\uNNNN | Unicode (4 hex) |
\UNNNNNNNN | Unicode (8 hex) |
Raw strings (backtick) have no escape processing.
§Examples
use rusty_promql_parser::lexer::string::string_literal;
// Double-quoted
let (_, s) = string_literal(r#""hello""#).unwrap();
assert_eq!(s, "hello");
// Single-quoted with escape
let (_, s) = string_literal(r"'line\nbreak'").unwrap();
assert_eq!(s, "line\nbreak");
// Raw string (no escapes)
let (_, s) = string_literal(r"`\n is literal`").unwrap();
assert_eq!(s, r"\n is literal");Functions§
- double_
quoted_ string - Parse a double-quoted string: “hello "world"”
- raw_
string - Parse a raw/backtick string:
no escapesIn raw strings, backslashes are literal - no escape processing. - single_
quoted_ string - Parse a single-quoted string: ‘hello 'world'’
- string_
literal - Parse a PromQL string literal and return the unescaped string value.