Function quad_compat_rhai::parse_string_literal[][src]

pub fn parse_string_literal(
    stream: &mut impl InputStream,
    state: &mut TokenizeState,
    pos: &mut Position,
    termination_char: char,
    continuation: bool,
    verbatim: bool,
    allow_interpolation: bool
) -> Result<(Box<str>, bool), (LexError, Position)>
Expand description

(internals) Parse a string literal ended by termination_char. Exported under the internals feature only.

Returns the parsed string and a boolean indicating whether the string is terminated by an interpolation ${.

Returns

TypeReturn Valuestate.is_within_text_terminated_by
"hello"StringConstant("hello")None
"hello{LF} or {EOF}LexErrorNone
"hello\{EOF} or {LF}{EOF}StringConstant("hello")Some('"')
`hello{EOF}StringConstant("hello")Some('`')
`hello{LF}{EOF}StringConstant("hello\n")Some('`')
`hello ${InterpolatedString("hello ")
next token is {
None
} hello`StringConstant(" hello")None
} hello{EOF}StringConstant(" hello")Some('`')

This function does not throw a LexError for the following conditions:

  • Unterminated literal string at {EOF}

  • Unterminated normal string with continuation at {EOF}

This is to facilitate using this function to parse a script line-by-line, where the end of the line (i.e. {EOF}) is not necessarily the end of the script.

Any time a StringConstant is returned with state.is_within_text_terminated_by set to Some(_) is one of the above conditions.