tolerant-php-parser
tolerant-php-parser copied to clipboard
API should support getting next or previous tokens
trafficstars
A basic implementation of this would be adding a method Node::getDescendantTokenAtPosition (similar to Node::getDescendantNodeAtPosition), and because the tree is fully representative, we could simply $rootNode->getTokenAtPosition($token->getEnd()) or $rootNode->getTokenAtPosition($token->getFullStart()-1). Eventually, the method could be optimized further.
Edge cases:
- Zero-length error tokens (of type MissingToken) should not be returned by this method. All other tokens are uniquely addressable, as per our defined invariants.