Add parsetree support for wildcards in simple expressions - #300
Open
dra27 wants to merge 5 commits into
Open
Conversation
Pexp_hole
dra27-js
force-pushed
the
upstream-Pexp_hole
branch
3 times, most recently
from
August 7, 2026 06:21
07d22b8 to
e7bb8f4
Compare
Record the current behaviour of the wildcard `_` appearing in expression positions: - `~_:` and `?_:` already lex as labels named `_` - where a general expression can start, the parser recognizes `_` via an ad hoc rule in order to report a specific syntax error; - where only a simple expression is allowed (function-argument positions), "_" is a plain syntax error. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
dra27-js
force-pushed
the
upstream-Pexp_hole
branch
from
August 7, 2026 06:24
e7bb8f4 to
53fcb48
Compare
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
dra27-js
force-pushed
the
upstream-Pexp_hole
branch
from
August 7, 2026 06:29
53fcb48 to
57ee73d
Compare
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
dra27-js
force-pushed
the
upstream-Pexp_hole
branch
from
August 7, 2026 06:31
57ee73d to
db22502
Compare
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.
This PR first extends the parser to recognise syntax errors specifically related to invalid uses of
_in more places. It then converts these illegal_to a new parsetree node, moving the error handling for encountering them to the type checker. The value of this change is that ppxes can both transform parsetrees which include the new node, and also use the OCaml parser to parse attribute and extension point payloads which include them.The name
Pexp_holecomes from the (highly experimental) feature in oxcaml/oxcaml#3310 which introduced it. Although the feature in OxCaml remains incomplete, we have found the node to be very useful in ppxes, and the parsing was extended in oxcaml/oxcaml#4956 entirely with ppx use in mind. We think the node is a useful addition to the parsetree, even without a language feature that directly requires it.The PR itself is three fairly straightforward commits, which are worth reviewing separately:
fun_expruses of_displaying the existing "unexpected wildcard" parsing error, and all the additionalsimple_exprpoints where a standard "syntax error" is displayedPexp_holeas a simple expression oxcaml/oxcaml#4956, without the parsetree node), extends the handling of_tosimple_expr, which can be seen in the parse-errors test outputThere are various subtleties (visible in the reference files) to do with
_and~/?corner cases. For information, the original work predates LLM-use - Claude's responsibility in this PR was refactoring the work to be a syntax change, then a parsetree change, and adding the tests to demonstrate the effects.