Skip to content

Commit

Permalink
Added support for AWK (#3375)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Mar 21, 2022
1 parent 33f2cf9 commit a134066
Show file tree
Hide file tree
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
Expand Up @@ -330,6 +330,10 @@
"title": "CSV",
"owner": "RunDevelopment"
},
"cue": {
"title": "CUE",
"owner": "RunDevelopment"
},
"cypher": {
"title": "Cypher",
"owner": "RunDevelopment"
Expand Down
84 changes: 84 additions & 0 deletions components/prism-cue.js
@@ -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
@@ -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
Expand Up @@ -71,6 +71,7 @@
"csp": "Content-Security-Policy",
"css-extras": "CSS Extras",
"csv": "CSV",
"cue": "CUE",
"dataweave": "DataWeave",
"dax": "DAX",
"django": "Django/Jinja2",
Expand Down
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
@@ -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
@@ -0,0 +1,9 @@
true
false

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

[
["boolean", "true"],
["boolean", "false"]
]
74 changes: 74 additions & 0 deletions tests/languages/cue/builtin_feature.test
@@ -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
@@ -0,0 +1,7 @@
// comment

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

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

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

[
"math",
["punctuation", "."],
["function", "Sin"],
["punctuation", "("],
"x",
["punctuation", ")"]
]

0 comments on commit a134066

Please sign in to comment.