Skip to content

Add support for l (long) length modifier#59

Merged
donatj merged 3 commits into
masterfrom
copilot/add-support-for-long-modifier
Apr 21, 2026
Merged

Add support for l (long) length modifier#59
donatj merged 3 commits into
masterfrom
copilot/add-support-for-long-modifier

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 21, 2026

PHP parses but ignores the l length modifier (e.g. %ld, %ls, %10lf). The parser did not recognise it, causing these format strings to produce invalid lexemes.

Changes

  • ArgumentLexeme — new $longModifier bool property (constructor param defaulting to false), exposed via getLongModifier(): bool
  • Parser — detects l immediately before the type specifier in lexSprintf; consumed and stored as the long modifier flag. A bare l with no valid type following (e.g. %lls) still yields an invalid lexeme
  • Printer — emits l before the type character when getLongModifier() is true, preserving round-trip fidelity
  • Tests — serialisation updated to append |long:1 when present; new cases cover %ld, %ls, %lf, %10lf, %.5lf, %10.5lf, %1$ld, %-10ld, and the invalid %lls

Example

$parser->parseStr('%10lf');
// ArgumentLexeme: type=f, padWidth=10, longModifier=true

$printer->print($lexemes); // → '%10lf'

Copilot AI linked an issue Apr 21, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add support for long modifier in argument parsing Add support for l (long) length modifier Apr 21, 2026
Copilot AI requested a review from donatj April 21, 2026 21:30
@donatj
Copy link
Copy Markdown
Owner

donatj commented Apr 21, 2026

@copilot Can we change the serialization to just |l instead of |long:1

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 21, 2026

@copilot Can we change the serialization to just |l instead of |long:1

Done in c499fc3 — changed |long:1 to |l throughout the serialization helper and all test expectations.

@donatj donatj marked this pull request as ready for review April 21, 2026 21:34
Copilot AI review requested due to automatic review settings April 21, 2026 21:34
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 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 ArgumentLexeme with a longModifier flag and accessor.
  • Update Parser::lexSprintf to recognize and consume l immediately before the type specifier.
  • Update Printer to emit l when present; extend integration tests to cover valid/invalid l cases.

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.

Comment thread test/Integration/ParserTest.php
@donatj donatj merged commit 946413a into master Apr 21, 2026
21 checks passed
@donatj donatj deleted the copilot/add-support-for-long-modifier branch April 21, 2026 21:54
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.

Add support for 'long' modifier

3 participants