From 43c8cd39e6902650df2b0f4e6c3caab8c9c541d0 Mon Sep 17 00:00:00 2001 From: Jack Cherng Date: Wed, 15 Jul 2020 17:46:11 +0800 Subject: [PATCH] [PHP] Add support for named arguments https://wiki.php.net/rfc/named_params Signed-off-by: Jack Cherng --- PHP/PHP Source.sublime-syntax | 18 ++++++++++++++++-- PHP/syntax_test_php.php | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/PHP/PHP Source.sublime-syntax b/PHP/PHP Source.sublime-syntax index 8d2ecec7d60..c915e764b56 100644 --- a/PHP/PHP Source.sublime-syntax +++ b/PHP/PHP Source.sublime-syntax @@ -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 @@ -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: diff --git a/PHP/syntax_test_php.php b/PHP/syntax_test_php.php index e9bd1cc31e2..66ee11950b1 100644 --- a/PHP/syntax_test_php.php +++ b/PHP/syntax_test_php.php @@ -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 () { }; @@ -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