[d24f17c] | 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));
|
---|