Module string

Module string 

Source
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:

EscapeDescription
\aBell
\bBackspace
\fForm feed
\nNewline
\rCarriage return
\tTab
\vVertical tab
\\Backslash
\"Double quote
\'Single quote
\xNNHex (2 digits)
\NNNOctal (3 digits)
\uNNNNUnicode (4 hex)
\UNNNNNNNNUnicode (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 escapes In 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.