Skip to content

Tighten and modernise the public API - #156

Merged
chrisjenkinson merged 7 commits into
masterfrom
claude/api-cleanup
Sep 25, 2026
Merged

chrisjenkinson merged 7 commits into
masterfrom
claude/api-cleanup

Conversation

@chrisjenkinson

@chrisjenkinson chrisjenkinson commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

This tightens the public API and moves the code to modern PHP property syntax:

  • StateInterface, NodeInterface, NodeVisitorInterface and TokenInterface declare native return types. findMatchingToken() returns TokenInterface instead of TokenInterface|false, and leaveNode() returns NodeInterface|NodeVisitorAction|null.
  • VisitableInterface::accept() takes a VisitorInterface and returns mixed. The visitor interfaces have docblocks explaining how to extend them. Token::getValue() throws NonexistentKeyException for a missing key.
  • StateInterface drops runMatchers(), and AbstractState's matching internals are private. Matches are held as small internal MatcherMatch objects instead of three parallel arrays.
  • Lexer::pushState() replaces setState(), which remains as a deprecated alias.
  • Every property is typed, with readonly and constructor promotion where they fit.

Breaking changes: implementations of these interfaces need the new return types, including leaveNode() in visitors and accept() in visitable nodes. Subclasses of AbstractState can no longer call runMatchers() or guardAgainstWrongNumberOfMatches(). Subclasses of AbstractNode that redeclare $attributes or $nodes must type them as array. Token and MatchedText now require arrays for their values.

@chrisjenkinson
chrisjenkinson merged commit 08ff031 into master Sep 25, 2026
4 checks passed
@chrisjenkinson
chrisjenkinson deleted the claude/api-cleanup branch September 25, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant