Function rhai::parse_string_literal
source · [−]pub fn parse_string_literal(
stream: &mut impl InputStream,
state: &mut TokenizeState,
pos: &mut Position,
termination_char: char,
verbatim: bool,
allow_line_continuation: bool,
allow_interpolation: bool
) -> Result<(SmartString<LazyCompact>, bool, Position), (LexError, Position)>
Expand description
(internals) Parse a string literal ended by a specified termination character.
Exported under the internals
feature only.
Returns the parsed string and a boolean indicating whether the string is
terminated by an interpolation ${
.
Returns
Type | Return Value | state.is_within_text_terminated_by |
---|---|---|
"hello" | StringConstant("hello") | None |
"hello {LF} or {EOF} | LexError | None |
"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.