Skip to content

Commit 4f97b82

Browse files
authoredSep 1, 2021
Added support for GN (#3062)
1 parent 5de8947 commit 4f97b82

16 files changed

+237
-3
lines changed
 

‎components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎components.json

+5
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,11 @@
466466
"require": "c",
467467
"owner": "Golmote"
468468
},
469+
"gn": {
470+
"title": "GN",
471+
"alias": "gni",
472+
"owner": "RunDevelopment"
473+
},
469474
"go": {
470475
"title": "Go",
471476
"require": "clike",

‎components/prism-gn.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// https://gn.googlesource.com/gn/+/refs/heads/main/docs/reference.md#grammar
2+
3+
Prism.languages.gn = {
4+
'comment': {
5+
pattern: /#.*/,
6+
greedy: true
7+
},
8+
'string-literal': {
9+
pattern: /(^|[^\\"])"(?:[^\r\n"\\]|\\.)*"/,
10+
lookbehind: true,
11+
greedy: true,
12+
inside: {
13+
'interpolation': {
14+
pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:\{[\s\S]*?\}|[a-zA-Z_]\w*|0x[a-fA-F0-9]{2})/,
15+
lookbehind: true,
16+
inside: {
17+
'number': /^\$0x[\s\S]{2}$/,
18+
'variable': /^\$\w+$/,
19+
'interpolation-punctuation': {
20+
pattern: /^\$\{|\}$/,
21+
alias: 'punctuation'
22+
},
23+
'expression': {
24+
pattern: /[\s\S]+/,
25+
inside: null // see below
26+
}
27+
}
28+
},
29+
'string': /[\s\S]+/
30+
}
31+
},
32+
33+
'keyword': /\b(?:else|if)\b/,
34+
'boolean': /\b(?:true|false)\b/,
35+
'builtin-function': {
36+
// a few functions get special highlighting to improve readability
37+
pattern: /\b(?:assert|defined|foreach|import|pool|print|template|tool|toolchain)(?=\s*\()/i,
38+
alias: 'keyword'
39+
},
40+
'function': /\b[a-z_]\w*(?=\s*\()/i,
41+
'constant': /\b(?:current_cpu|current_os|current_toolchain|default_toolchain|host_cpu|host_os|root_build_dir|root_gen_dir|root_out_dir|target_cpu|target_gen_dir|target_out_dir|target_os)\b/,
42+
43+
'number': /-?\b\d+\b/,
44+
45+
'operator': /[-+!=<>]=?|&&|\|\|/,
46+
'punctuation': /[(){}[\],.]/
47+
};
48+
49+
Prism.languages.gn['string-literal'].inside['interpolation'].inside['expression'].inside = Prism.languages.gn;
50+
51+
Prism.languages.gni = Prism.languages.gn;

‎components/prism-gn.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/prism-gn.html

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<h2>Full example</h2>
2+
<pre><code># Source: https://gn.googlesource.com/gn/+/main/docs/cross_compiles.md
3+
4+
declare_args() {
5+
# Applies only to toolchains targeting target_cpu.
6+
sysroot = ""
7+
}
8+
9+
config("my_config") {
10+
# Uses current_cpu because compile flags are toolchain-dependent.
11+
if (current_cpu == "arm") {
12+
defines = [ "CPU_IS_32_BIT" ]
13+
} else {
14+
defines = [ "CPU_IS_64_BIT" ]
15+
}
16+
# Compares current_cpu with target_cpu to see whether current_toolchain
17+
# has the same architecture as target_toolchain.
18+
if (sysroot != "" && current_cpu == target_cpu) {
19+
cflags = [
20+
"-isysroot",
21+
sysroot,
22+
]
23+
}
24+
}</code></pre>

‎plugins/autoloader/prism-autoloader.js

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
"xlsx": "excel-formula",
190190
"xls": "excel-formula",
191191
"gamemakerlanguage": "gml",
192+
"gni": "gn",
192193
"hbs": "handlebars",
193194
"hs": "haskell",
194195
"idr": "idris",

‎plugins/autoloader/prism-autoloader.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎plugins/show-language/prism-show-language.js

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@
8989
"gdscript": "GDScript",
9090
"gedcom": "GEDCOM",
9191
"glsl": "GLSL",
92+
"gn": "GN",
93+
"gni": "GN",
9294
"graphql": "GraphQL",
9395
"hbs": "Handlebars",
9496
"hs": "Haskell",

‎plugins/show-language/prism-show-language.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
true false
2+
3+
----------------------------------------------------
4+
5+
[
6+
["boolean", "true"],
7+
["boolean", "false"]
8+
]
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# comment
2+
3+
----------------------------------------------------
4+
5+
[
6+
["comment", "# comment"]
7+
]
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
foo()
2+
3+
----------------------------------------------------
4+
5+
[
6+
["function", "foo"],
7+
["punctuation", "("],
8+
["punctuation", ")"]
9+
]
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
0
2+
123
3+
-123
4+
5+
----------------------------------------------------
6+
7+
[
8+
["number", "0"],
9+
["number", "123"],
10+
["number", "-123"]
11+
]
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
+ +=
2+
- -=
3+
== != < > <= =>
4+
! =
5+
&& ||
6+
7+
----------------------------------------------------
8+
9+
[
10+
["operator", "+"],
11+
["operator", "+="],
12+
13+
["operator", "-"],
14+
["operator", "-="],
15+
16+
["operator", "=="],
17+
["operator", "!="],
18+
["operator", "<"],
19+
["operator", ">"],
20+
["operator", "<="],
21+
["operator", "="],
22+
["operator", ">"],
23+
24+
["operator", "!"],
25+
["operator", "="],
26+
27+
["operator", "&&"],
28+
["operator", "||"]
29+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
( ) [ ] { }
2+
, .
3+
4+
----------------------------------------------------
5+
6+
[
7+
["punctuation", "("],
8+
["punctuation", ")"],
9+
["punctuation", "["],
10+
["punctuation", "]"],
11+
["punctuation", "{"],
12+
["punctuation", "}"],
13+
14+
["punctuation", ","],
15+
["punctuation", "."]
16+
]
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
""
2+
"foo"
3+
".$output_extension"
4+
"$0xFF"
5+
"$var_one/$var_two"
6+
"${var_one}"
7+
"$root_out_dir/lib${_output_name}${_shlib_extension}"
8+
9+
----------------------------------------------------
10+
11+
[
12+
["string-literal", [
13+
["string", "\"\""]
14+
]],
15+
["string-literal", [
16+
["string", "\"foo\""]
17+
]],
18+
["string-literal", [
19+
["string", "\"."],
20+
["interpolation", [
21+
["variable", "$output_extension"]
22+
]],
23+
["string", "\""]
24+
]],
25+
["string-literal", [
26+
["string", "\""],
27+
["interpolation", [
28+
["number", "$0xFF"]
29+
]],
30+
["string", "\""]
31+
]],
32+
["string-literal", [
33+
["string", "\""],
34+
["interpolation", [
35+
["variable", "$var_one"]
36+
]],
37+
["string", "/"],
38+
["interpolation", [
39+
["variable", "$var_two"]
40+
]],
41+
["string", "\""]
42+
]],
43+
["string-literal", [
44+
["string", "\""],
45+
["interpolation", [
46+
["interpolation-punctuation", "${"],
47+
["expression", ["var_one"]],
48+
["interpolation-punctuation", "}"]
49+
]],
50+
["string", "\""]
51+
]],
52+
["string-literal", [
53+
["string", "\""],
54+
["interpolation", [
55+
["variable", "$root_out_dir"]
56+
]],
57+
["string", "/lib"],
58+
["interpolation", [
59+
["interpolation-punctuation", "${"],
60+
["expression", ["_output_name"]],
61+
["interpolation-punctuation", "}"]
62+
]],
63+
["interpolation", [
64+
["interpolation-punctuation", "${"],
65+
["expression", ["_shlib_extension"]],
66+
["interpolation-punctuation", "}"]
67+
]],
68+
["string", "\""]
69+
]]
70+
]

0 commit comments

Comments
 (0)
Please sign in to comment.