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

String Interpolation #940

Open
peq opened this issue Feb 14, 2020 · 2 comments
Open

String Interpolation #940

peq opened this issue Feb 14, 2020 · 2 comments

Comments

@peq
Copy link
Collaborator

peq commented Feb 14, 2020

Add a nicer way to construct strings.

So instead of

return "(" + v.x.toString() + ", " + v.y.toString() + ", " + v.z.toString() + ")"

we could write:

return s"(${v.x}, ${v.y}, ${v.z})"

I am not sure if we should add a special syntax for strings with interpolation (like the s prefix in the example above) or just allow interpolation in every string (and use \$ to write a real dollar sign).

We should also add a syntax for multiline strings, like:

let s = """This is a
           string with
           several lines"""

This thread is open for suggestions and discussion.

@Jaccouille
Copy link

Hello, I'd like to contribute to the multiline strings, may I ask for some pointers?

What I believe I've understood so far I don't have any experience with lexer/parser :

I don't know how to test apart from running make_for_userdir, reload and build in Visual studio code.
I don't know how to test the language server so I can see that my multi line string is recognized as a string in Visual studio code.

@Frotty
Copy link
Member

Frotty commented Aug 30, 2023

Instead of building the compiler, I would suggest you write unit tests instead, which you can run in your IDE. Then you can go from there to see what errors you have to address. Tests will be required anyway for the PR to be accepted.
Otherwise, you seem to be on the right path, you need to add an antlr rule (perhaps backticks would be better than """).
Then probably the easiest way would be to transform the special multiline string into a concatenation of regular strings with line breaks added.
Regarding Visual Studio Code, the syntax highlighting is defined in the extension's source repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants