This directory owns ReScript source parsing, comment attachment, printing, and
the built-in JSX transformation. The parser is hand-written and produces the
parsetree consumed by compiler/ml.
src/res_scanner.mltokenizes source text.src/res_parser.mlandsrc/res_grammar.mlimplement parsing and recovery.src/res_comment.mlandsrc/res_comments_table.mlretain and attach comments for printing.src/res_printer.ml,src/res_doc.ml, andsrc/res_parens.mlimplement formatting.src/jsx_ppx.mlselects and applies the built-in JSX transformation;src/jsx_v4.mlimplements the current transform.cli/res_cli.mlprovides the repository-onlyres_parserdiagnostic tool. Production compiler code calls the syntax library APIs.
See Formatter.md for formatter policy and JSX.md for the current JSX transformation contract.
Run commands from the repository root:
make # build the compiler and build system
make test-syntax # parser and printer tests
make test-syntax-roundtrip # parse/print round-trip tests
make checkformat # check repository formattingUse the repository diagnostic CLI to inspect one file:
dune exec res_parser -- example.res
dune exec res_parser -- -print tokens example.res
dune exec res_parser -- -print ast -recover example.res
dune exec res_parser -- -print comments example.res
dune exec res_parser -- -print ml example.res
dune exec res_parser -- -print res -width 80 example.resThe CLI is for compiler development and tests; it is not a supported public parser interface.
A syntax change can affect more than the grammar. Check each relevant layer:
- scanner tokens and parser recovery;
- the current parsetree in
compiler/ml/parsetree.ml; - printing, parentheses, and comment attachment;
- the v0 AST bridges in
compiler/ml/ast_mapper_from0.mlandcompiler/ml/ast_mapper_to0.ml; - type checking and every later compiler representation that carries the construct;
- parser, round-trip, type-error, and end-to-end tests.
Do not modify compiler/ml/parsetree0.ml. It is the frozen input/output shape
for existing PPX integrations. When the current parsetree changes, define an
explicit compatibility mapping in both directions; do not use a wildcard to
discard a new construct.
Parser tests should cover valid input, recovery from invalid input, printing, and comment placement where applicable. Run the round-trip suite whenever a change affects parsing or printing, even when the intended AST is unchanged.
Public language behavior belongs on the ReScript website. This directory keeps
implementation-facing documentation needed to change the parser, printer, or
built-in transformations. Put API contracts in .mli files and local parsing
or printing invariants beside their implementation.