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