UNPKG

2.6 kBJavaScriptView Raw
1// https://wren.io/
2
3Prism.languages.wren = {
4 // Multiline comments in Wren can have nested multiline comments
5 // Comments: // and /* */
6 'comment': [
7 {
8 // support 3 levels of nesting
9 // regex: \/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|<self>)*\*\/
10 pattern: /\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|\/\*(?:[^*/]|\*(?!\/)|\/(?!\*))*\*\/)*\*\/)*\*\//,
11 greedy: true
12 },
13 {
14 pattern: /(^|[^\\:])\/\/.*/,
15 lookbehind: true,
16 greedy: true
17 }
18 ],
19
20 // Triple quoted strings are multiline but cannot have interpolation (raw strings)
21 // Based on prism-python.js
22 'triple-quoted-string': {
23 pattern: /"""[\s\S]*?"""/,
24 greedy: true,
25 alias: 'string'
26 },
27
28 // see below
29 'string-literal': null,
30
31 // #!/usr/bin/env wren on the first line
32 'hashbang': {
33 pattern: /^#!\/.+/,
34 greedy: true,
35 alias: 'comment'
36 },
37
38 // Attributes are special keywords to add meta data to classes
39 'attribute': {
40 // #! attributes are stored in class properties
41 // #!myvar = true
42 // #attributes are not stored and dismissed at compilation
43 pattern: /#!?[ \t\u3000]*\w+/,
44 alias: 'keyword'
45 },
46 'class-name': [
47 {
48 // class definition
49 // class Meta {}
50 pattern: /(\bclass\s+)\w+/,
51 lookbehind: true
52 },
53 // A class must always start with an uppercase.
54 // File.read
55 /\b[A-Z][a-z\d_]*\b/,
56 ],
57
58 // A constant can be a variable, class, property or method. Just named in all uppercase letters
59 'constant': /\b[A-Z][A-Z\d_]*\b/,
60
61 'null': {
62 pattern: /\bnull\b/,
63 alias: 'keyword'
64 },
65 'keyword': /\b(?:as|break|class|construct|continue|else|for|foreign|if|import|in|is|return|static|super|this|var|while)\b/,
66 'boolean': /\b(?:true|false)\b/,
67 'number': /\b(?:0x[\da-f]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?)\b/i,
68
69 // Functions can be Class.method()
70 'function': /\b[a-z_]\w*(?=\s*[({])/i,
71
72 'operator': /<<|>>|[=!<>]=?|&&|\|\||[-+*/%~^&|?:]|\.{2,3}/,
73 'punctuation': /[\[\](){}.,;]/,
74};
75
76Prism.languages.wren['string-literal'] = {
77 // A single quote string is multiline and can have interpolation (similar to JS backticks ``)
78 pattern: /(^|[^\\"])"(?:[^\\"%]|\\[\s\S]|%(?!\()|%\((?:[^()]|\((?:[^()]|\([^)]*\))*\))*\))*"/,
79 lookbehind: true,
80 greedy: true,
81 inside: {
82 'interpolation': {
83 // "%(interpolation)"
84 pattern: /((?:^|[^\\])(?:\\{2})*)%\((?:[^()]|\((?:[^()]|\([^)]*\))*\))*\)/,
85 lookbehind: true,
86 inside: {
87 'expression': {
88 pattern: /^(%\()[\s\S]+(?=\)$)/,
89 lookbehind: true,
90 inside: Prism.languages.wren
91 },
92 'interpolation-punctuation': {
93 pattern: /^%\(|\)$/,
94 alias: 'punctuation'
95 },
96 }
97 },
98 'string': /[\s\S]+/
99 }
100};