Skip to content

Commit

Permalink
Added support for AWK (#3375)
Browse files Browse the repository at this point in the history
RunDevelopment authored Mar 21, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 33f2cf9 commit a134066
Showing 17 changed files with 534 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
@@ -330,6 +330,10 @@
"title": "CSV",
"owner": "RunDevelopment"
},
"cue": {
"title": "CUE",
"owner": "RunDevelopment"
},
"cypher": {
"title": "Cypher",
"owner": "RunDevelopment"
84 changes: 84 additions & 0 deletions components/prism-cue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
(function (Prism) {

// https://cuelang.org/docs/references/spec/

// eslint-disable-next-line regexp/strict
var stringEscape = /\\(?:(?!\2)|\2(?:[^()\r\n]|\([^()]*\)))/.source;
// eslint-disable-next-line regexp/strict
var stringTypes = /"""(?:[^\\"]|"(?!""\2)|<esc>)*"""/.source +
// eslint-disable-next-line regexp/strict
'|' + /'''(?:[^\\']|'(?!''\2)|<esc>)*'''/.source +
// eslint-disable-next-line regexp/strict
'|' + /"(?:[^\\\r\n"]|"(?!\2)|<esc>)*"/.source +
// eslint-disable-next-line regexp/strict
'|' + /'(?:[^\\\r\n']|'(?!\2)|<esc>)*'/.source;
var stringLiteral = '(?:' + stringTypes.replace(/<esc>/g, stringEscape) + ')';

Prism.languages.cue = {
'comment': {
pattern: /\/\/.*/,
greedy: true
},
'string-literal': {
// eslint-disable-next-line regexp/strict
pattern: RegExp(/(^|[^#"'\\])(#*)/.source + stringLiteral + /(?!["'])\2/.source),
lookbehind: true,
greedy: true,
inside: {
// I'm using dirty hack here. We have to know the number hashes at the start of the string somehow,
// but we can't look back. So instead, we will use a lookahead, go to the end of the string, and
// capture the hashes at the end of the string.
'escape': {
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}|[^(])/,
greedy: true,
alias: 'string'
},
'interpolation': {
pattern: /(?=[\s\S]*["'](#*)$)\\\1\([^()]*\)/,
greedy: true,
inside: {
'punctuation': /^\\#*\(|\)$/,
'expression': {
pattern: /[\s\S]+/,
inside: null
}
}
},
'string': /[\s\S]+/
}
},

'keyword': {
pattern: /(^|[^\w$])(?:for|if|import|in|let|null|package)(?![\w$])/,
lookbehind: true
},
'boolean': {
pattern: /(^|[^\w$])(?:false|true)(?![\w$])/,
lookbehind: true
},
'builtin': {
pattern: /(^|[^\w$])(?:bool|bytes|float|float(?:32|64)|u?int(?:8|16|32|64|128)?|number|rune|string)(?![\w$])/,
lookbehind: true
},

'attribute': {
pattern: /@[\w$]+(?=\s*\()/,
alias: 'function'
},
'function': {
pattern: /(^|[^\w$])[a-z_$][\w$]*(?=\s*\()/i,
lookbehind: true
},

'number': {
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$])/,
lookbehind: true
},

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

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

}(Prism));
1 change: 1 addition & 0 deletions components/prism-cue.min.js

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

23 changes: 23 additions & 0 deletions examples/prism-cue.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<h2>Full example</h2>
<pre><code>#Spec: {
kind: string

name: {
first: !="" // must be specified and non-empty
middle?: !="" // optional, but must be non-empty when specified
last: !=""
}

// The minimum must be strictly smaller than the maximum and vice versa.
minimum?: int & &lt;maximum
maximum?: int & >minimum
}

// A spec is of type #Spec
spec: #Spec
spec: {
knid: "Homo Sapiens" // error, misspelled field

name: first: "Jane"
name: last: "Doe"
}</code></pre>
1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
@@ -71,6 +71,7 @@
"csp": "Content-Security-Policy",
"css-extras": "CSS Extras",
"csv": "CSV",
"cue": "CUE",
"dataweave": "DataWeave",
"dax": "DAX",
"django": "Django/Jinja2",
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

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

20 changes: 20 additions & 0 deletions tests/languages/cue/attribute_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@protobuf(proto3)
@jsonschema(id="https://example.org/mystruct1.json")

----------------------------------------------------

[
["attribute", "@protobuf"],
["punctuation", "("],
"proto3",
["punctuation", ")"],

["attribute", "@jsonschema"],
["punctuation", "("],
"id",
["operator", "="],
["string-literal", [
["string", "\"https://example.org/mystruct1.json\""]
]],
["punctuation", ")"]
]
9 changes: 9 additions & 0 deletions tests/languages/cue/boolean_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
true
false

----------------------------------------------------

[
["boolean", "true"],
["boolean", "false"]
]
74 changes: 74 additions & 0 deletions tests/languages/cue/builtin_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Types
null // The null type and value
bool // All boolean values
int // All integral numbers
float // All decimal floating-point numbers
string // Any valid UTF-8 sequence
bytes // Any valid byte sequence

// Derived Value
number // int | float
uint // >=0
uint8 // >=0 & <=255
int8 // >=-128 & <=127
uint16 // >=0 & <=65536
int16 // >=-32_768 & <=32_767
rune // >=0 & <=0x10FFFF
uint32 // >=0 & <=4_294_967_296
int32 // >=-2_147_483_648 & <=2_147_483_647
uint64 // >=0 & <=18_446_744_073_709_551_615
int64 // >=-9_223_372_036_854_775_808 & <=9_223_372_036_854_775_807
uint128 // >=0 & <=340_282_366_920_938_463_463_374_607_431_768_211_455
int128 // >=-170_141_183_460_469_231_731_687_303_715_884_105_728 &
// <=170_141_183_460_469_231_731_687_303_715_884_105_727
float32 // >=-3.40282346638528859811704183484516925440e+38 &
// <=3.40282346638528859811704183484516925440e+38
float64 // >=-1.797693134862315708145274237317043567981e+308 &
// <=1.797693134862315708145274237317043567981e+308

----------------------------------------------------

[
["comment", "// Types"],
["keyword", "null"], ["comment", "// The null type and value"],
["builtin", "bool"], ["comment", "// All boolean values"],
["builtin", "int"], ["comment", "// All integral numbers"],
["builtin", "float"], ["comment", "// All decimal floating-point numbers"],
["builtin", "string"], ["comment", "// Any valid UTF-8 sequence"],
["builtin", "bytes"], ["comment", "// Any valid byte sequence"],

["comment", "// Derived Value"],
["builtin", "number"],
["comment", "// int | float"],
["builtin", "uint"],
["comment", "// >=0"],
["builtin", "uint8"],
["comment", "// >=0 & <=255"],
["builtin", "int8"],
["comment", "// >=-128 & <=127"],
["builtin", "uint16"],
["comment", "// >=0 & <=65536"],
["builtin", "int16"],
["comment", "// >=-32_768 & <=32_767"],
["builtin", "rune"],
["comment", "// >=0 & <=0x10FFFF"],
["builtin", "uint32"],
["comment", "// >=0 & <=4_294_967_296"],
["builtin", "int32"],
["comment", "// >=-2_147_483_648 & <=2_147_483_647"],
["builtin", "uint64"],
["comment", "// >=0 & <=18_446_744_073_709_551_615"],
["builtin", "int64"],
["comment", "// >=-9_223_372_036_854_775_808 & <=9_223_372_036_854_775_807"],
["builtin", "uint128"],
["comment", "// >=0 & <=340_282_366_920_938_463_463_374_607_431_768_211_455"],
["builtin", "int128"],
["comment", "// >=-170_141_183_460_469_231_731_687_303_715_884_105_728 &"],
["comment", "// <=170_141_183_460_469_231_731_687_303_715_884_105_727"],
["builtin", "float32"],
["comment", "// >=-3.40282346638528859811704183484516925440e+38 &"],
["comment", "// <=3.40282346638528859811704183484516925440e+38"],
["builtin", "float64"],
["comment", "// >=-1.797693134862315708145274237317043567981e+308 &"],
["comment", "// <=1.797693134862315708145274237317043567981e+308"]
]
7 changes: 7 additions & 0 deletions tests/languages/cue/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// comment

----------------------------------------------------

[
["comment", "// comment"]
]
12 changes: 12 additions & 0 deletions tests/languages/cue/function_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
math.Sin(x)

----------------------------------------------------

[
"math",
["punctuation", "."],
["function", "Sin"],
["punctuation", "("],
"x",
["punctuation", ")"]
]
19 changes: 19 additions & 0 deletions tests/languages/cue/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
for
if
import
in
let
null
package

----------------------------------------------------

[
["keyword", "for"],
["keyword", "if"],
["keyword", "import"],
["keyword", "in"],
["keyword", "let"],
["keyword", "null"],
["keyword", "package"]
]
39 changes: 39 additions & 0 deletions tests/languages/cue/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
42
1.5G // 1_000_000_000
1.3Ki // 1.3 * 1024 = trunc(1331.2) = 1331
170_141_183_460_469_231_731_687_303_715_884_105_727
0xBad_Face
0o755
0b0101_0001

0.
72.40
072.40 // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5

----------------------------------------------------

[
["number", "42"],
["number", "1.5G"], ["comment", "// 1_000_000_000"],
["number", "1.3Ki"], ["comment", "// 1.3 * 1024 = trunc(1331.2) = 1331"],
["number", "170_141_183_460_469_231_731_687_303_715_884_105_727"],
["number", "0xBad_Face"],
["number", "0o755"],
["number", "0b0101_0001"],

["number", "0."],
["number", "72.40"],
["number", "072.40"], ["comment", "// == 72.40"],
["number", "2.71828"],
["number", "1.e+0"],
["number", "6.67428e-11"],
["number", "1E6"],
["number", ".25"],
["number", ".12345E+5"]
]
32 changes: 32 additions & 0 deletions tests/languages/cue/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
+ - * /
< <= > >= == != =~ !~

&& || & |
! ? =

_|_
...

----------------------------------------------------

[
["operator", "+"],
["operator", "-"],
["operator", "*"],
["operator", "/"],

["operator", "<"],
["operator", "<="],
["operator", ">"],
["operator", ">="],
["operator", "=="],
["operator", "!="],
["operator", "=~"],
["operator", "!~"],

["operator", "&&"], ["operator", "||"], ["operator", "&"], ["operator", "|"],
["operator", "!"], ["operator", "?"], ["operator", "="],

["operator", "_|_"],
["operator", "..."]
]
17 changes: 17 additions & 0 deletions tests/languages/cue/punctuation_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
( ) [ ] { }
, . :

----------------------------------------------------

[
["punctuation", "("],
["punctuation", ")"],
["punctuation", "["],
["punctuation", "]"],
["punctuation", "{"],
["punctuation", "}"],

["punctuation", ","],
["punctuation", "."],
["punctuation", ":"]
]
190 changes: 190 additions & 0 deletions tests/languages/cue/string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
'a\000\xab'
'\007'
'\377'
'\xa' // illegal: too few hexadecimal digits
"\n"
"\""
'Hello, world!\n'
"Hello, \( name )!"
"日本語"
"\u65e5本\U00008a9e"
'\xff\u00FF'
"\uD800" // illegal: surrogate half (TODO: probably should allow)
"\U00110000" // illegal: invalid Unicode code point

#"This is not an \(interpolation)"#
#"This is an \#(interpolation)"#
#"The sequence "\U0001F604" renders as \#U0001F604."#

"日本語" // UTF-8 input text
'日本語' // UTF-8 input text as byte sequence
"\u65e5\u672c\u8a9e" // the explicit Unicode code points
"\U000065e5\U0000672c\U00008a9e" // the explicit Unicode code points
'\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e' // the explicit UTF-8 bytes

"""
lily:
out of the water
out of itself

bass
picking bugs
off the moon
— Nick Virgilio, Selected Haiku, 1988
"""

----------------------------------------------------

[
["string-literal", [
["string", "'a"],
["escape", "\\000"],
["escape", "\\xab"],
["string", "'"]
]],

["string-literal", [
["string", "'"],
["escape", "\\007"],
["string", "'"]
]],

["string-literal", [
["string", "'"],
["escape", "\\377"],
["string", "'"]
]],

["string-literal", [
["string", "'"],
["escape", "\\xa"],
["string", "'"]
]],
["comment", "// illegal: too few hexadecimal digits"],

["string-literal", [
["string", "\""],
["escape", "\\n"],
["string", "\""]
]],

["string-literal", [
["string", "\""],
["escape", "\\\""],
["string", "\""]
]],

["string-literal", [
["string", "'Hello, world!"],
["escape", "\\n"],
["string", "'"]
]],

["string-literal", [
["string", "\"Hello, "],
["interpolation", [
["punctuation", "\\("],
["expression", [" name "]],
["punctuation", ")"]
]],
["string", "!\""]
]],

["string-literal", [
["string", "\"日本語\""]
]],

["string-literal", [
["string", "\""],
["escape", "\\u65e5"],
["string", "本"],
["escape", "\\U00008a9e"],
["string", "\""]
]],

["string-literal", [
["string", "'"],
["escape", "\\xff"],
["escape", "\\u00FF"],
["string", "'"]
]],

["string-literal", [
["string", "\""],
["escape", "\\uD800"],
["string", "\""]
]],
["comment", "// illegal: surrogate half (TODO: probably should allow)"],

["string-literal", [
["string", "\""],
["escape", "\\U00110000"],
["string", "\""]
]],
["comment", "// illegal: invalid Unicode code point"],

["string-literal", [
["string", "#\"This is not an \\(interpolation)\"#"]
]],
["string-literal", [
["string", "#\"This is an "],
["interpolation", [
["punctuation", "\\#("],
["expression", ["interpolation"]],
["punctuation", ")"]
]],
["string", "\"#"]
]],
["string-literal", [
["string", "#\"The sequence \"\\U0001F604\" renders as "],
["escape", "\\#U0001F604"],
["string", ".\"#"]
]],

["string-literal", [
["string", "\"日本語\""]
]],
["comment", "// UTF-8 input text"],

["string-literal", [
["string", "'日本語'"]
]],
["comment", "// UTF-8 input text as byte sequence"],

["string-literal", [
["string", "\""],
["escape", "\\u65e5"],
["escape", "\\u672c"],
["escape", "\\u8a9e"],
["string", "\""]
]],
["comment", "// the explicit Unicode code points"],

["string-literal", [
["string", "\""],
["escape", "\\U000065e5"],
["escape", "\\U0000672c"],
["escape", "\\U00008a9e"],
["string", "\""]
]],
["comment", "// the explicit Unicode code points"],

["string-literal", [
["string", "'"],
["escape", "\\xe6"],
["escape", "\\x97"],
["escape", "\\xa5"],
["escape", "\\xe6"],
["escape", "\\x9c"],
["escape", "\\xac"],
["escape", "\\xe8"],
["escape", "\\xaa"],
["escape", "\\x9e"],
["string", "'"]
]],
["comment", "// the explicit UTF-8 bytes"],

["string-literal", [
["string", "\"\"\"\r\n lily:\r\n out of the water\r\n out of itself\r\n\r\n bass\r\n picking bugs\r\n off the moon\r\n — Nick Virgilio, Selected Haiku, 1988\r\n \"\"\""]
]]
]

0 comments on commit a134066

Please sign in to comment.