doctrine / lexer

Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
https://www.doctrine-project.org/projects/lexer.html
MIT License
11.07k stars 60 forks source link

[TASK] Use proper docblock type for `AbstractLexer::isNextTokenAny()` #63

Closed sbuerk closed 2 years ago

sbuerk commented 2 years ago

[TASK] Use proper docblock type for AbstractLexer::isNextTokenAny()

This patch changes the docblock type hint of AbstractLexer::isNextTokenAny() to list<int|string> to adopt the int and string based support of token types. Thus making phpstan in projects happy which uses this packages for there own lexer implementations.

However this only aligns to other token methods which already supports int and string as token types, thus fixing a wrong set type hint through #48.

Additionally a concrete lexer implementation was added to test a lexer implemention with integer based tokens, adopted from the already string based implementation.

If this got accepted and merged, it would be nice to have a patchlevel release in the nearer time.

Fixes: #62

greg0ire commented 2 years ago

You can use git rebase -i HEAD^^ --exec vendor/bin/phpcbf to fix the coding standard issues.

greg0ire commented 2 years ago

While reading your PR, I noticed there are a lot of repetition of the array shape describing a token. I attempted to extract it into a Psalm type in https://github.com/doctrine/lexer/pull/64, and was forced by static analysis to apply the main change you did to this PR, as well as some others. Please review it.

If this got accepted and merged, it would be nice to have a patchlevel release in the nearer time.

I'll do a release as soon as we merge either your PR or mine.

greg0ire commented 2 years ago

Please address the conflicts, and use a Psalm type.