Repository navigation
Apply design patterns across packages: shared scanner loop, polymorphic criteria nodes, label dispatch, split SLR parser - #3
Merged
Conversation
…tility, improve consistency across scanners
- Introduce `KIND` and `STYLE` as class variables for node types. - Centralize node copying logic with `copy_into` methods in node classes. - Generalize edge validation via `check_target`. - Simplify `add_node` and edge attachment logic in `CriteriaGraph`. - Merge node shape definitions into `nodes.py`.
…IT_LATEX` lookup, and refactor subtree tagging logic in node label parsing.
…o use typed parse-table entries, and adjust related tests, documentation, and changelog.
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.
Four behaviour-preserving refactors from a design-pattern review of the packages. Each is one commit and can be reviewed (or reverted) on its own. Public behaviour is unchanged; the one API change is noted under slr_parsing.
Changes
_replace_command,sanitise_latexandnormalise_unicode_operatorseach repeated the same find/copy/replace loop. They now pass a finder to_scanning.replace_matches.substitute(hot path with a first-character index),_protect_e_symbols(token-based) and units'_replace_prefix(another package) are left as they were.KINDandSTYLEand implementscopy_into(graph)andcheck_target(target). That replaces theisinstancechains inCriteriaGraph.add_node,CriteriaGraph.attachandtree._tree_node. Error messages are unchanged.match._UNIT_LATEXtable.quantity_tag_handleris amatchon the label, using a leaf-tag table and named predicates (_is_unit_power,_is_reciprocal_unit,_is_number_ratio).kg 2xreported a garbled extra reverted unit. A new regression test pins the currentreverted_unitsfor those inputs.SLRParsersplit into scanner, table and driver.Scanner(scanner.py) turns text into tokens.ParseTable(table.py) holds the FIRST and FOLLOW sets, the LR(0) states and the rows.SLRParserkeeps its constructor and methods and runs the parse.Shift,Reduce,Accept,RejectandRecover, exported with anEntryunion. They replace the integer encoding.parsing_table_to_string()output is unchanged.@final, and the driver tells them apart withtype(...) ischecks:matchmadeparse()8–10% slower.Verification
tools/parity/check.py: 0 unexpected changes.parsing_table_to_string()output is byte-identical before and after for the criteria, convention and quantity parsers.mainwith runs interleaved:parse()alone is about 2–3% faster.scripts/check_dist.pypasses.Followed by the stacked PR for
PhysicalQuantity(refactor/physical-quantity).🤖 Generated with Claude Code