Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Consolidate the parsetree printers

Abierto
#8,798 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Refactorización
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
ocaml
Área
compilers

Línea de trabajo

Start with compiler/ml/printast.ml, compiler/syntax/src/res_ast_debugger.ml, compiler/ml/pprintast.ml, and the roundtrip test in scripts/test_syntax.sh. Trace the printer call sites and parser fixture snapshots named in the issue, then check how bsc -dsource handles PPX and builtin rewrites. Done means removing the redundant printers and comparisons while keeping the listed print modes, fixtures, and tests working.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

The compiler has three printers for the parsetree, and each one matches over every node. Every new node (recently Pexp_dict, Ppat_dict, Pexp_ternary, Pmod_await, Ppat_variant_spread) has to be added to all three, on top of the parsetree, the v0 mappers and the formatter.

Printer Size Output Used by
compiler/ml/printast.ml 827 lines tree with source locations bsc -dparsetree, res_parser -print ast, the playground's parsetree view, ounit_parser_recovery_tests
Sexp_ast in compiler/syntax/src/res_ast_debugger.ml ~1,040 lines S-expression without locations, except the offsets of explicit braces (see below) res_parser -print sexp, used by the formatter roundtrip test
compiler/ml/pprintast.ml 1,471 lines OCaml syntax res_parser -print ml (expected output for the parser fixtures in tests/syntax_tests/data/parsing), bsc -dsource, a few ounit tests

Sexp_ast is redundant. The roundtrip test in scripts/test_syntax.sh formats a file twice and checks two things:

  • the two formatted texts are equal;
  • the ASTs parsed from them are equal (as sexp).

The parser is deterministic, so the AST check holds whenever the text check does. The original file's AST can't usefully be compared with the formatted one, because the formatter changes the AST on purpose, e.g. it removes braces in switch cases.

Sexp_ast prints no locations, with one exception: since #8678 it prints the character offsets of explicit braces (braces_loc of Pexp_braces). That was not intended and nothing depends on it. It should not be carried into any other printer or test.

Pprintast is a leftover from OCaml. ReScript has no other use for printing its AST as OCaml code.

Proposal

  1. Remove Sexp_ast, -print sexp and the redundant AST comparison from the roundtrip test.
  2. Snapshot the parser fixtures with Printast instead of -print ml.
  3. Make bsc -dsource print the parsetree after PPX and builtin rewrites with the ReScript printer instead of OCaml syntax.
  4. Move Pprintast.string_of_int_as_char (used by printlambda.ml and parmatch.ml), then remove Pprintast and res_driver_ml_printer.ml.

That removes about 2,500 lines, and new parsetree nodes need one printer case instead of three. -print comments and -print doc in res_ast_debugger.ml, Printtyped and Printlambda are not affected.

Compatibility: res_parser isn't shipped in the npm packages, so -print sexp and -print ml are internal. bsc -dsource is a debugging flag. Its output switches from OCaml-like to ReScript syntax.

Lenguaje dominante
OCaml
Estrellas
7.5k
Forks
484
Merge medio
19 h 20 min
PR fusionados (30 d)
96

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de rescript-lang/rescript

Todos los issues de rescript-lang/rescript

Issues similares

Más issues de Compilers

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.