Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHP] Fix string interpolations #8

Merged
merged 2 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions PHP/CSS (for PHP).sublime-syntax
Original file line number Diff line number Diff line change
@@ -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
40 changes: 20 additions & 20 deletions PHP/JavaScript (for PHP).sublime-syntax
Original file line number Diff line number Diff line change
@@ -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
64 changes: 42 additions & 22 deletions PHP/PHP.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,62 @@ first_line_match: '^(#!.*[^-]php[0-9]?|<\?php)\b'
contexts:
prototype:
- meta_prepend: true
- include: php-tag-start
- include: php-embedded

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:
- match: (\?>)(\s*\n)?
captures:
1: punctuation.section.embedded.end.php
2: meta.html-newline-after-php.php
Copy link
Member

@FichteFoll FichteFoll Apr 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed that this match was removed, too, as I thought it was only done for JS and CSS. The scope is needed for indentation rules and causes the indentation tests to fail.

I can reintroduce it tomorrow if you don't beat me to it. 😉

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't aware about it being used for indentation. Is that something to consider for the other syntaxes, too, then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. I barely spent time on this, but I'm sure just asking @keith-hall would be quicker. 😉

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't aware about it being used for indentation. Is that something to consider for the other syntaxes, too, then?

Yep, though maybe we should tweak the scope a bit to standardize it in a more general form. It's also a good time to add indentation tests for other syntaxes :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least, I've learned why I missed those tests (sublimehq/sublime_text#4113).

It appears PHP's sophisticated indentation rules may be used for other syntaxes as well. Ruby on Rails seems to be a candidate, maybe JSP as well.

Yes, indentation tests are useful, but I often failed to implement them due to ST's limitations, which prevent proper indentation in many situations anyway.

Copy link
Member

@FichteFoll FichteFoll Apr 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in c1b69b4 and 71c32a3.

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-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-embedded-content

php-embedded:
- match: <\?(?i:php|=)?(?![^?]*\?>)
scope: punctuation.section.embedded.begin.php
push: php-embedded-block
- match: <\?(?i:php|=)?
scope: punctuation.section.embedded.begin.php
push: php-embedded-line

php-embedded-block:
- meta_scope: meta.embedded.block.php
- meta_content_scope: source.php.embedded.html
- include: php-embedded-content

php-embedded-line:
- meta_scope: meta.embedded.line.php
- meta_content_scope: source.php.embedded.html
- include: php-embedded-content

php-embedded-content:
- match: \?>
scope: punctuation.section.embedded.end.php
pop: 1
- include: scope:source.php
apply_prototype: true

###[ EMBEDDED LANGUAGES ]#####################################################

Expand Down
18 changes: 13 additions & 5 deletions PHP/tests/syntax_test_php.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -2029,12 +2034,15 @@ public function __test()

<div class="test <?= $foo ?>"></div>
// ^^^^^^^^^^^^^^^^^^^^^^^^ 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
Expand Down