Skip to content

Represent regexp literals explicitly and remove %re syntax - #8634

Draft
cknitt wants to merge 3 commits into
masterfrom
regexp
Draft

Represent regexp literals explicitly and remove %re syntax#8634
cknitt wants to merge 3 commits into
masterfrom
regexp

Conversation

@cknitt

@cknitt cknitt commented Sep 7, 2026

Copy link
Copy Markdown
Member

Represent regexp literals explicitly and remove %re syntax

Add Pexp_regexp to represent regexp literals directly, preserving their pattern, escapes, flag order, attributes, and location. Literals lower to the existing typed raw-JavaScript representation, so Typedtree, Lambda, and runtime behavior remain unchanged.

Remove %re source syntax with a targeted migration diagnostic. ReScript 12’s formatter already rewrites it to regexp literals. The legacy "re" encoding remains confined to the frozen AST0 bridge for PPX compatibility: supported payloads become Pexp_regexp, payload attributes are retained, and malformed payloads are rejected at the bridge.

Why JSX recovery changes too

Previously, a missing JSX prop value before /> could be misread as an unterminated regexp. Editor completion recognized the resulting empty regexp and missing location as a recovery sentinel. Introducing a properly located regexp node requires removing that dependency.

The parser now produces an expression hole for missing prop values. Disambiguation still needs care: a valid regexp can begin with />, and an enclosing JSX closing tag can supply an apparent regexp delimiter.

Recovery checkpoints let the parser keep the regexp interpretation unless the element cannot close structurally. It can then restore the latest ambiguous boundary and recover it as a self-closing tag. This preserves earlier valid regexps despite later errors and avoids repeatedly parsing the remaining element.

Validation

  • Full compiler/runtime, analysis, and syntax round-trip suites pass.
  • All 310 unit tests pass; each commit builds and passes its unit tests.
  • Coverage includes AST0 compatibility, metadata preservation, lowering, fresh regexp instances, nested JSX recovery, and completion.

Signed-off-by: Christoph Knittel <ck@cca.io>

# Conflicts:
#	CHANGELOG.md

# Conflicts:
#	CHANGELOG.md
Signed-off-by: Christoph Knittel <ck@cca.io>

^ Conflicts:
^	tests/ounit_tests/ounit_lambda_constant_tests.ml
Signed-off-by: Christoph Knittel <ck@cca.io>
@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.81319% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.63%. Comparing base (2e532c7) to head (5779df7).

Files with missing lines Patch % Lines
tests/ounit_tests/ounit_jsx_loc_tests.ml 83.33% 9 Missing ⚠️
compiler/syntax/src/res_parens.ml 30.00% 7 Missing ⚠️
tests/ounit_tests/ounit_ast_mapper0_tests.ml 92.18% 5 Missing ⚠️
tests/ounit_tests/ounit_lambda_constant_tests.ml 87.50% 4 Missing ⚠️
compiler/ml/ast_payload.ml 84.61% 2 Missing ⚠️
analysis/src/completion_jsx.ml 50.00% 1 Missing ⚠️
analysis/src/dump_ast.ml 0.00% 1 Missing ⚠️
analysis/src/utils.ml 0.00% 1 Missing ⚠️
compiler/frontend/ast_exp_handle_external.ml 0.00% 1 Missing ⚠️
compiler/ml/ast_mapper_from0.ml 94.11% 1 Missing ⚠️
... and 4 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8634      +/-   ##
==========================================
+ Coverage   77.58%   77.63%   +0.04%     
==========================================
  Files         475      475              
  Lines       64062    64270     +208     
==========================================
+ Hits        49704    49894     +190     
- Misses      14358    14376      +18     
Files with missing lines Coverage Δ
compiler/frontend/ast_exp_extension.ml 100.00% <100.00%> (ø)
compiler/frontend/bs_builtin_ppx.ml 91.31% <100.00%> (+0.28%) ⬆️
compiler/ml/ast_helper.ml 80.72% <100.00%> (+0.07%) ⬆️
compiler/ml/ast_iterator.ml 93.83% <100.00%> (+0.02%) ⬆️
compiler/ml/ast_mapper.ml 77.48% <100.00%> (+0.04%) ⬆️
compiler/ml/ast_mapper_to0.ml 70.58% <100.00%> (+0.24%) ⬆️
compiler/ml/pprintast.ml 91.29% <100.00%> (+0.01%) ⬆️
compiler/syntax/src/res_ast_debugger.ml 96.18% <100.00%> (+0.01%) ⬆️
compiler/syntax/src/res_core.ml 91.73% <100.00%> (+0.13%) ⬆️
compiler/syntax/src/res_parser.ml 93.65% <100.00%> (+0.43%) ⬆️
... and 15 more

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Sep 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@8634

@rescript/belt

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/belt@8634

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@8634

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@8634

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@8634

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@8634

@rescript/runtime

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@8634

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@8634

commit: 5779df7

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

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