Add T_PERCENT type to handle %4%-style format specifiers#61
Merged
Conversation
Agent-Logs-Url: https://github.com/donatj/printf-parser/sessions/e0bec571-8995-42d0-95e4-b614c587fb7f Co-authored-by: donatj <133747+donatj@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add handling for type % in printf cases
Add Apr 22, 2026
T_PERCENT type to handle %4%-style format specifiers
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for PHP printf-compatible format specifiers that end in % but include modifiers (e.g. %4%, %l%, %+5.5%), treating them as valid argument-consuming lexemes instead of invalid ones.
Changes:
- Introduces
ArgumentLexeme::T_PERCENT('%') and includes it inVALID_T_TYPESso the parser recognizes%...%type specifiers. - Extends integration coverage to verify parsing/serialization and that these specifiers consume exactly one argument (typed as
ARG_TYPE_MISSING).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/ArgumentLexeme.php |
Adds the new T_PERCENT type and makes it a recognized valid type for parsing. |
test/Integration/ParserTest.php |
Adds parsing + argument-consumption test cases for %...% percent-type specifiers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PHP's
printfallows format specifiers ending in%with modifiers (e.g.%4%,%l%,%+5.5%). These differ from%%: they consume one argument (without using it), whereas%%consumes none. Previously these were emitted as invalid lexemes.Changes
ArgumentLexeme: addsT_PERCENT = '%'constant and includes it inVALID_T_TYPES.argType()returnsARG_TYPE_MISSINGby default sinceT_PERCENTis not in any of the typed groups (INTEGER_TYPES,DOUBLE_TYPES,STRING_TYPES).%%special case: untouched — still emits aT_LITERAL_STRINGand consumes no argument.