Recognition, semantics and effect commit¶
- Pure recognition and
guard(callable(ConcreteNode): bool)choose syntax. Guards may run on speculative alternatives; they cannot read typed semantic output from a CST node. False rejects the attempt. - Successful ParseResult reads evaluate
mapValue()or collection operations lazily, with per-recognition caching. Failed/discarded attempts do not evaluate them automatically. Raw CST/AST text never depends on transforms. validate()runs selected semantic validators after syntactic acceptance. Validators receive ParseResult and return true, false, a message string, a ValidationIssue or a list of issues (empty means valid). Child and accepted-trivia validation contribute issues once. Definition validators use this same contract, without speculative alternative selection.commit()validates and then executes selectedonCommit()effects and assignments in recognition order. Effects receive ParseResult as their only argument. They never run merely because parsing or output reading succeeds.
Commit returns false for failed syntax or rejected semantic validation. An accepted result containing explicit error recovery also refuses commit. Its validation reports recovery issues without running semantic validators; no effects execute on valid siblings or enclosing parsers. Successful commits are idempotent. Mapping, validation and effect exceptions are cached and rethrown; a partially executed effect sequence is never retried or reported as committed. External effects cannot be rolled back automatically. Recursive value reads, named-result evaluation, validation and commit are errors.
Grammar callbacks/validators/mappings/names are snapshotted per recognition. Discarded alternative callbacks and speculative trivia produce no committed effects. A semantic rejection does not retry a syntactically selected choice; use a pure guard when rejection belongs to recognition.
Internal effect snapshots receive their owning match only during commit, so they do not keep discarded matches alive through self-references. User callbacks, cached values and retained exceptions can still introduce reference cycles.
For runtime maintenance details, see lifecycle implementation notes.
See structured validation, semantic values, ParseResult and the runnable examples.