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

Semantic syntax highlighting #367

Merged
merged 68 commits into from
Mar 23, 2022

Conversation

zth
Copy link
Collaborator

@zth zth commented Mar 12, 2022

Check out the forum post for context.

Closes #89
Closes #357
Closes #85
Closes #57
Closes #35
Closes #275
Closes #21

@zth zth changed the base branch from master to parser March 12, 2022 13:01
@zth zth changed the title WIP: Semantic highlighting Semantic syntax highlighting Mar 19, 2022
@zth zth marked this pull request as ready for review March 19, 2022 11:44
@zth zth changed the base branch from parser to master March 19, 2022 11:49
@zth zth force-pushed the semantic-highlighting branch from 94970db to b7dd509 Compare March 19, 2022 13:00
cristianoc and others added 22 commits March 19, 2022 14:05
Don't emit semantic tokens for true/false.
Remove redundant parts of grammar that were overriding booleans.
In case the user types `\""`
Labels are not handled by semantic highlighting (because there is no precise location information in the AST).
But the grammar defines to/downto as keywords, in order to handle for loops.

There are 3 cases where to/downto can be labels:
1) function definition `(~to as x) =>...`
2) function application `foo(~to=...)`
3) JSX props `<foo to=...`
(punned cases are not problematic as they are also variables, and variables are handled via semantic highlighting).

The grammar now recognises patterns of the form `to = ` and `to as` and highlights `to` as a variable.

The correctness of this relies on an observation: in `to =` and `to as`, it's not possible that `to` is the keyword of a syntactically valid for loop, as for that to be the case it must be followed by an expression.
The jsx grammar only needs to take care of `<>` and `</>` and `</` and `/>`.
The `<` and `>` cases are handled via semantic highlighting.
And the ids are handled via semantic highlighting just like ids in any other context.
Does not rely on the code to be formatted in order to determine if there are children.
….someType.

- #foo is marked as enum
- space is allowed: # foo
- #...foo. is a type
@cristianoc cristianoc force-pushed the semantic-highlighting branch from 8d801ff to 2d7fcd1 Compare March 19, 2022 13:06
@cristianoc cristianoc merged commit 6bdc1a5 into rescript-lang:master Mar 23, 2022
@zth zth deleted the semantic-highlighting branch March 23, 2022 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants