Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As mentioned in #91, I have been working on a simplified version of the OCaml language grammar used for syntax highlighting.
As of now, the existing language grammar has various inconsistencies and issues that make it hard to work with. My implementation uses less context-sensitive highlighting and is much simpler and shorter because of it (500 vs 2000 lines). I have also added comments describing each rule, using terminology from the OCaml manual, which will hopefully make it easier to maintain in the future.
I have followed the official OCaml manual as close as I can, so special syntax is highlighted, including:
\\
,\n
,\t
, etc.)int
/int32
/int64
/nativeint
)let+
,and+
, etc.)A limitation of the approach I took is that capital identifiers are all highlighted the same (constructors, exceptions, modules); type parameters (
'a
) and builtin types are the only highlighted types.I also added a few context sensitive highlighting (see the
bindings
patterns) that seem to work consistently, unlike the existing grammar.My intention for this syntax is that it will be a base for incremental improvements in the future. Due to the inherit complexities of the official OCaml grammar, it may be worthwhile to look at tree-sitter or LSP semantic highlighting (proposal: microsoft/vscode-languageserver-node#367) in the future.
Comparison:
For an example of two existing problems that this fixes, I provide the following examples.
For the let operators in #45:
For the Menhir highlighting problem I mentioned in #91:
I know this is a lengthy PR, but hopefully I communicated my justifications clearly. If you have any questions, I'll be happy to answer.