Skip to content

Feature/parser refactor phase2#70

Merged
niden merged 10 commits intophalcon:masterfrom
niden-code:feature/parser-refactor-phase2
Apr 13, 2026
Merged

Feature/parser refactor phase2#70
niden merged 10 commits intophalcon:masterfrom
niden-code:feature/parser-refactor-phase2

Conversation

@niden
Copy link
Copy Markdown
Member

@niden niden commented Apr 13, 2026

Volt Parser Refactor — Phase 2

Refactors Phalcon\Volt\Parser\Parser to be stateless and reusable across multiple parse calls.

Changes

src/Parser/Parser.php

  • Removed private ?Token $token instance property - $token is now a local variable inside parse()
  • Renamed parseView(string $templatePath) to parse(string $code, string $templatePath = 'eval code'): array, where $templatePath defaults to 'eval code' to match the original C implementation behavior (used only in error messages, never affects the AST)
  • Added setDebug(bool): static and setDebugFile(string): static fluent setters replacing direct property access via Reflection
  • Replaced switch with match for opcode dispatch
  • Extracted all complex opcode handlers into focused private methods (handleIf, handleFor, handleBlock, handleMacro, handleSwitch, handleCase, handleDefault, handleExtends, handleRawFragment, handleSet, handleOpenEdelimiter, handleRaw, handleEndraw, handleElseif, handleEndif, handleEndfor, handleEndblock, handleEndmacro, handleEndswitch, handleUnknownOpcode)
  • Simplified parseWithToken() to use $token->opcode directly, removing the redundant int $opcode parameter - aligning with PHQL's makeParserToken pattern
  • Inlined the handleDefault token relabelling (the one genuine case where the opcode differs from the token's own opcode)

src/Compiler.php

  • Updated both call sites to use the new stateless API: new Parser() and ->parse($viewCode, $path) instead of new Parser($viewCode) and ->parseView($path)

Updated all tests

@niden niden requested a review from Jeckerson April 13, 2026 20:56
@niden niden self-assigned this Apr 13, 2026
@niden niden added the enhancement New feature or request label Apr 13, 2026
@niden niden added this to Phalcon v6 Apr 13, 2026
@github-project-automation github-project-automation bot moved this to In progress in Phalcon v6 Apr 13, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 95.98662% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.78%. Comparing base (75111d6) to head (86297a2).
⚠️ Report is 12 commits behind head on master.

Files with missing lines Patch % Lines
src/Parser/Parser.php 95.38% 12 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master      #70      +/-   ##
============================================
- Coverage     85.93%   85.78%   -0.16%     
+ Complexity     4551     4482      -69     
============================================
  Files             9        9              
  Lines          6564     6491      -73     
============================================
- Hits           5641     5568      -73     
  Misses          923      923              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@niden niden merged commit bf086a5 into phalcon:master Apr 13, 2026
13 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Implemented in Phalcon v6 Apr 13, 2026
@niden niden deleted the feature/parser-refactor-phase2 branch April 13, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Implemented

Development

Successfully merging this pull request may close these issues.

2 participants