Support Strings inside string interpolations
This PR aims at supporting arbitrary strings inside string interpolations.
Progress on this so far:
- [X] Support fixed strings in interpolations
- [X] Support interpolated strings inside interpolations
- [ ] Report errors with correct and intuitive spans
I'm not sure if the errors are too bad, but I would like a second set of eyes on it if anyone are up for it. I'm having a bit of difficulty figuring out how it all connects to produce the errors and associated spans I get on a given invalid string.
I'm not sure if the errors are too bad, but I would like a second set of eyes on it if anyone are up for it.
Yes, of course. Can you show a few error messages here? Or add some (snapshot) tests so we can discuss them in the review?
I'm having a bit of difficulty figuring out how it all connects to produce the errors and associated spans I get on a given invalid string.
We could probably always fall back to a range that includes the "full" string, if it's hard to generate more precise spans?
Can you show a few error messages here? Or add some (snapshot) tests so we can discuss them in the review?
Gladly. I'll share some examples when next I’m able.
We could probably always fall back to a range that includes the "full" string, if it's hard to generate more precise spans?
I feel like I’m close to getting more specific spans that would provide more helpful errors so I’m not quite ready to give up on it yet. But if I’m unable to get it to work, this would be a good solution I think.
Here is a list of example errors. They are quite unrealistic but simple.
Example of a single missing closing bracket:
>>> "{ "{"Hi"" }"
error: while parsing
┌─ <input:11>:1:4
│
1 │ "{ "{"Hi"" }"
│ ^^^^^^ Unterminated string
Example of a single missing closing bracket with multiple nested interpolations:
>>> "{ "{"Hi"} {"there"" }"
error: while parsing
┌─ <input:16>:1:4
│
1 │ "{ "{"Hi"} {"there"" }"
│ ^^^^^^^^^^^^^^^^ Unterminated string
>>> "{ "{"Hi" {"there"}" }"
error: while parsing
┌─ <input:17>:1:11
│
1 │ "{ "{"Hi" {"there"}" }"
│ ^ Unexpected '{' inside string interpolation
Example of unterminated string inside nested interpolation:
>>> "{ "{"Hi}" }"
error: while parsing
┌─ <input:12>:1:1
│
1 │ "{ "{"Hi}" }"
│ ^^^^^^^^^^^^^ Unterminated string
Example of unterminated string with multiple nested interpolations:
>>> "{ "{"Hi"} {"there}" }"
error: while parsing
┌─ <input:19>:1:1
│
1 │ "{ "{"Hi"} {"there}" }"
│ ^^^^^^^^^^^^^^^^^^^^^^^ Unterminated string
>>> "{ "{"Hi} {"there"}" }"
error: while parsing
┌─ <input:20>:1:1
│
1 │ "{ "{"Hi} {"there"}" }"
│ ^^^^^^^^^^^^^^^^^^^^^^^ Unterminated string
>>> "{ "{"Hi"} {"there} }"
error: while parsing
┌─ <input:21>:1:4
│
1 │ "{ "{"Hi"} {"there} }"
│ ^^^^^^^^^^^^^^^^^^^ Unterminated string
I remembered I had been working on this and gave it another stab. I'm not sure what I think about all the decisions I made, but everything seems to work and error messages are good in all the common and many uncommon cases.