diff --git a/PHP/PHP Source.sublime-syntax b/PHP/PHP Source.sublime-syntax index e76274e9da0..f2194f75a2b 100644 --- a/PHP/PHP Source.sublime-syntax +++ b/PHP/PHP Source.sublime-syntax @@ -56,7 +56,6 @@ contexts: captures: 1: storage.type.trait.php 2: entity.name.trait.php - - include: attributes - include: typed-property - include: function - match: '^\s*((?!default|else){{identifier}})\s*(:)(?!:)' @@ -112,6 +111,7 @@ contexts: - include: statements expressions: + - include: attributes - include: comments - match: (?i)\b((?:require|include)(?:_once)?)\b\s* captures: @@ -143,6 +143,7 @@ contexts: 1: keyword.control.exception.catch.php push: - meta_scope: meta.catch.php + - include: attributes - include: comments - include: identifier-parts-as-path - match: '(\\)' @@ -355,55 +356,23 @@ contexts: attributes: # https://wiki.php.net/rfc/attributes_v2 - - match: (?=<<(?![<=])) - branch_point: branch-point-attributes - branch: - - is-attributes-branch - - not-attributes-branch - - attributes-in-function-parameter: - # https://wiki.php.net/rfc/attributes_v2 (for function parameter) - - match: (?=<<(?![<=])) - branch_point: branch-point-attributes-in-function-parameter - branch: - - is-attributes-in-function-parameter-branch - - not-attributes-branch - - is-attributes-branch: - - match: '<<(?={{path}})' - scope: punctuation.definition.attribute.begin.php + # https://wiki.php.net/rfc/attribute_amendments + # https://wiki.php.net/rfc/shorter_attribute_syntax + - match: '@@(?=[\\\w])' + scope: punctuation.definition.attribute.php push: - meta_scope: meta.attribute.php - # [>(?=\s*(?:$|[=)\]},;]|\s*\?>) - pop: true - include: class-name - - include: expressions - - match: '' - fail: branch-point-attributes - - is-attributes-in-function-parameter-branch: - - match: '<<(?={{path}})' - scope: punctuation.definition.attribute.begin.php - push: - - meta_scope: meta.attribute.php - - match: '>>' - scope: punctuation.definition.attribute.end.php - pop: 2 # branch successful matched - - match: (?=[<>=)\]},;]|\s*\?>) + - match: \( + scope: punctuation.section.group.begin.php + set: + - meta_scope: meta.attribute.php meta.group.php + - match: \) + scope: punctuation.section.group.end.php + pop: true + - include: expressions + - match: '' pop: true - - include: class-name - - include: expressions - - match: '' - fail: branch-point-attributes-in-function-parameter - - not-attributes-branch: - - match: '<<' - scope: keyword.operator.bitwise.php - pop: true class-builtin: - match: |- @@ -461,6 +430,7 @@ contexts: pop: true use-statement-common: + - include: attributes - include: comments - match: (?i)\bas\b scope: keyword.other.use-as.php @@ -470,6 +440,7 @@ contexts: use-statement-identifier-class-def: - match: '(?={{path}})' push: + - include: attributes - include: comments # We are going to assume the alias is for a class so that the identifier # gets put into the index. This will be incorrect sometimes (because it @@ -478,6 +449,7 @@ contexts: - match: '(?i)\b(as)\b' scope: keyword.other.use-as.php push: + - include: attributes - include: comments - match: '{{identifier}}' scope: entity.name.class.php @@ -514,10 +486,12 @@ contexts: use-statement-identifier-function-def: - match: '(?={{path}})' push: + - include: attributes - include: comments - match: '(?i)\b(as)\b' scope: keyword.other.use-as.php push: + - include: attributes - include: comments - match: '{{identifier}}' scope: entity.name.function.php @@ -581,6 +555,7 @@ contexts: - match: '\{' scope: meta.block.php punctuation.section.block.php set: class-body + - include: attributes - include: comments - match: (?i)(extends)\b\s* captures: @@ -588,6 +563,7 @@ contexts: push: - match: '(?=implements)' pop: true + - include: attributes - include: comments - match: '(?={{path}})' set: @@ -606,6 +582,7 @@ contexts: captures: 1: storage.modifier.implements.php push: + - include: attributes - include: comments - match: '(?={{path}})' push: @@ -625,6 +602,7 @@ contexts: class-body: - meta_content_scope: meta.class.php meta.block.php + - include: attributes - include: comments - match: '\}' scope: meta.class.php meta.block.php punctuation.section.block.php @@ -643,6 +621,7 @@ contexts: - match: '}' scope: punctuation.section.block.php pop: true + - include: attributes - include: comments - match: \b(as)\b scope: keyword.other.use-as.php @@ -660,6 +639,7 @@ contexts: 1: punctuation.separator.namespace.php - match: '' pop: true + - include: attributes - include: comments - include: class-builtin - match: (?={{path}}) @@ -692,6 +672,7 @@ contexts: - match: (?i)(?=(?:\b(?:final|abstract|{{visibility_modifier}}|static)\s+)*\bfunction\b\s*(&\s*)?{{identifier_start}}) push: - meta_content_scope: meta.function.php + - include: attributes - include: comments - match: '(?i)\b(final|abstract|{{visibility_modifier}}|static)\b' scope: storage.modifier.php @@ -757,6 +738,7 @@ contexts: - match: '(?=;|,|\)|\s*\?>)' pop: 2 - include: expressions + - include: attributes - include: comments - match: (?=\S) fail: arrow-function-branch @@ -797,11 +779,11 @@ contexts: # Exit on unexpected content - match: (?=\S) pop: true + - include: attributes - include: comments - match: \b(array|callable|int|string|bool|float|object)\b scope: storage.type.php # Class name type hint - - include: attributes-in-function-parameter - include: type-hint - match: '\.\.\.' scope: keyword.operator.spread.php @@ -822,6 +804,7 @@ contexts: function-use: - meta_content_scope: meta.function.closure.use.php + - include: attributes - include: comments - match: '\)' scope: punctuation.section.group.end.php @@ -1106,7 +1089,7 @@ contexts: 1: punctuation.separator.namespace.php - match: |- (\\)?\b(?x: - T_ABSTRACT | T_AND_EQUAL | T_ARRAY | T_ARRAY_CAST | T_AS | T_BAD_CHARACTER | T_BOOLEAN_AND | T_BOOLEAN_OR | + T_ABSTRACT | T_AND_EQUAL | T_ARRAY | T_ARRAY_CAST | T_AS | T_ATTRIBUTE | T_BAD_CHARACTER | T_BOOLEAN_AND | T_BOOLEAN_OR | T_BOOL_CAST | T_BREAK | T_CASE | T_CATCH | T_CHARACTER | T_CLASS | T_CLASS_C | T_CLONE | T_CLOSE_TAG | T_COMMENT | T_CONCAT_EQUAL | T_CONST | T_CONSTANT_ENCAPSED_STRING | T_CONTINUE | T_CURLY_OPEN | T_DEC | T_DECLARE | T_DEFAULT | T_DIR | T_DIV_EQUAL | T_DNUMBER | T_DO | T_DOC_COMMENT | T_DOLLAR_OPEN_CURLY_BRACES | diff --git a/PHP/syntax_test_php.php b/PHP/syntax_test_php.php index 86ca6a72218..cd7f532bdbf 100644 --- a/PHP/syntax_test_php.php +++ b/PHP/syntax_test_php.php @@ -270,148 +270,117 @@ function foo(?stinrg ...$args) {} // ^ punctuation.section.brackets.begin.php // ^ punctuation.section.brackets.end.php -$not_attribute = 2 << 1; -// ^^ keyword.operator.bitwise -$not_attribute = 2<<1; -// ^^ keyword.operator.bitwise -$not_attribute = 1<<5>>2; -// ^^ keyword.operator.bitwise -// ^^ keyword.operator.bitwise -$not_attribute = CONST_A <> CONST_C; -// ^^^^^^^ constant -// ^^ keyword.operator.bitwise -// ^^^^^^^ constant -// ^^ keyword.operator.bitwise -$not_attribute = CONST_A <> $var_c; -// ^^^^^^^ constant -// ^^ keyword.operator.bitwise -// ^^^^^^^ constant -// ^^ keyword.operator.bitwise - -<> -// ^^^^^^^^^^^^^^^^ meta.attribute -// <- punctuation.definition.attribute.begin +@@@@@@@@@@ExampleAttribute +// <- keyword.operator.error-control +//^^^^^^ keyword.operator.error-control +// ^^ punctuation.definition.attribute +// ^^^^^^^^^^^^^^^^ meta.path +@@WithoutArgument +// ^^^^^^^^^^^^^^ meta.attribute +// <- punctuation.definition.attribute // ^^^^^^^^^^^^^^ meta.path -// ^^ punctuation.definition.attribute.end -<> -// ^^^^^^^^^^^^^^^^^^ meta.attribute -// <- punctuation.definition.attribute.begin +@@WithoutArgument() +// ^^^^^^^^^^^^^^^^ meta.attribute +// <- punctuation.definition.attribute // ^^^^^^^^^^^^^^ meta.path -// ^^ punctuation.definition.attribute.end -<> -// ^^^^^^^^^^^^^^^^^^ meta.attribute -// <- punctuation.definition.attribute.begin +@@SingleArgument(0) +// ^^^^^^^^^^^^^^^^ meta.attribute +// <- punctuation.definition.attribute // ^^^^^^^^^^^^^ meta.path -// ^^ punctuation.definition.attribute.end -<> -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute -// <- punctuation.definition.attribute.begin +@@FewArguments('Hello', 'World') +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute +// <- punctuation.definition.attribute // ^^^^^^^^^^^ meta.path // ^^^^^^^ string.quoted // ^^^^^^^ string.quoted -// ^^ punctuation.definition.attribute.end -<> -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute -// <- punctuation.definition.attribute.begin +@@FewArguments(PDO::class, PHP_VERSION_ID) +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute +// <- punctuation.definition.attribute // ^^^^^^^^^^^ meta.path // ^^^ support.class // ^^ punctuation.accessor // ^^^^^^^^^^^^^^ support.constant -// ^^ punctuation.definition.attribute.end -<<\My\Attributes\FewArguments("foo", "bar")>> -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute -// <- punctuation.definition.attribute.begin +@@\My\Attributes\FewArguments("foo", "bar") +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute +// <- punctuation.definition.attribute // ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.path // ^^^^^ string.quoted // ^^^^^ string.quoted -// ^^ punctuation.definition.attribute.end /** docblock */ // <- comment.block -<> 1, 4 << 1)>> -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute -// <- punctuation.definition.attribute.begin -// ^^ keyword.operator.bitwise -// ^^ keyword.operator.bitwise -// ^^ punctuation.definition.attribute.end -<> 1)>> -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute -// <- punctuation.definition.attribute.begin +@@BitShiftExample(4 >> 1, 4 << 1) +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute +// <- punctuation.definition.attribute // ^^ keyword.operator.bitwise // ^^ keyword.operator.bitwise -// ^^ punctuation.definition.attribute.end function foo() {} // <- storage.type.function -<><> <> -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute -// ^ - meta.attribute -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute -// <- punctuation.definition.attribute.begin -// ^^ punctuation.definition.attribute.end -// ^^ punctuation.definition.attribute.begin -// ^^ punctuation.definition.attribute.end -// ^^ punctuation.definition.attribute.begin -// ^^ punctuation.definition.attribute.end +@@JoinTable( +// <- punctuation.definition.attribute +//^^^^^^^^^ support.class + "User_Group", +// ^^^^^^^^^^^^ string.quoted.double + @@JoinColumn("User_id", "id"), +// ^^ punctuation.definition.attribute +// ^^^^^^^^^ support.class + @@JoinColumn("Group_id", "id"), +// ^^ punctuation.definition.attribute +// ^^^^^^^^^ support.class +) +// ^ - meta.attribute function foo() {} // <- storage.type.function -<> -// ^^^^^^^^^^^^^^^^^ meta.attribute -// <- punctuation.definition.attribute.begin +@@ExampleAttribute +// ^^^^^^^^^^^^^^^ meta.attribute +// <- punctuation.definition.attribute // ^^^^^^^^^^^^^^^ meta.path -// ^^ punctuation.definition.attribute.end class Foo { - <> -// ^^^^^^^^^^^^^^^^^^^^ meta.attribute -// ^^ punctuation.definition.attribute.begin + @@ExampleAttribute +// ^^^^^^^^^^^^^^^^^^ meta.attribute +// ^^ punctuation.definition.attribute // ^^^^^^^^^^^^^^^^ meta.path -// ^^ punctuation.definition.attribute.end public const FOO = 'foo'; - <> -// ^^^^^^^^^^^^^^^^^^^^ meta.attribute -// ^^ punctuation.definition.attribute.begin + @@ExampleAttribute +// ^^^^^^^^^^^^^^^^^^ meta.attribute +// ^^ punctuation.definition.attribute // ^^^^^^^^^^^^^^^^ meta.path -// ^^ punctuation.definition.attribute.end public $x; - <> // comment -// ^^^^^^^^^^^^^^^^^^^^ meta.attribute -// ^^ punctuation.definition.attribute.begin + @@ExampleAttribute // comment +// ^^^^^^^^^^^^^^^^^^ meta.attribute +// ^^ punctuation.definition.attribute // ^^^^^^^^^^^^^^^^ meta.path -// ^^ punctuation.definition.attribute.end // ^^^^^^^^^^ comment - public function foo(<> \Foo\Bar $bar) { } -// ^^^^^^^^^^^^^^^^^^^^ meta.attribute -// ^^ punctuation.definition.attribute.begin + public function foo(@@ExampleAttribute \Foo\Bar $bar) { } +// ^^^^^^^^^^^^^^^^^^ meta.attribute +// ^^ punctuation.definition.attribute // ^^^^^^^^^^^^^^^^ meta.path -// ^^ punctuation.definition.attribute.end -// ^^^^^^^^ meta.path -// ^^^^ variable.parameter +// ^^^^^^^^ meta.path +// ^^^^ variable.parameter } -$object = new <> class () { }; -// ^^^^^^^^^^^^^^^^^^^^ meta.attribute -// ^^ punctuation.definition.attribute.begin +$object = new @@ExampleAttribute class () { }; +// ^^^^^^^^^^^^^^^^^^ meta.attribute +// ^^ punctuation.definition.attribute // ^^^^^^^^^^^^^^^^ meta.path -// ^^ punctuation.definition.attribute.end -// ^^^^^ storage.type +// ^^^^^ storage.type -$f2 = <> function () { }; -// ^^^^^^^^^^^^^^^^^^^^ meta.attribute -// ^^ punctuation.definition.attribute.begin +$f2 = @@ExampleAttribute function () { }; +// ^^^^^^^^^^^^^^^^^^ meta.attribute +// ^^ punctuation.definition.attribute // ^^^^^^^^^^^^^^^^ meta.path -// ^^ punctuation.definition.attribute.end -// ^^^^^^^^ storage.type +// ^^^^^^^^ storage.type -$f3 = <> fn () => 1; -// ^^^^^^^^^^^^^^^^^^^^ meta.attribute -// ^^ punctuation.definition.attribute.begin +$f3 = @@ExampleAttribute fn () => 1; +// ^^^^^^^^^^^^^^^^^^ meta.attribute +// ^^ punctuation.definition.attribute // ^^^^^^^^^^^^^^^^ meta.path -// ^^ punctuation.definition.attribute.end -// ^^ storage.type -// ^^ punctuation.definition.arrow-function +// ^^ storage.type +// ^^ punctuation.definition.arrow-function /** No longer a phpdoc comment since no leading *