Repository navigation
Adds Predicator.AST prewalk, postwalk, reduce - #248
Merged
Merged
Conversation
Tooling that reads or rewrites a parsed tree hand-wrote a clause per node kind. Predicator.AST adds the three walks in Macro's shape over everything Parser.visitable/0 names: expressions, statements, blocks and programs. An accumulator is threaded, children are visited in source order, and the trailing position slot is carried untouched. An object key is part of its entry, not a node, so the walks skip it. A duration has no children; a relative date's duration is a child. A binding test reads the typespec's constructor set and goes red when a node kind has no map_children/3 clause. It is added to the sabotage test roots. Refs: px-ybw0
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
Predicator.ASTwithprewalk/3,postwalk/3andreduce/3over the positioned AST. Tooling that reads or rewrites a parsed tree no longer hand-writes a clause per node kind.What it does
Macrowalks:prewalk(ast, acc, fun)andpostwalk(ast, acc, fun)takefun.(node, acc) -> {node, acc}and return{ast, acc};reduce(ast, acc, fun)takesfun.(node, acc) -> acc, visits pre-order and rewrites nothing.t:Predicator.Parser.visitable/0names: expressions, statements, blocks and programs.{line, column}, a span ornil.Predicator.Visitoris unchanged.Rules for the three shapes that are not plain children
t:Predicator.Parser.object_key/0) is outside theast/0andvisitable/0unions. The walks treat it as part of its entry: it is never handed to the callback and is carried through untouched; each entry's value is visited in entry order. Pinned by two tests (no key is ever seen; a rewrite leaves the key as it was).:durationholds{integer, unit}pairs, which are data. It has no children.:relative_date's first element is a node (its duration) and is walked as a child.A tuple with an unknown tag raises
FunctionClauseError; the sync test below is what keeps that from happening for a real node kind.Sync test
test/predicator/ast_clause_coverage_test.exsreads thevisitable/0union from the compiled parser beam (Code.Typespec.fetch_types/1) and themap_children/3clause heads fromlib/predicator/ast.ex, and compares them both ways, so adding a node kind with no children clause turns it red (and so does a clause with no node kind). It follows the model ofvisitor_clause_coverage_test.exs. It is added togate.sabotage.test_rootsin.claude/wurk.json, as that file's convention asks of a binding test.Provenance
The traversal's shape (
Macro's, children in source order, programs and statement types walked) was decided by the conductor under a standing consent, 2026-10-12.Gate and tier
mix qualitygreen on this head: Format, Compile, Doc links, Dependencies, Docs, Credo, Tests, Dialyzer. Doctor, Gettext and Sobelow report skipped (not installed), the expected state for this repo.conformance/file moved.changelog.d/px-ybw0.md,### Added, one line.Sabotage (sync test and order tests)
:durationclause head to:durationxinast.exPredicator.ASTClauseCoverageTest"map_children/3 covers exactly the constructors of Parser.visitable/0, both ways" (also walk tests that reach a duration){:sabotage_probe, ast(), position()}member tot:Predicator.Parser.ast/0rightbeforeleftin the comparison clausePredicator.ASTTest"binary nodes visit left then right" and "prewalk visits a parent before its children, postwalk after"Each file was restored byte-equal from a copy and the build forced before the next check.