Skip to content

Commit

Permalink
[PHP] Add support for named arguments
Browse files Browse the repository at this point in the history
https://wiki.php.net/rfc/named_params

Signed-off-by: Jack Cherng <jfcherng@gmail.com>
  • Loading branch information
jfcherng committed Jul 15, 2020
1 parent 1e88b97 commit 43c8cd3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
18 changes: 16 additions & 2 deletions PHP/PHP Source.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,13 @@ contexts:
- match: \(
scope: punctuation.section.group.begin.php
set:
- meta_scope: meta.attribute.php meta.group.php
- meta_scope: meta.attribute.php meta.function-call.php meta.group.php
- match: \)
scope: punctuation.section.group.end.php
scope: meta.function-call.php meta.group.php punctuation.section.group.end.php
pop: true
- match: ','
scope: punctuation.separator.php
- include: function-call-named-parameters
- include: expressions
- match: ''
pop: true
Expand Down Expand Up @@ -1165,7 +1168,18 @@ contexts:
set: after-function-call
- match: ','
scope: punctuation.separator.php
- include: function-call-named-parameters
- include: expressions
function-call-named-parameters:
# https://wiki.php.net/rfc/named_params
- match: ({{identifier}})\s*(:)(?!:)
captures:
1: variable.parameter.named.php
2: punctuation.definition.variable.php
push:
- include: expressions
- match: ''
pop: true
heredoc:
- match: (?=<<<\s*'?({{identifier}})'?\s*$)
push:
Expand Down
16 changes: 16 additions & 0 deletions PHP/syntax_test_php.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,17 @@ public function foo(@@ExampleAttribute \Foo\Bar $bar) { }
// ^^^^^^^^^^^^^^^^ meta.path
// ^^^^^^^^ meta.path
// ^^^^ variable.parameter

@@Route("/api/posts/{id}", methods: ["GET", "HEAD"])
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute
// ^^ punctuation.definition.attribute
// ^^^^^ meta.path
// ^ punctuation.section.group.begin
// ^ punctuation.separator
// ^^^^^^^ variable.parameter.named
// ^ punctuation.definition.variable
// ^ punctuation.section.group.end
public function show(int $id) { }
}

$object = new @@ExampleAttribute class () { };
Expand Down Expand Up @@ -842,6 +853,11 @@ interface MyInter2 extends \MyNamespace\Foo {
//^^^^ support.function.var - variable.function
// ^^^^^^ meta.group

array_slice($array, $offset, $length, preserve_keys: true);
// ^^^^^^^^^^^^^ variable.parameter.named
// ^ punctuation.definition.variable
// ^^^^ constant.language

$test = new Test1;
// ^ keyword.other.new.php
// ^^^^^ meta.path
Expand Down

0 comments on commit 43c8cd3

Please sign in to comment.