numbat icon indicating copy to clipboard operation
numbat copied to clipboard

Support Strings inside string interpolations

Open Goju-Ryu opened this issue 1 year ago • 3 comments

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.

Goju-Ryu avatar Nov 17 '24 15:11 Goju-Ryu

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?

sharkdp avatar Dec 27 '24 21:12 sharkdp

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.

Goju-Ryu avatar Dec 27 '24 21:12 Goju-Ryu

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

Goju-Ryu avatar Jan 01 '25 15:01 Goju-Ryu

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.

Goju-Ryu avatar Jul 06 '25 20:07 Goju-Ryu