Skip to content

Commit

Permalink
add php syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
vanyauhalin committed Dec 5, 2024
1 parent fa952e3 commit 7b39b42
Show file tree
Hide file tree
Showing 8 changed files with 433 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"**/fixtures/json-*.js": "javascript",
"**/fixtures/makefile-*": "makefile",
"**/fixtures/makefile-*.js": "javascript",
"**/fixtures/php-*": "php",
"**/fixtures/php-*.js": "javascript",
"**/fixtures/py-*": "python",
"**/fixtures/py-*.js": "javascript",
"**/fixtures/rb-*": "ruby",
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Moondust is crafted to reduce eye strain, allowing to focus on code. It challeng

For a more in-depth discussion on the issues associated with the conventional approach to syntax highlighting, recommend reading the articles [A case against syntax highlighting] and [Syntax highlighting is a waste of an information channel].

Moondust is tailored for each syntax individually. At present, it supports [CSS], [Dockerfile], [fish], [Go], [Go Module], [Go Sum], [HTML], [INI], [JavaScript], [JSON], [JSON with Comments], [JSON Lines], [JSX], [Makefile], [Python], [Ruby], [Rust], [Shell Script], [SQL], [Swift], [TOML], [TypeScript], [TSX], and [YAML].
Moondust is tailored for each syntax individually. At present, it supports [CSS], [Dockerfile], [fish], [Go], [Go Module], [Go Sum], [HTML], [INI], [JavaScript], [JSON], [JSON with Comments], [JSON Lines], [JSX], [Makefile], [PHP], [Python], [Ruby], [Rust], [Shell Script], [SQL], [Swift], [TOML], [TypeScript], [TSX], and [YAML].

In the [initial phase], Moondust was primarily a modification of the [GitHub Theme]. I owe a great deal of gratitude to the Primer team for their work.

Expand Down Expand Up @@ -51,6 +51,7 @@ A special shout-out goes to the entire community that focuses on creating minima
[JSON Lines]: https://moondustthe.me/#jsonl
[JSX]: https://moondustthe.me/#jsx
[Makefile]: https://moondustthe.me/#makefile
[PHP]: https://moondustthe.me/#php
[Python]: https://moondustthe.me/#py
[Ruby]: https://moondustthe.me/#rb
[Rust]: https://moondustthe.me/#rs
Expand Down
137 changes: 137 additions & 0 deletions fixtures/php-00
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!

<?php

// c
# c
/* c */

include "s"
include 's'
include `s`

;

"s"
's'
`s`

"/s{5}/"
'/s{5}/'

<<<EOD
s
EOD

<<<'EOD'
s
EOD

true
false

0
0.0
0b0
0x0
0o0

$a

$a+$a
$a+=$a
$a>$a
$a~$a
$a++
$a??$a
$a->a
...$a
?$a:$a
$a.$a

&&

[$a,$a]
{$a=>$a}

a:
goto a

continue
declare
default
die
do
else
elseif
enddeclare
endfor
endforeach
endif
endswitch
endwhile
exit
for
foreach
if
return
while
yield
yield from

@$a

use a as a;
use a {
insteadof a;
}

if ($a instanceof a) {}

switch ($a) {
case $a:
break
}

try {
throw
} catch () {
} finally {}

match () {
200 => $a,
default => $a
}

enum a {
case a
}

function a(?int $a, &$a, ...$a): never {}
fn() => $a
a()
array(a)

class a extends {}
class a implements {}

class a {
public $a
}

abstract class a {}
final class a {}

new a()

$a::class

trait a {}
namespace a {}
interface a {}

clone $a
print $a
echo $a

?>
137 changes: 137 additions & 0 deletions fixtures/php-00.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
c0("#!")

p0("<?php")

c0("// c")
c0("# c")
c0("/* c */")

p0('include "'), p1("s"), p0('"')
p0("include '"), p1("s"), p0("'")
p0("include `"), p1("s"), p0("`")

p0(";")

s0('"'), s1("s"), s0('"')
s0("'"), s1("s"), s0("'")
s0("`"), s1("s"), s0("`")

s0('"/'), s1("s{5}"), s0('/"')
s0("'/"), s1("s{5}"), s0("/'")

s0("<<<EOD")
s1("s")
s0("EOD")

s0("<<<"), s1("'"), s0("EOD"), s1("'")
s1("s")
s0("EOD")

p1("true")
p1("false")

p1("0")
p1("0"), p0("."), p1("0")
p1("0b0")
p1("0x0")
p1("0o0")

p0("$"), p1("a")

p0("$"), p1("a"), p0("+$"), p1("a")
p0("$"), p1("a"), p0("+=$"), p1("a")
p0("$"), p1("a"), p0(">$"), p1("a")
p0("$"), p1("a"), p0("~$"), p1("a")
p0("$"), p1("a"), p0("++")
p0("$"), p1("a"), p0("??$"), p1("a")
p0("$"), p1("a"), p0("->"), p1("a")
p0("...$"), p1("a")
p0("?$"), p1("a"), p0(":$"), p1("a")
p0("$"), p1("a"), p0(".$"), p1("a")

p0("&&")

p0("[$"), p1("a"), p0(",$"), p1("a"), p0("]")
p0("{$"), p1("a"), p0("=>$"), p1("a"), p0("}")

p1("a:")
p0("goto"), p1("a")

p0("continue")
p0("declare")
p0("default")
p0("die")
p0("do")
p0("else")
p0("elseif")
p0("enddeclare")
p0("endfor")
p0("endforeach")
p0("endif")
p0("endswitch")
p0("endwhile")
p0("exit")
p0("for")
p0("foreach")
p0("if")
p0("return")
p0("while")
p0("yield")
p0("yield from")

p0("@$"), p1("a")

p0("use"), p1("a"), p0("as"), p1("a"), p0(";")
p0("use"), p1("a"), p0("{")
p0("insteadof"), p1("a"), p0(";")
p0("}")

p0("if ($"), p1("a"), p0("instanceof"), p1("a"), p0(") {}")

p0("switch ($"), p1("a"), p0(") {")
p0("case $"), p1("a"), p0(":")
p0("break")
p0("}")

p0("try {")
p0("throw")
p0("} catch () {")
p0("} finally {}")

p0("match () {")
p1("200"), p0("=> $"), p1("a"), p0(",")
p0("default => $"), p1("a")
p0("}")

p0("enum"), p1("a"), p0("{")
p0("case"), p1("a")
p0("}")

p0("function"), p1("a"), p0("(?int $"), p1("a"), p0(", &$"), p1("a"), p0(", ...$"), p1("a"), p0("): never {}")
p0("fn() => $"), p1("a")
p1("a"), p0("()")
p1("array"), p0("("), p1("a"), p0(")")

p0("class"), p1("a"), p0("extends {}")
p0("class"), p1("a"), p0("implements {}")

p0("class"), p1("a"), p0("{")
p0("public $"), p1("a")
p0("}")

p0("abstract class"), p1("a"), p0("{}")
p0("final class"), p1("a"), p0("{}")

p0("new"), p1("a"), p0("()")

p0("$"), p1("a"), p0("::"), p1("class")

p0("trait"), p1("a"), p0("{}")
p0("namespace"), p1("a"), p0("{}")
p0("interface"), p1("a"), p0("{}")

p0("clone $"), p1("a")
p0("print $"), p1("a")
p0("echo $"), p1("a")

p0("?>")
9 changes: 9 additions & 0 deletions fixtures/php-01
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

// PHP grammar has no rule for the colon after the label.
a:

// PHP grammar has no rule for quotes around the label in the nowdoc.
<<<'EOD'
s
EOD
8 changes: 8 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,14 @@ function configs() {
"https://github.com/microsoft/vscode/blob/1.87.0/extensions/make/syntaxes/make.tmLanguage.json/",
],
},
{
id: "php",
scope: "text.html.php",
files: [
"https://github.com/microsoft/vscode/blob/1.95.3/extensions/php/syntaxes/html.tmLanguage.json/",
"https://github.com/microsoft/vscode/blob/1.95.3/extensions/php/syntaxes/php.tmLanguage.json/",
],
},
{
id: "py",
scope: "source.python",
Expand Down
Loading

0 comments on commit 7b39b42

Please sign in to comment.