Skip to content

Commit c2c2212

Browse files
committed
Fix function argument highlighting in multi-line declarations
1 parent 1720dbc commit c2c2212

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

Syntaxes/PHP.plist

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -421,40 +421,30 @@
421421
</dict>
422422
</dict>
423423
<key>match</key>
424-
<string>(?x)
424+
<string>(?xi)
425425
\s*(array) # Typehint
426426
\s*(&amp;)? # Reference
427-
\s*((\$+)[a-zA-Z_\x{7f}-\x{ff}][a-zA-Z0-9_\x{7f}-\x{ff}]*) # The variable name
427+
\s*((\$+)[a-z_\x{7f}-\x{ff}][a-z0-9_\x{7f}-\x{ff}]*) # The variable name
428428
(?:
429-
\s*(=) # A default value
430-
\s*(?i:
431-
(NULL)
432-
|
433-
(\S.*?)
434-
)?
429+
\s*(?:(=)\s*(?:(null)|((?:\S*?\(\))|(?:\S*?)))) # A default value
435430
)?
436-
\s*(?=,|\)) # A closing parentheses (end of argument list) or a comma
431+
\s*(?=,|\)|$) # A closing parentheses (end of argument list) or a comma
437432
</string>
438433
<key>name</key>
439434
<string>meta.function.argument.array.php</string>
440435
</dict>
441436
<dict>
442437
<key>begin</key>
443-
<string>(?i)(?=\\?[a-z_])</string>
438+
<string>(?i)(?=[a-z_0-9\\]*[a-z_][a-z_0-9]*\s*&amp;?\s*\$)</string>
444439
<key>end</key>
445-
<string>(?x)
446-
\s*([A-Za-z_][A-Za-z_0-9]*) # Typehinted class name
440+
<string>(?xi)
441+
\s*([a-z_][a-z_0-9]*) # Typehinted class name
447442
\s*(&amp;)? # Reference
448-
\s*((\$+)[a-zA-Z_\x{7f}-\x{ff}][a-zA-Z0-9_\x{7f}-\x{ff}]*) # The variable name
443+
\s*((\$+)[a-z_\x{7f}-\x{ff}][a-z0-9_\x{7f}-\x{ff}]*) # The variable name
449444
(?:
450-
\s*(=) # A default value
451-
\s*(?i:
452-
(NULL)
453-
|
454-
(\S.*?)
455-
)?
445+
\s*(?:(=)\s*(?:(null)|((?:\S*?\(\))|(?:\S*?)))) # A default value
456446
)?
457-
\s*(?=,|\)) # A closing parentheses (end of argument list) or a comma
447+
\s*(?=,|\)|$) # A closing parentheses (end of argument list) or a comma
458448
</string>
459449
<key>endCaptures</key>
460450
<dict>

Tests/test-cases.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,5 +479,24 @@ public function __construct(namespace\MyClass $myClass) {
479479
mysql_db_query();
480480
mysql_escape_string();
481481

482+
// Multi-line declarations
483+
function foo(
484+
$asdf,
485+
$name = '',
486+
array $stuff = array()
487+
) {
488+
$blah = 123;
489+
return true;
490+
}
491+
492+
function foo(
493+
$asdf,
494+
$name = '',
495+
array $stuff = array(),
496+
Some_Type $something = null
497+
) {
498+
$blah = 123;
499+
return true;
500+
}
482501

483502
?>

0 commit comments

Comments
 (0)