Add support for l (long) length modifier#59
Merged
Conversation
Agent-Logs-Url: https://github.com/donatj/printf-parser/sessions/ca89d5a6-bb00-475f-a460-078c6341c911 Co-authored-by: donatj <133747+donatj@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add support for long modifier in argument parsing
Add support for Apr 21, 2026
l (long) length modifier
Owner
|
@copilot Can we change the serialization to just |
Agent-Logs-Url: https://github.com/donatj/printf-parser/sessions/25ed9d91-e30e-4adb-9e17-9a3d0eb9240d Co-authored-by: donatj <133747+donatj@users.noreply.github.com>
Contributor
Author
Contributor
There was a problem hiding this comment.
Pull request overview
Adds first-class parsing/printing support for the l (long) length modifier in printf-format argument lexemes, so formats like %ld, %ls, and %10lf no longer produce invalid lexemes and can round-trip through parse → print.
Changes:
- Extend
ArgumentLexemewith alongModifierflag and accessor. - Update
Parser::lexSprintfto recognize and consumelimmediately before the type specifier. - Update
Printerto emitlwhen present; extend integration tests to cover valid/invalidlcases.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/Integration/ParserTest.php | Serializes and asserts l-modifier behavior; adds new parse/print cases including %lls invalid handling. |
| src/Printer.php | Emits l before the type character when the parsed lexeme indicates the modifier. |
| src/Parser.php | Detects l just before type and stores it on the emitted ArgumentLexeme. |
| src/ArgumentLexeme.php | Adds longModifier state + getLongModifier() to preserve modifier for round-trip fidelity. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
donatj
approved these changes
Apr 21, 2026
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 parses but ignores the
llength modifier (e.g.%ld,%ls,%10lf). The parser did not recognise it, causing these format strings to produce invalid lexemes.Changes
ArgumentLexeme— new$longModifierbool property (constructor param defaulting tofalse), exposed viagetLongModifier(): boolParser— detectslimmediately before the type specifier inlexSprintf; consumed and stored as the long modifier flag. A barelwith no valid type following (e.g.%lls) still yields an invalid lexemePrinter— emitslbefore the type character whengetLongModifier()is true, preserving round-trip fidelity|long:1when present; new cases cover%ld,%ls,%lf,%10lf,%.5lf,%10.5lf,%1$ld,%-10ld, and the invalid%llsExample