Skip to content

feat(php): add Heredoc and Nowdoc syntax support - #5611

Open
Ori Kuttner (OriKuttner) wants to merge 1 commit into
microsoft:mainfrom
OriKuttner:feat/php-heredoc-support
Open

Ori Kuttner (OriKuttner) wants to merge 1 commit into
microsoft:mainfrom
OriKuttner:feat/php-heredoc-support

Conversation

@OriKuttner

Copy link
Copy Markdown

Summary

Adds support for PHP Heredoc (<<<TAG / <<<"TAG") and Nowdoc (<<<'TAG') syntax to the Monarch PHP tokenizer.

Motivation

Previously, PHP was missing Heredoc/Nowdoc tokenization rules (unlike Perl, Ruby, Shell, and PowerShell which already have Heredoc support in Monaco).
When a Heredoc block contains double quotes (e.g. HTML attributes like <th scope="col"> or quotes in Hebrew/English text), the tokenizer incorrectly interpreted them as standard double-quoted string literals, causing subsequent code across hundreds of lines to lose syntax coloring.

Changes

  • Added regex rules for <<<TAG, <<<"TAG", and <<<'TAG' in phpRoot.
  • Added phpHeredoc and phpNowdoc states supporting:
    • Dynamic closing delimiter matching ($1==$S2) at line start with optional indentation (PHP 7.3+) and trailing delimiters (;, ,, )).
    • Variable interpolation inside Heredoc.
    • Literal string handling in Nowdoc.
  • Added tokenizer unit tests in php.test.ts.

@OriKuttner

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

This branch has not been deployed

No deployments
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.

1 participant