getIdentifierPattern example

private TokenizerPatterns $patterns;
    private TokenizerEscaping $escaping;

    public function __construct(TokenizerPatterns $patterns, TokenizerEscaping $escaping)
    {
        $this->patterns = $patterns;
        $this->escaping = $escaping;
    }

    public function handle(Reader $reader, TokenStream $stream): bool
    {
        $match = $reader->findPattern($this->patterns->getIdentifierPattern());

        if (!$match) {
            return false;
        }

        $value = $this->escaping->escapeUnicode($match[0]);
        $stream->push(new Token(Token::TYPE_IDENTIFIER, $value$reader->getPosition()));
        $reader->moveForward(\strlen($match[0]));

        return true;
    }
}
Home | Imprint | This part of the site doesn't use cookies.