Skip to content

Fix parsing of ReScript compiler syntax examples - #309

Merged
aspeddro merged 5 commits into
rescript-lang:mainfrom
aspeddro:cover-syntax-from-compiler
Nov 15, 2026
Merged

aspeddro merged 5 commits into
rescript-lang:mainfrom
aspeddro:cover-syntax-from-compiler

Conversation

@aspeddro

Copy link
Copy Markdown
Collaborator

Summary

ReScript compiler printer fixtures exposed missing grammar rules and premature automatic semicolon insertion. This PR allows those constructs to parse without ERROR or MISSING nodes and adds 28 regression tests organized by syntax category.

Declaration continuations

Newlines and comments before constraint or a binding's = no longer terminate the declaration:

type result<'good, 'bad> =
  | Good('good)
  | Bad('bad)
  constraint 'good = bool
  constraint 'bad = float

let identity: int => int
  /* The initializer belongs to the same binding. */
  = value => value

Extensible types and constructor rebindings

Support private extensible types and constructor aliases, including qualified aliases and decorated constructors:

module Private = {type t = private ..}
type event = ..
type event += Original(int)
type event += Alias = Original

Functors

Support bare and anonymous functor parameters, unit parameters, and type annotations on functor arguments:

module type Input = {type t}
module type Output = {type t}
module type Build = Input => Output
module type Anonymous = (_: Input) => Output

module Make = (Config: Input, ()) => {type t = Config.t}
module Config = {type t = int}
module Result = Make(Config: Input, ())

Expression receivers and labeled arguments

Braced expressions can be used as call, member-access, and subscript receivers. Labeled arguments now accept punned type annotations and combined source-type/coercion annotations:

let add = (a, b) => a + b
let sum = {add}(1, 2)
let values = [1, 2]
let first = {values}[{0}]

let call = (~value: int) => value
let value = 1
let typed = call(~value: int)
let coerced = call(~value=value : int :> int)

Additional Coverage

  • Polymorphic variant conjunctions (&) and escaped type variables.
  • Repeated type constraints in module type refinements.
  • Explicit exception result types and extensions in type/pattern positions.
  • Type annotations in collection patterns and optional parenthesized record patterns.
  • Adjacent decorators and decorator payloads containing patterns, guards, or declarations.
  • Signature payloads in extensions.
  • Regression cases for tuple callbacks, decorator statement boundaries, and continuations through comments.

The generated parser and node metadata are updated. The ReScript development dependency is updated to 13.0.0-alpha.7 for compiler validation.

Validation

  • npm test: 185/185 corpus tests passed, including 28 new cases; highlighting assertions passed.
  • node scripts/test_wild.mjs: 2,084 files across 11 projects, zero parse errors.
  • npm run lint and npm run checkformat: passed.
  • git diff --check: passed.
  • 25 adapted standalone examples compiled with npx bsc and parsed with npm run parse --.

The standalone examples were checked locally under the Git-ignored test_wild/to-fix directory. Four examples preserve unsupported extension or semantically invalid printer fragments inside custom @syntax(...) attribute payloads: the compiler validates their syntax but does not type-check or expand those payloads. The corpus includes the original unwrapped snippets; successful Tree-sitter parsing does not imply successful type checking or extension execution.

Valid syntax from compiler printer fixtures was rejected by missing
grammar rules and premature automatic semicolon insertion.

Support additional type constraints, escaped type variables, extensible
types, functors, patterns, decorator payloads, and expression forms.
Preserve declaration continuations across newlines and comments.

Add 28 regression tests organized by syntax category and document
compiler validation limits for the standalone examples.

Validation: 185 corpus tests pass; 2,084 wild files parse without errors.

Signed-off-by: Pedro Castro <aspeddro@gmail.com>
Valid syntax from compiler printer fixtures was rejected by missing
grammar rules and premature automatic semicolon insertion.

Support additional type constraints, escaped type variables, extensible
types, functors, patterns, decorator payloads, and expression forms.
Preserve declaration continuations across newlines and comments.

Add 28 regression tests organized by syntax category and document
compiler validation limits for the standalone examples.

Validation: 185 corpus tests pass; 2,084 wild files parse without errors.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T05:03:02.594596Z 82f1011 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: de0c5af277

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread grammar.js Resolved
…n_relation precedence.

`call(~x=1 + 2 : int :> int)` now coerces the entire sum, preserving
existing parenthesized trees.

Signed-off-by: Pedro Castro <aspeddro@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 685d8534ca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread grammar.js Resolved
Remove forced precedence from source-typed coercions so an outer colon
can follow a completed nested ternary without error recovery. Preserve
full-expression coercions and declare the resulting rule conflicts.

Add regression coverage for nested numeric and identifier branches,
including a nested consequent with an explicit source-typed coercion.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 31fba5ad66

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread grammar.js Resolved
Prefer complete unescaped character literals over type-variable tokens
when a ternary colon can also introduce a source-type annotation.
Preserve escape-sequence nodes and type-variable coercions.

Add regression coverage for simple, nested, escaped, and coerced
character-valued ternaries and regenerate the parser.
@aspeddro
aspeddro merged commit d93f5cb into rescript-lang:main Nov 15, 2026
8 checks passed
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