ion7-grammar / ast.walk

module

ast.walk

Functions

walk.collect_refs

Walk an AST node and accumulate ref-name counts into `counts`.

walk.collect_refs(node, counts)
nodenodeAST node to walk.
countstable{ rule_name → count } accumulator (mutated in place).

walk.build_ref_counts

Build a { rule_name → total_ref_count } map across all rule bodies. Counts how many times each rule name is referenced by other rules.

walk.build_ref_counts(rules)
rulestableArray of { name, body } pairs (from Builder._rules).
→ table{ rule_name → count }

walk.first_literals

Recursively collect literal string prefixes that can start a valid match. Only literal-initiated branches are collected; char-class branches (e.g. [0-9]) are intentionally skipped because they would expand into too many trigger strings to be useful for CRANE grammar_lazy activation.

walk.first_literals(node, rules_map, visited, acc, max_len)
nodenodeAST node to walk.
rules_maptable{ rule_name → body } for ref resolution.
visitedtableSet of already-visited rule names (cycle guard).
acctable{ prefix_string → true } accumulator (mutated).
max_lennumberMaximum prefix length to collect.