-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33f2cf9
commit a134066
Showing
17 changed files
with
534 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 & <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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", ")"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
true | ||
false | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["boolean", "true"], | ||
["boolean", "false"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// comment | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "// comment"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
math.Sin(x) | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
"math", | ||
["punctuation", "."], | ||
["function", "Sin"], | ||
["punctuation", "("], | ||
"x", | ||
["punctuation", ")"] | ||
] |
Oops, something went wrong.