WurstScript
WurstScript copied to clipboard
String Interpolation
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.
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 :
- Wurst.g4 contains antlr rules responsible for parsing
- AntlrWurstParseTreeTransformer replace the tokens with an output
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.
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.