Skip to content

Commit a134066

Browse files
Added support for AWK (#3375)
1 parent 33f2cf9 commit a134066

17 files changed

+534
-2
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@
330330
"title": "CSV",
331331
"owner": "RunDevelopment"
332332
},
333+
"cue": {
334+
"title": "CUE",
335+
"owner": "RunDevelopment"
336+
},
333337
"cypher": {
334338
"title": "Cypher",
335339
"owner": "RunDevelopment"

components/prism-cue.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
(function (Prism) {
2+
3+
// https://cuelang.org/docs/references/spec/
4+
5+
// eslint-disable-next-line regexp/strict
6+
var stringEscape = /\\(?:(?!\2)|\2(?:[^()\r\n]|\([^()]*\)))/.source;
7+
// eslint-disable-next-line regexp/strict
8+
var stringTypes = /"""(?:[^\\"]|"(?!""\2)|<esc>)*"""/.source +
9+
// eslint-disable-next-line regexp/strict
10+
'|' + /'''(?:[^\\']|'(?!''\2)|<esc>)*'''/.source +
11+
// eslint-disable-next-line regexp/strict
12+
'|' + /"(?:[^\\\r\n"]|"(?!\2)|<esc>)*"/.source +
13+
// eslint-disable-next-line regexp/strict
14+
'|' + /'(?:[^\\\r\n']|'(?!\2)|<esc>)*'/.source;
15+
var stringLiteral = '(?:' + stringTypes.replace(/<esc>/g, stringEscape) + ')';
16+
17+
Prism.languages.cue = {
18+
'comment': {
19+
pattern: /\/\/.*/,
20+
greedy: true
21+
},
22+
'string-literal': {
23+
// eslint-disable-next-line regexp/strict
24+
pattern: RegExp(/(^|[^#"'\\])(#*)/.source + stringLiteral + /(?!["'])\2/.source),
25+
lookbehind: true,
26+
greedy: true,
27+
inside: {
28+
// I'm using dirty hack here. We have to know the number hashes at the start of the string somehow,
29+
// but we can't look back. So instead, we will use a lookahead, go to the end of the string, and
30+
// capture the hashes at the end of the string.
31+
'escape': {
32+
pattern: /(?=[\s\S]*["'](#*)$)\\\1(?:U[a-fA-F0-9]{1,8}|u[a-fA-F0-9]{1,4}|x[a-fA-F0-9]{1,2}|\d{2,3}|[^(])/,
33+
greedy: true,
34+
alias: 'string'
35+
},
36+
'interpolation': {
37+
pattern: /(?=[\s\S]*["'](#*)$)\\\1\([^()]*\)/,
38+
greedy: true,
39+
inside: {
40+
'punctuation': /^\\#*\(|\)$/,
41+
'expression': {
42+
pattern: /[\s\S]+/,
43+
inside: null
44+
}
45+
}
46+
},
47+
'string': /[\s\S]+/
48+
}
49+
},
50+
51+
'keyword': {
52+
pattern: /(^|[^\w$])(?:for|if|import|in|let|null|package)(?![\w$])/,
53+
lookbehind: true
54+
},
55+
'boolean': {
56+
pattern: /(^|[^\w$])(?:false|true)(?![\w$])/,
57+
lookbehind: true
58+
},
59+
'builtin': {
60+
pattern: /(^|[^\w$])(?:bool|bytes|float|float(?:32|64)|u?int(?:8|16|32|64|128)?|number|rune|string)(?![\w$])/,
61+
lookbehind: true
62+
},
63+
64+
'attribute': {
65+
pattern: /@[\w$]+(?=\s*\()/,
66+
alias: 'function'
67+
},
68+
'function': {
69+
pattern: /(^|[^\w$])[a-z_$][\w$]*(?=\s*\()/i,
70+
lookbehind: true
71+
},
72+
73+
'number': {
74+
pattern: /(^|[^\w$.])(?:0b[01]+(?:_[01]+)*|0o[0-7]+(?:_[0-7]+)*|0[xX][0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*|(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[eE][+-]?\d+(?:_\d+)*)?(?:[KMGTP]i?)?)(?![\w$])/,
75+
lookbehind: true
76+
},
77+
78+
'operator': /\.{3}|_\|_|&&?|\|\|?|[=!]~|[<>=!]=?|[+\-*/?]/,
79+
'punctuation': /[()[\]{},.:]/
80+
};
81+
82+
Prism.languages.cue['string-literal'].inside.interpolation.inside.expression.inside = Prism.languages.cue;
83+
84+
}(Prism));

components/prism-cue.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-cue.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<h2>Full example</h2>
2+
<pre><code>#Spec: {
3+
kind: string
4+
5+
name: {
6+
first: !="" // must be specified and non-empty
7+
middle?: !="" // optional, but must be non-empty when specified
8+
last: !=""
9+
}
10+
11+
// The minimum must be strictly smaller than the maximum and vice versa.
12+
minimum?: int & &lt;maximum
13+
maximum?: int & >minimum
14+
}
15+
16+
// A spec is of type #Spec
17+
spec: #Spec
18+
spec: {
19+
knid: "Homo Sapiens" // error, misspelled field
20+
21+
name: first: "Jane"
22+
name: last: "Doe"
23+
}</code></pre>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"csp": "Content-Security-Policy",
7272
"css-extras": "CSS Extras",
7373
"csv": "CSV",
74+
"cue": "CUE",
7475
"dataweave": "DataWeave",
7576
"dax": "DAX",
7677
"django": "Django/Jinja2",

plugins/show-language/prism-show-language.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.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@protobuf(proto3)
2+
@jsonschema(id="https://example.org/mystruct1.json")
3+
4+
----------------------------------------------------
5+
6+
[
7+
["attribute", "@protobuf"],
8+
["punctuation", "("],
9+
"proto3",
10+
["punctuation", ")"],
11+
12+
["attribute", "@jsonschema"],
13+
["punctuation", "("],
14+
"id",
15+
["operator", "="],
16+
["string-literal", [
17+
["string", "\"https://example.org/mystruct1.json\""]
18+
]],
19+
["punctuation", ")"]
20+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
true
2+
false
3+
4+
----------------------------------------------------
5+
6+
[
7+
["boolean", "true"],
8+
["boolean", "false"]
9+
]
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Types
2+
null // The null type and value
3+
bool // All boolean values
4+
int // All integral numbers
5+
float // All decimal floating-point numbers
6+
string // Any valid UTF-8 sequence
7+
bytes // Any valid byte sequence
8+
9+
// Derived Value
10+
number // int | float
11+
uint // >=0
12+
uint8 // >=0 & <=255
13+
int8 // >=-128 & <=127
14+
uint16 // >=0 & <=65536
15+
int16 // >=-32_768 & <=32_767
16+
rune // >=0 & <=0x10FFFF
17+
uint32 // >=0 & <=4_294_967_296
18+
int32 // >=-2_147_483_648 & <=2_147_483_647
19+
uint64 // >=0 & <=18_446_744_073_709_551_615
20+
int64 // >=-9_223_372_036_854_775_808 & <=9_223_372_036_854_775_807
21+
uint128 // >=0 & <=340_282_366_920_938_463_463_374_607_431_768_211_455
22+
int128 // >=-170_141_183_460_469_231_731_687_303_715_884_105_728 &
23+
// <=170_141_183_460_469_231_731_687_303_715_884_105_727
24+
float32 // >=-3.40282346638528859811704183484516925440e+38 &
25+
// <=3.40282346638528859811704183484516925440e+38
26+
float64 // >=-1.797693134862315708145274237317043567981e+308 &
27+
// <=1.797693134862315708145274237317043567981e+308
28+
29+
----------------------------------------------------
30+
31+
[
32+
["comment", "// Types"],
33+
["keyword", "null"], ["comment", "// The null type and value"],
34+
["builtin", "bool"], ["comment", "// All boolean values"],
35+
["builtin", "int"], ["comment", "// All integral numbers"],
36+
["builtin", "float"], ["comment", "// All decimal floating-point numbers"],
37+
["builtin", "string"], ["comment", "// Any valid UTF-8 sequence"],
38+
["builtin", "bytes"], ["comment", "// Any valid byte sequence"],
39+
40+
["comment", "// Derived Value"],
41+
["builtin", "number"],
42+
["comment", "// int | float"],
43+
["builtin", "uint"],
44+
["comment", "// >=0"],
45+
["builtin", "uint8"],
46+
["comment", "// >=0 & <=255"],
47+
["builtin", "int8"],
48+
["comment", "// >=-128 & <=127"],
49+
["builtin", "uint16"],
50+
["comment", "// >=0 & <=65536"],
51+
["builtin", "int16"],
52+
["comment", "// >=-32_768 & <=32_767"],
53+
["builtin", "rune"],
54+
["comment", "// >=0 & <=0x10FFFF"],
55+
["builtin", "uint32"],
56+
["comment", "// >=0 & <=4_294_967_296"],
57+
["builtin", "int32"],
58+
["comment", "// >=-2_147_483_648 & <=2_147_483_647"],
59+
["builtin", "uint64"],
60+
["comment", "// >=0 & <=18_446_744_073_709_551_615"],
61+
["builtin", "int64"],
62+
["comment", "// >=-9_223_372_036_854_775_808 & <=9_223_372_036_854_775_807"],
63+
["builtin", "uint128"],
64+
["comment", "// >=0 & <=340_282_366_920_938_463_463_374_607_431_768_211_455"],
65+
["builtin", "int128"],
66+
["comment", "// >=-170_141_183_460_469_231_731_687_303_715_884_105_728 &"],
67+
["comment", "// <=170_141_183_460_469_231_731_687_303_715_884_105_727"],
68+
["builtin", "float32"],
69+
["comment", "// >=-3.40282346638528859811704183484516925440e+38 &"],
70+
["comment", "// <=3.40282346638528859811704183484516925440e+38"],
71+
["builtin", "float64"],
72+
["comment", "// >=-1.797693134862315708145274237317043567981e+308 &"],
73+
["comment", "// <=1.797693134862315708145274237317043567981e+308"]
74+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// comment
2+
3+
----------------------------------------------------
4+
5+
[
6+
["comment", "// comment"]
7+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
math.Sin(x)
2+
3+
----------------------------------------------------
4+
5+
[
6+
"math",
7+
["punctuation", "."],
8+
["function", "Sin"],
9+
["punctuation", "("],
10+
"x",
11+
["punctuation", ")"]
12+
]

0 commit comments

Comments
 (0)