Skip to main content

parse_quote_operator_content

Function parse_quote_operator_content 

Source
pub fn parse_quote_operator_content<'a>(
    s: &'a str,
    operator: &str,
) -> Option<&'a str>
Expand description

Extract the inner content of a Perl quote-like operator expression.

This is the canonical shared implementation for all qw/q/qq delimiter parsing in the workspace. Every consumer crate (perl-semantic-analyzer, perl-workspace, perl-module, and this crate’s own HIR model) delegates here.

§Behaviour

Strips operator from the start of s, trims any optional whitespace between the operator and its opening delimiter (Perl allows qw (a b)), reads the opening delimiter, maps it to its paired closing delimiter ((), {}, [], <>; all others self-close), rejects an alphanumeric or underscore character in delimiter position (i.e. qwfooNone), verifies the string ends with the closing delimiter, and returns the interior slice.

§Examples

// Basic qw
assert_eq!(parse_quote_operator_content("qw(foo bar)", "qw"), Some("foo bar"));
// Space before delimiter
assert_eq!(parse_quote_operator_content("qw (foo bar)", "qw"), Some("foo bar"));
// Self-closing delimiter
assert_eq!(parse_quote_operator_content("qw/foo bar/", "qw"), Some("foo bar"));
// Bareword — rejected
assert_eq!(parse_quote_operator_content("qwfoo", "qw"), None);