Skip to content

Add T_PERCENT type to handle %4%-style format specifiers#61

Merged
donatj merged 2 commits into
masterfrom
copilot/handle-type-percent-cases
Apr 22, 2026
Merged

Add T_PERCENT type to handle %4%-style format specifiers#61
donatj merged 2 commits into
masterfrom
copilot/handle-type-percent-cases

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 22, 2026

PHP's printf allows 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: adds T_PERCENT = '%' constant and includes it in VALID_T_TYPES. argType() returns ARG_TYPE_MISSING by default since T_PERCENT is not in any of the typed groups (INTEGER_TYPES, DOUBLE_TYPES, STRING_TYPES).
  • %% special case: untouched — still emits a T_LITERAL_STRING and consumes no argument.
// Previously invalid — now parses as a valid T_PERCENT ArgumentLexeme
// consuming one argument slot with ARG_TYPE_MISSING
sprintf("%4%", $ignored);   // → "%"
sprintf("%l%", $ignored);   // → "%"
sprintf("%+5.5%", $ignored); // → "%"

// Still handled as the literal special case (no argument consumed)
sprintf("%%");              // → "%"

Copilot AI linked an issue Apr 22, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add handling for type % in printf cases Add T_PERCENT type to handle %4%-style format specifiers Apr 22, 2026
Copilot AI requested a review from donatj April 22, 2026 15:07
@donatj donatj marked this pull request as ready for review April 22, 2026 15:08
Copilot AI review requested due to automatic review settings April 22, 2026 15:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in VALID_T_TYPES so 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.

@donatj donatj merged commit cdbc40a into master Apr 22, 2026
21 checks passed
@donatj donatj deleted the copilot/handle-type-percent-cases branch April 22, 2026 15:43
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.

Handle type % in cases other than %%

3 participants