Skip to content

Commit

Permalink
Added support for GN (#3062)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Sep 1, 2021
1 parent 5de8947 commit 4f97b82
Show file tree
Hide file tree
Showing 16 changed files with 237 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@
"require": "c",
"owner": "Golmote"
},
"gn": {
"title": "GN",
"alias": "gni",
"owner": "RunDevelopment"
},
"go": {
"title": "Go",
"require": "clike",
Expand Down
51 changes: 51 additions & 0 deletions components/prism-gn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// https://gn.googlesource.com/gn/+/refs/heads/main/docs/reference.md#grammar

Prism.languages.gn = {
'comment': {
pattern: /#.*/,
greedy: true
},
'string-literal': {
pattern: /(^|[^\\"])"(?:[^\r\n"\\]|\\.)*"/,
lookbehind: true,
greedy: true,
inside: {
'interpolation': {
pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:\{[\s\S]*?\}|[a-zA-Z_]\w*|0x[a-fA-F0-9]{2})/,
lookbehind: true,
inside: {
'number': /^\$0x[\s\S]{2}$/,
'variable': /^\$\w+$/,
'interpolation-punctuation': {
pattern: /^\$\{|\}$/,
alias: 'punctuation'
},
'expression': {
pattern: /[\s\S]+/,
inside: null // see below
}
}
},
'string': /[\s\S]+/
}
},

'keyword': /\b(?:else|if)\b/,
'boolean': /\b(?:true|false)\b/,
'builtin-function': {
// a few functions get special highlighting to improve readability
pattern: /\b(?:assert|defined|foreach|import|pool|print|template|tool|toolchain)(?=\s*\()/i,
alias: 'keyword'
},
'function': /\b[a-z_]\w*(?=\s*\()/i,
'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/,

'number': /-?\b\d+\b/,

'operator': /[-+!=<>]=?|&&|\|\|/,
'punctuation': /[(){}[\],.]/
};

Prism.languages.gn['string-literal'].inside['interpolation'].inside['expression'].inside = Prism.languages.gn;

Prism.languages.gni = Prism.languages.gn;
1 change: 1 addition & 0 deletions components/prism-gn.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions examples/prism-gn.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<h2>Full example</h2>
<pre><code># Source: https://gn.googlesource.com/gn/+/main/docs/cross_compiles.md

declare_args() {
# Applies only to toolchains targeting target_cpu.
sysroot = ""
}

config("my_config") {
# Uses current_cpu because compile flags are toolchain-dependent.
if (current_cpu == "arm") {
defines = [ "CPU_IS_32_BIT" ]
} else {
defines = [ "CPU_IS_64_BIT" ]
}
# Compares current_cpu with target_cpu to see whether current_toolchain
# has the same architecture as target_toolchain.
if (sysroot != "" && current_cpu == target_cpu) {
cflags = [
"-isysroot",
sysroot,
]
}
}</code></pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
"xlsx": "excel-formula",
"xls": "excel-formula",
"gamemakerlanguage": "gml",
"gni": "gn",
"hbs": "handlebars",
"hs": "haskell",
"idr": "idris",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
"gdscript": "GDScript",
"gedcom": "GEDCOM",
"glsl": "GLSL",
"gn": "GN",
"gni": "GN",
"graphql": "GraphQL",
"hbs": "Handlebars",
"hs": "Haskell",
Expand Down
Loading

0 comments on commit 4f97b82

Please sign in to comment.