Skip to content

Commit 4f97b82

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

16 files changed

+237
-3
lines changed

components.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

Lines changed: 5 additions & 0 deletions
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

Lines changed: 51 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-gn.html

Lines changed: 24 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy