From fcf948243d4968fb8a7cd2603159561447604d74 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 25 Apr 2021 14:08:19 +0200 Subject: [PATCH 1/2] [PHP] Fix string interpolation --- PHP/PHP.sublime-syntax | 58 ++++++++++++++++++++++++----------- PHP/tests/syntax_test_php.php | 18 ++++++++--- 2 files changed, 53 insertions(+), 23 deletions(-) diff --git a/PHP/PHP.sublime-syntax b/PHP/PHP.sublime-syntax index 213a95ed4f..a369d25e17 100644 --- a/PHP/PHP.sublime-syntax +++ b/PHP/PHP.sublime-syntax @@ -21,42 +21,64 @@ first_line_match: '^(#!.*[^-]php[0-9]?|<\?php)\b' contexts: prototype: - meta_prepend: true - - include: php-tag-start + - include: php-tags tag-attribute-value-content: - meta_prepend: true - - include: php-tag-start + - include: php-interpolations strings-common-content: - meta_prepend: true - - include: php-tag-start + - include: php-interpolations ###[ PHP TAGS ]############################################################### - php-tag-start: + php-interpolations: - match: <\?(?i:php|=)?(?![^?]*\?>) scope: punctuation.section.embedded.begin.php - push: - - meta_scope: meta.embedded.block.php - - meta_content_scope: source.php.embedded.html - - include: php-end-tag-pop - - include: scope:source.php - apply_prototype: true + push: php-interpolation-block - match: <\?(?i:php|=)? scope: punctuation.section.embedded.begin.php - push: - - meta_scope: meta.embedded.line.php - - meta_content_scope: source.php.embedded.html - - include: php-end-tag-pop - - include: scope:source.php - apply_prototype: true - - php-end-tag-pop: + push: php-interpolation-line + + php-interpolation-block: + - clear_scopes: 1 + - meta_scope: meta.interpolation.html meta.embedded.block.php + - meta_content_scope: source.php.embedded.html + - include: php-tag-content + + php-interpolation-line: + - clear_scopes: 1 + - meta_scope: meta.interpolation.html meta.embedded.line.php + - meta_content_scope: source.php.embedded.html + - include: php-tag-content + + php-tags: + - match: <\?(?i:php|=)?(?![^?]*\?>) + scope: punctuation.section.embedded.begin.php + push: php-tag-block + - match: <\?(?i:php|=)? + scope: punctuation.section.embedded.begin.php + push: php-tag-line + + php-tag-block: + - meta_scope: meta.embedded.block.php + - meta_content_scope: source.php.embedded.html + - include: php-tag-content + + php-tag-line: + - meta_scope: meta.embedded.line.php + - meta_content_scope: source.php.embedded.html + - include: php-tag-content + + php-tag-content: - match: (\?>)(\s*\n)? captures: 1: punctuation.section.embedded.end.php 2: meta.html-newline-after-php.php pop: 1 + - include: scope:source.php + apply_prototype: true ###[ EMBEDDED LANGUAGES ]##################################################### diff --git a/PHP/tests/syntax_test_php.php b/PHP/tests/syntax_test_php.php index 6c9880107e..5061d03ba2 100644 --- a/PHP/tests/syntax_test_php.php +++ b/PHP/tests/syntax_test_php.php @@ -1982,7 +1982,12 @@ public function __test() // ^^^^^^^^^^^^^^^^^^^^^ entity.other.attribute-name // ^^^ punctuation.section.embedded.begin // ^^ punctuation.section.embedded.end -// ^^^^^^^^^^^^^^^^ string.unquoted +// ^^ meta.string.html - meta.interpolation +// ^^^^^^^^^^ meta.string.html meta.interpolation.html meta.embedded.line.php +// ^^^^ meta.string.html - meta.interpolation +// ^^ string.unquoted.html +// ^^^^^^^^^^ - string +// ^^^^ string.unquoted.html // ^^ punctuation.section.embedded.begin.php // ^^ punctuation.section.embedded.end.php @@ -2029,12 +2034,15 @@ public function __test()
// ^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute-with-value.class.html +// ^^^^^^ meta.string.html - meta.interpolation +// ^^^^^^^^^^^ meta.string.html meta.interpolation.html meta.embedded.line.php +// ^ meta.string.html - meta.interpolation // ^ punctuation.definition.string.begin.html -// ^^^^^^^^^^^^^^^^^^ string.quoted.double.html -// ^ punctuation.definition.string.end.html -// ^^^^^^^^^^^ meta.embedded.line +// ^^^^^^ string.quoted.double.html +// ^^^^^^^^^^^ - string +// ^ string.quoted.double.html punctuation.definition.string.end.html // ^^^ punctuation.section.embedded.begin - source.php -// ^^^^^^ source.php +// ^^^^^^ source.php.embedded.html // ^^^^ variable.other // ^^ punctuation.section.embedded.end - source.php // ^ punctuation.definition.tag.end.html From 0126456f9cecd2ad985408c6603d997122648dbf Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Sun, 25 Apr 2021 20:13:06 +0200 Subject: [PATCH 2/2] [PHP] Reorganize embedded contexts Context name "tag" seems a bit strange for `<% ... %>`. Thus changing it to `php-embedded`. For string interpolation `php-interpolations` is used. Note: JSP and Rails will follow. --- PHP/CSS (for PHP).sublime-syntax | 40 ++++++++++++------------- PHP/JavaScript (for PHP).sublime-syntax | 40 ++++++++++++------------- PHP/PHP.sublime-syntax | 28 ++++++++--------- 3 files changed, 53 insertions(+), 55 deletions(-) diff --git a/PHP/CSS (for PHP).sublime-syntax b/PHP/CSS (for PHP).sublime-syntax index 6064bd31c3..9527cf66ba 100644 --- a/PHP/CSS (for PHP).sublime-syntax +++ b/PHP/CSS (for PHP).sublime-syntax @@ -1,38 +1,38 @@ %YAML 1.2 --- name: CSS (for PHP) -hidden: true scope: source.css.php version: 2 +hidden: true extends: Packages/CSS/CSS.sublime-syntax contexts: prototype: - meta_prepend: true - - include: php-tag-start + - include: php-embedded - php-tag-start: + php-embedded: - match: <\?(?i:php|=)?(?![^?]*\?>) scope: punctuation.section.embedded.begin.php - push: - - meta_scope: meta.embedded.block.php - - meta_content_scope: source.php.embedded.css - - include: php-end-tag-pop - - include: scope:source.php - apply_prototype: true + push: php-embedded-block - match: <\?(?i:php|=)? scope: punctuation.section.embedded.begin.php - push: - - meta_scope: meta.embedded.line.php - - meta_content_scope: source.php.embedded.css - - include: php-end-tag-pop - - include: scope:source.php - apply_prototype: true + push: php-embedded-line + + php-embedded-block: + - meta_scope: meta.embedded.block.php + - meta_content_scope: source.php.embedded.css + - include: php-embedded-content + + php-embedded-line: + - meta_scope: meta.embedded.line.php + - meta_content_scope: source.php.embedded.css + - include: php-embedded-content - php-end-tag-pop: - - match: (\?>)(\s*\n)? - captures: - 1: punctuation.section.embedded.end.php - 2: meta.css-newline-after-php.php + php-embedded-content: + - match: \?> + scope: punctuation.section.embedded.end.php pop: 1 + - include: scope:source.php + apply_prototype: true diff --git a/PHP/JavaScript (for PHP).sublime-syntax b/PHP/JavaScript (for PHP).sublime-syntax index 079fc95dea..24882e2279 100644 --- a/PHP/JavaScript (for PHP).sublime-syntax +++ b/PHP/JavaScript (for PHP).sublime-syntax @@ -1,38 +1,38 @@ %YAML 1.2 --- name: JavaScript (for PHP) -hidden: true scope: source.js.php version: 2 +hidden: true extends: Packages/JavaScript/JavaScript.sublime-syntax contexts: prototype: - meta_prepend: true - - include: php-tag-start + - include: php-embedded - php-tag-start: + php-embedded: - match: <\?(?i:php|=)?(?![^?]*\?>) scope: punctuation.section.embedded.begin.php - push: - - meta_scope: meta.embedded.block.php - - meta_content_scope: source.php.embedded.css - - include: php-end-tag-pop - - include: scope:source.php - apply_prototype: true + push: php-embedded-block - match: <\?(?i:php|=)? scope: punctuation.section.embedded.begin.php - push: - - meta_scope: meta.embedded.line.php - - meta_content_scope: source.php.embedded.css - - include: php-end-tag-pop - - include: scope:source.php - apply_prototype: true + push: php-embedded-line + + php-embedded-block: + - meta_scope: meta.embedded.block.php + - meta_content_scope: source.php.embedded.js + - include: php-embedded-content + + php-embedded-line: + - meta_scope: meta.embedded.line.php + - meta_content_scope: source.php.embedded.js + - include: php-embedded-content - php-end-tag-pop: - - match: (\?>)(\s*\n)? - captures: - 1: punctuation.section.embedded.end.php - 2: meta.js-newline-after-php.php + php-embedded-content: + - match: \?> + scope: punctuation.section.embedded.end.php pop: 1 + - include: scope:source.php + apply_prototype: true diff --git a/PHP/PHP.sublime-syntax b/PHP/PHP.sublime-syntax index a369d25e17..ceb13a191e 100644 --- a/PHP/PHP.sublime-syntax +++ b/PHP/PHP.sublime-syntax @@ -21,7 +21,7 @@ first_line_match: '^(#!.*[^-]php[0-9]?|<\?php)\b' contexts: prototype: - meta_prepend: true - - include: php-tags + - include: php-embedded tag-attribute-value-content: - meta_prepend: true @@ -45,37 +45,35 @@ contexts: - clear_scopes: 1 - meta_scope: meta.interpolation.html meta.embedded.block.php - meta_content_scope: source.php.embedded.html - - include: php-tag-content + - include: php-embedded-content php-interpolation-line: - clear_scopes: 1 - meta_scope: meta.interpolation.html meta.embedded.line.php - meta_content_scope: source.php.embedded.html - - include: php-tag-content + - include: php-embedded-content - php-tags: + php-embedded: - match: <\?(?i:php|=)?(?![^?]*\?>) scope: punctuation.section.embedded.begin.php - push: php-tag-block + push: php-embedded-block - match: <\?(?i:php|=)? scope: punctuation.section.embedded.begin.php - push: php-tag-line + push: php-embedded-line - php-tag-block: + php-embedded-block: - meta_scope: meta.embedded.block.php - meta_content_scope: source.php.embedded.html - - include: php-tag-content + - include: php-embedded-content - php-tag-line: + php-embedded-line: - meta_scope: meta.embedded.line.php - meta_content_scope: source.php.embedded.html - - include: php-tag-content + - include: php-embedded-content - php-tag-content: - - match: (\?>)(\s*\n)? - captures: - 1: punctuation.section.embedded.end.php - 2: meta.html-newline-after-php.php + php-embedded-content: + - match: \?> + scope: punctuation.section.embedded.end.php pop: 1 - include: scope:source.php apply_prototype: true