Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Strings inside string interpolations #658

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Goju-Ryu
Copy link
Contributor

@Goju-Ryu Goju-Ryu commented Nov 17, 2024

This PR aims at supporting arbitrary strings inside string interpolations.

Progress on this so far:

  • Support fixed strings in interpolations
  • 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.

@sharkdp
Copy link
Owner

sharkdp commented Dec 27, 2024

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?

@Goju-Ryu
Copy link
Contributor Author

Goju-Ryu commented Dec 27, 2024

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
Copy link
Contributor Author

Goju-Ryu commented Jan 1, 2025

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:111"{ "{"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:11"{ "{"Hi} {"there"}" }"
  │ ^^^^^^^^^^^^^^^^^^^^^^^ Unterminated string

>>> "{ "{"Hi"} {"there} }"
error: while parsing
  ┌─ <input:21>:1:41"{ "{"Hi"} {"there} }"
  │    ^^^^^^^^^^^^^^^^^^^ Unterminated string

@Goju-Ryu Goju-Ryu force-pushed the nested-interpolation branch from 9156a36 to 69aef06 Compare January 12, 2025 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants