OxCaml modes - #146
Open
314eter wants to merge 6 commits into
Open
Conversation
Collaborator
Author
|
I reduced the number of states by adding conflicts instead of inlining rules to avoid them. I usually prefer to keep the grammar conflict free, but here it's not worth the increased complexity. |
Open
tkoukpari
suggested changes
Sep 7, 2026
Collaborator
Author
There was a problem hiding this comment.
The _ in type _ t = ... is not really a type variable, it's the absence of a type variable. I tried to make the parsing of _ a bit more consistent across the whole grammar, but completely ignoring it here is maybe not the best solution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds support for OxCaml modes and modalities.
The main difficulty was to get modes to work with function types. The left side of a
function_typecan only be a_simple_type, not a_type. But if the parser encounterslet x : t @, it needs to choose iftis a_simple_typeor_type, since it can't backtrack later. But depending on if it continues withlet x : t @ mode = _orlet x : t @ mode -> t = _, the correct choice is different.The easy solution would be to make the left side of
function_typea_type, and use precedences to make sure everything is still parsed correctly. That almost works, except forwhich will then be parsed as
T with type t = (t as 'a -> t)instead of(T with type t = t as 'a) -> t. I couldn't find a way to avoid that.The alternative solution is to inline
_type. That works, but it needs to be inlined in a lot of places, which results in a lot more states. This PR doubles the parser in size.The other issue was polymorphic types. I had to refactor them a bit to be able to resolve conflicts like
let x : 'a . 'a @ mode -> t = _. This has an impact on the resulting tree-sitter AST.