Simplify Extended_ast vs Std_ast
Make Extended_ast the single entry point for parsing, validation, and
AST operations. Std_ast becomes a purely internal implementation detail.
Extended_ast.t GADT now uses paired wrapper types that embed both the
extended and standard ASTs: `('a, 'b) paired = {extended: 'a; std: 'b}`.
For the 7 OCaml fragment types (Structure, Signature, Use_file,
Core_type, Module_type, Expression, Pattern), parsing produces both
ASTs in one operation. Repl_file and Documentation have no std
counterpart.
Main changes:
- Add `('a, 'b) paired` record type to Extended_ast, used by the GADT
for fragments with std parser support
- Extended_ast.Parse.ast now internally calls Std_ast.Parse.ast to
produce the paired result. A `paired` helper factors out the common
parse-normalize-pair pattern.
- Absorb Parse_with_comments into Extended_ast:
- `Extended_ast.parse` is the full parsing pipeline (warnings,
hash-bang, tokens, Source.t creation)
- `Extended_ast.parse_toplevel` dispatches Use_file vs Repl_file
- `Extended_ast.Parsed.t` replaces `Parse_with_comments.with_comments`
- `Extended_ast.Warning50` replaces `Parse_with_comments.Warning50`
- Delete Parse_with_comments.ml/.mli
- Documentation bypasses the OCaml parsing pipeline entirely (no
hash-bang handling, no w50, no token collection)
- Add `Extended_ast.equivalent` to check AST preservation using the
embedded std ASTs, returning `Ast_preserved | Docstrings_moved _
| Ast_changed`. Includes a TODO for Repl_file/Documentation which
currently skip the check.
- Add `Extended_ast.dump` and `dump_normalized` for debug output,
falling back to extended AST printing for fragments without std
- Break Normalize_std_ast -> Normalize_extended_ast dependency by
making `normalize_code` a parameter instead of an import
- Simplify Translation_unit: remove `std_fg`/`std_parsed` parameters
from `format` and `parse_and_format`, remove `(type std)`, use
`Extended_ast.equivalent` for validation. Translation_unit no longer
references Std_ast directly.
- Clean up Std_ast: remove `of_syntax`, `any_t`, `Repl_file`,
`Documentation` constructors, comment collection from Parse.ast
- Remove unused `Extended_ast.equal`, `equal_core_type`,
`Normalize_extended_ast.equal`, `Normalize_extended_ast.ast`
- Break Source -> Extended_ast cycle (Source.ml only needs Parsetree)
- Document why Std_ast exists: the standard parser is used to verify
formatting preserves semantics (two programs are equivalent if the
compiler parses them identically)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
e6c6c9
-
Mar 26 03:09 +00:00