-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix string interpolation syntax highlighting (#90)
Previously, we'd highlight "{$x->y->z}" incorrectly, and "$x[foo]" would look like it wasn't accessing the key in $x. Highlight the whole interpolation to make this more explicit.
- Loading branch information
Showing
2 changed files
with
42 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// See https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing | ||
function double_quoted(): void { | ||
// Escape characters. | ||
$x = "world \n \t \\"; | ||
|
||
// Octal/hex. | ||
$x = "world \07 \xFF" | ||
|
||
// Simple interpolation. | ||
$y = "hello $x"; | ||
|
||
// We can do a single array access, but not nested. | ||
$y = "hello $x[0]"; | ||
$y = "hello $x[0][1]"; // literal "[1]" | ||
|
||
// Similarly with properties, we can only access the first. | ||
$y = "hello $x->foo"; | ||
$y = "hello $x->foo->bar"; // literal "->bar" | ||
|
||
// In {} we can use more complex expressions. | ||
$y = "hello {$x->y->z[0][1] + 2}"; | ||
|
||
// Just accessing $x here due to the space. | ||
$y = "hello { $x + 1}"; | ||
} | ||
|
||
function single_quoted(): void { | ||
// This is a literal \ and n. | ||
$x = 'foo\n bar'; | ||
|
||
// No interpolation here. | ||
$x = 'foo $x'; | ||
} |