You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Move the majority of token/terminal match decisions from Python
callbacks into the C++ Earley core, per doc/cpp-matching-design.md.
- binparser.py: build_matching_table() classifies each terminal into a
native matching kind (strong/lemma literals, default-category, noun,
adjective, adverb, masked abfn/pfn, töl) or T_PYTHON for semantics
that stay in Python (verbs, prepositions, proper names, ending
constraints, etc.); encode_token_matching_data() packs each token's
BÍN meanings into MeaningRec arrays sharing the existing VBIT/fbits
bit space. Literal lemmas/forms are interned so literal matching
reduces to integer identity.
- eparser.cpp/.h: Parser::evalMatch() decides matches natively from
the TerminalSpec table and per-column TokenRec data (fetched once
per column via the new MeaningsFunc callback and cached per token
key); Column::matches() falls back to the Python callback for
T_PYTHON terminals and non-word tokens. A parity mode double-checks
every native decision against the Python matcher.
- fastparser.py: install the table at parser construction, gated so
that subclasses which override token wrapping (e.g. GreynirCorrect)
automatically keep pure Python matching; also disable via the
_USE_CPP_MATCHING class attribute or GREYNIR_DISABLE_CPP_MATCHING=1.
Parity mode via GREYNIR_MATCHING_PARITY=1.
Phase 0 measurement: 69% of match queries are natively answerable.
Measured effect: ~89% of matching callbacks eliminated; typical
fresh-text parsing 2.2x faster on CPython 3.13 (1.40s -> 0.65s for
the benchmark set), test suite ~20% faster, PyPy ~20% faster cold;
warm-cache and long-sentence workloads unchanged. Query-level parity:
zero discrepancies over the test corpus.
Incidental pre-existing finding, documented in the design doc:
reduction of exact score ties is unstable across repeated parses,
so the new equivalence test compares forests, not reduced trees.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
0 commit comments