Closed schungx closed 3 years ago
Implemented in 02c3bc7 and deployed on https://rhai.rs/playground/dev/. Does it look right?
Not related to the tokenizer but I noticed that the parser panics (panicked at 'internal error: entered unreachable code: expected a string within an interpolated string literal, but gets LexError(UnterminatedString)', D:\dev\toolchain\rust\cargo\git\checkouts\rhai-f99f240b2f7f4b04\10f334d\src\parser.rs:1050:35
) if an interpolated string is not terminated, like this:
`${}
Ah, good catch! Let me check it out!
Fixed it. Forgot to check the case of unterminated string. I'll merge it to master in a bit.
Implemented in 02c3bc7 and deployed on https://rhai.rs/playground/dev/. Does it look right?
It certainly looks FINE!
BTW, there is an updated strings.rhai
version with multi-level interpolated strings.
The fix has landed inhttps://github.com/rhaiscript/rhai/pull/393
It no longer should panic...
Done, updated!
Not sure why, but if a string is not terminated at the end of the line, now it colors all lines below as text. stable
doesn't do that. Seems that the is_within_text
property is not property cleared, but I should have cleared it together with raising the error.
So not sure where the problem is...
Ah, I think I found where the problem is. It is in get_next_token
when given an unterminated string. I'll fix it.
OK, I should have fixed the bug with https://github.com/rhaiscript/rhai/pull/394
Please rebuild again to see if it solves the problem?
Updated again.
Working fine! However, just realized that I have a typo in function_decl2.rhai
.
The line should be:
print(`addme(a, 4) should be 46: ${result}`);
I put the backtick in the wrong place...
@alvinhochun I think it is time to move dev
into stable
?
Done
@alvinhochun the new version will include:
`... ${...} ...`
"......\
To handle these,
TokenizeState
has a new field:is_within_text_terminated_by
which isOption<char>
.is_within_text_terminated_by
"hello"
StringConstant
None
"hello
LexError
None
"hello\
StringConstant
Some('"')
`hello
|StringConstant
|Some('`')
`hello ${
|InterpolatedString
|None
`... ${...} hello`
|StringConstant
|Some('`')
When you see an
InterpolatedString
, you just push a level onto a stack, and start counting braces. The next token will be the{
of the${
. Once you finish the last closing}
for the level, pop the stack, setstate.is_within_text_terminated_by = Some("`")
to continue parsing as string.