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

Matching multiline text #211

Open
Nv7-GitHub opened this issue Sep 18, 2023 · 2 comments
Open

Matching multiline text #211

Nv7-GitHub opened this issue Sep 18, 2023 · 2 comments

Comments

@Nv7-GitHub
Copy link

My language has syntax that is structured as follows:

<Group 1>
<Group 2>
<Group 2>

<Group 1>
<Group 2>
<Group 2>
<Group 2>

...

There are sets of one "Group 1" followed by any number of "Group 2" before a blank line, after which another set starts. I want Group 1 highlighted differently than Group 2. There are no identifying features within the line, just its place within the file. I tried using newlines in a regex to capture these but it didn't work, and it seems that VSCode only goes one line at a time for the regex.

I can't use a language server since this needs to work in VSCode web, how can I achieve this highlighting?

@jeff-hykin
Copy link

(I'm just a random guy that does a lot of highlighting not a VS Code contributor btw)

how can I achieve this highlighting

There's only two tools in Textmate parsers (VS Code and many editors use Textmate grammars for highlighting).

  • The pattern (which can only match one line)
  • The pattern range (which has a start pattern, which can only match one line, and an end pattern, which can only match one line)

Thats it.

So you could get creative, use a pattern range, have it start with group 1, have it end when it sees a blank line, and then restrict what patterns are allowed inside of the pattern range.

Here's some code snippets to show a little bit of what I mean.

"What if the start-trigger/start-pattern requires multiple lines to be identified?"

Well then you're straight outta luck. Textmate parsers are hacky, very-limited things. Its actually more amazing that they work at all. Stuff like the C++ pre-processor just straight up break it with no good workaround. Its sad but that's how it is. One day (maybe) VS Code will switch to the Tree Sitter Parser and these problems won't exist.

@alexdima
Copy link
Member

I can't use a language server since this needs to work in VSCode web, how can I achieve this highlighting?

You could try using semantic tokens. There you can look at the entire file contents when creating them, not just one line at a time, looking for patterns. You can create an extension that uses a nodejs language server and our libraries for that. They are fit for running in a web worker, and creating a new worker on the web or a new nodejs process on the desktop. In our codebase, you can take a look at css.

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

No branches or pull requests

3 participants