rhaiscript / lsp

Language server for Rhai.
Apache License 2.0
43 stars 4 forks source link

String templates #75

Closed tamasfe closed 2 years ago

tamasfe commented 2 years ago

I finally decided to tackle this.

The AST remained surprisingly simple, a string template literal now looks like this:

LitStrTemplate =
  ('lit_str' '${' LitStrTemplateInterpolation '}')* 'lit_str'

The first lit_str token always starts with a backtick, whereas the last lit_str always ends with one. If there are no intermediate interpolated blocks, the entire node really is just a single lit_str.

After encountering a backtick, I manually parse each string segment before/between/after interploated blocks. There was some trickery because this essentially bypasses most of the context and the tokenizer behind it which has to be advanced manually.

In the end this was a lot less work than I expected. That is until we encounter the edge-cases and bugs.

Closes #46.

schungx commented 2 years ago

Seem to work just fine! Bravo!