Skip to content

Upstream Pexp_hole - #300

Open
dra27 wants to merge 5 commits into
trunkfrom
upstream-Pexp_hole
Open

Upstream Pexp_hole#300
dra27 wants to merge 5 commits into
trunkfrom
upstream-Pexp_hole

Conversation

@dra27

@dra27 dra27 commented Jul 30, 2026

Copy link
Copy Markdown
Owner

No description provided.

dra27 and others added 5 commits July 30, 2026 11:52
The -dparsetree output for `.` ran the following line of output onto
the same line as "Pexp_unreachable". No expected test output includes
this constructor, so no references change.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A new toplevel test records the current behaviour of the wildcard "_"
appearing in expression positions:
- "~_:" and "?_:" already lex as labels named "_", so e.g. `g ~_:3`
  is already legal;
- where a general expression can start, the parser recognizes "_" via
  an ad hoc rule in order to report "wildcard \"_\" not expected";
- where only a simple expression is allowed (function-argument
  positions), "_" is a plain syntax error.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The ad hoc "wildcard \"_\" not expected" rule moves from fun_expr to
simple_expr, and two new rules recognize the labelled-argument sugar
`~_` and `?_`. All positions where "_" can appear as an expression now
report the ad hoc message instead of a generic syntax error.

UNDERSCORE joins the "first tokens of simple_expr" precedence group so
that it is shifted as a function argument. All the new rules and the
precedence are inside BEGIN/END AVOID markers, since they still exist
only to report an error: the AVOID-stripped grammar is byte-for-byte
unchanged, so the generated-parse-errors corpus is unaffected.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The wildcard "_" now parses as an expression (a "hole", Pexp_hole)
anywhere a simple expression is allowed, including the labelled
argument sugar `~_` and `?_`. Holes are unconditionally rejected by
the type-checker with the same "wildcard \"_\" not expected" message
previously reported by the parser: they are intended to be eliminated
by a ppx rewriter before type-checking (merlin already uses Pexp_hole
as its error-recovery placeholder).

This matches oxcaml (PRs oxcaml/oxcaml#3310 and oxcaml/oxcaml#4956),
with three deliberate differences: Pprintast prints holes from
simple_expr (avoiding a spurious "(_)" in argument positions),
Printast terminates the "Pexp_hole" line properly, and the typing
error goes through Error.log_and_raise for typing recovery.

The generated-parse-errors corpus is not regenerated: the committed
sentences still all produce the same errors, and regenerating churns
thousands of unrelated lines (Menhir has changed its choice of
representative start symbols since the corpus was last generated,
and the generate-parse-errors recipe predates the current ocamltest
TEST syntax).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Repository owner deleted a comment from github-actions Bot Jul 30, 2026
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

Successfully merging this pull request may close these issues.

1 participant