1 | (function (Prism) {
|
2 | Prism.languages.scheme = {
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'comment': /;.*|#;\s*(?:\((?:[^()]|\([^()]*\))*\)|\[(?:[^\[\]]|\[[^\[\]]*\])*\])|#\|(?:[^#|]|#(?!\|)|\|(?!#)|#\|(?:[^#|]|#(?!\|)|\|(?!#))*\|#)*\|#/,
|
9 | 'string': {
|
10 | pattern: /"(?:[^"\\]|\\.)*"/,
|
11 | greedy: true
|
12 | },
|
13 | 'symbol': {
|
14 | pattern: /'[^()\[\]#'\s]+/,
|
15 | greedy: true
|
16 | },
|
17 | 'character': {
|
18 | pattern: /#\\(?:[ux][a-fA-F\d]+\b|[-a-zA-Z]+\b|[\uD800-\uDBFF][\uDC00-\uDFFF]|\S)/,
|
19 | greedy: true,
|
20 | alias: 'string'
|
21 | },
|
22 | 'lambda-parameter': [
|
23 |
|
24 | {
|
25 | pattern: /((?:^|[^'`#])[(\[]lambda\s+)(?:[^|()\[\]'\s]+|\|(?:[^\\|]|\\.)*\|)/,
|
26 | lookbehind: true
|
27 | },
|
28 | {
|
29 | pattern: /((?:^|[^'`#])[(\[]lambda\s+[(\[])[^()\[\]']+/,
|
30 | lookbehind: true
|
31 | }
|
32 | ],
|
33 | 'keyword': {
|
34 | pattern: /((?:^|[^'`#])[(\[])(?:begin|case(?:-lambda)?|cond(?:-expand)?|define(?:-library|-macro|-record-type|-syntax|-values)?|defmacro|delay(?:-force)?|do|else|export|except|guard|if|import|include(?:-ci|-library-declarations)?|lambda|let(?:rec)?(?:-syntax|-values|\*)?|let\*-values|only|parameterize|prefix|(?:quasi-?)?quote|rename|set!|syntax-(?:case|rules)|unless|unquote(?:-splicing)?|when)(?=[()\[\]\s]|$)/,
|
35 | lookbehind: true
|
36 | },
|
37 | 'builtin': {
|
38 |
|
39 | pattern: /((?:^|[^'`#])[(\[])(?:abs|and|append|apply|assoc|ass[qv]|binary-port\?|boolean=?\?|bytevector(?:-append|-copy|-copy!|-length|-u8-ref|-u8-set!|\?)?|caar|cadr|call-with-(?:current-continuation|port|values)|call\/cc|car|cdar|cddr|cdr|ceiling|char(?:->integer|-ready\?|\?|<\?|<=\?|=\?|>\?|>=\?)|close-(?:input-port|output-port|port)|complex\?|cons|current-(?:error|input|output)-port|denominator|dynamic-wind|eof-object\??|eq\?|equal\?|eqv\?|error|error-object(?:-irritants|-message|\?)|eval|even\?|exact(?:-integer-sqrt|-integer\?|\?)?|expt|features|file-error\?|floor(?:-quotient|-remainder|\/)?|flush-output-port|for-each|gcd|get-output-(?:bytevector|string)|inexact\??|input-port(?:-open\?|\?)|integer(?:->char|\?)|lcm|length|list(?:->string|->vector|-copy|-ref|-set!|-tail|\?)?|make-(?:bytevector|list|parameter|string|vector)|map|max|member|memq|memv|min|modulo|negative\?|newline|not|null\?|number(?:->string|\?)|numerator|odd\?|open-(?:input|output)-(?:bytevector|string)|or|output-port(?:-open\?|\?)|pair\?|peek-char|peek-u8|port\?|positive\?|procedure\?|quotient|raise|raise-continuable|rational\?|rationalize|read-(?:bytevector|bytevector!|char|error\?|line|string|u8)|real\?|remainder|reverse|round|set-c[ad]r!|square|string(?:->list|->number|->symbol|->utf8|->vector|-append|-copy|-copy!|-fill!|-for-each|-length|-map|-ref|-set!|\?|<\?|<=\?|=\?|>\?|>=\?)?|substring|symbol(?:->string|\?|=\?)|syntax-error|textual-port\?|truncate(?:-quotient|-remainder|\/)?|u8-ready\?|utf8->string|values|vector(?:->list|->string|-append|-copy|-copy!|-fill!|-for-each|-length|-map|-ref|-set!|\?)?|with-exception-handler|write-(?:bytevector|char|string|u8)|zero\?)(?=[()\[\]\s]|$)/,
|
40 | lookbehind: true
|
41 | },
|
42 | 'operator': {
|
43 | pattern: /((?:^|[^'`#])[(\[])(?:[-+*%/]|[<>]=?|=>?)(?=[()\[\]\s]|$)/,
|
44 | lookbehind: true
|
45 | },
|
46 | 'number': {
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | pattern: RegExp(SortedBNF({
|
73 | '<ureal dec>': /\d+(?:\/\d+)|(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?/.source,
|
74 | '<real dec>': /[+-]?<ureal dec>|[+-](?:inf|nan)\.0/.source,
|
75 | '<imaginary dec>': /[+-](?:<ureal dec>|(?:inf|nan)\.0)?i/.source,
|
76 | '<complex dec>': /<real dec>(?:@<real dec>|<imaginary dec>)?|<imaginary dec>/.source,
|
77 | '<num dec>': /(?:#d(?:#[ei])?|#[ei](?:#d)?)?<complex dec>/.source,
|
78 |
|
79 | '<ureal box>': /[0-9a-f]+(?:\/[0-9a-f]+)?/.source,
|
80 | '<real box>': /[+-]?<ureal box>|[+-](?:inf|nan)\.0/.source,
|
81 | '<imaginary box>': /[+-](?:<ureal box>|(?:inf|nan)\.0)?i/.source,
|
82 | '<complex box>': /<real box>(?:@<real box>|<imaginary box>)?|<imaginary box>/.source,
|
83 | '<num box>': /#[box](?:#[ei])?|(?:#[ei])?#[box]<complex box>/.source,
|
84 |
|
85 | '<number>': /(^|[()\[\]\s])(?:<num dec>|<num box>)(?=[()\[\]\s]|$)/.source,
|
86 | }), 'i'),
|
87 | lookbehind: true
|
88 | },
|
89 | 'boolean': {
|
90 | pattern: /(^|[()\[\]\s])#(?:[ft]|false|true)(?=[()\[\]\s]|$)/,
|
91 | lookbehind: true
|
92 | },
|
93 | 'function': {
|
94 | pattern: /((?:^|[^'`#])[(\[])(?:[^|()\[\]'\s]+|\|(?:[^\\|]|\\.)*\|)(?=[()\[\]\s]|$)/,
|
95 | lookbehind: true
|
96 | },
|
97 | 'identifier': {
|
98 | pattern: /(^|[()\[\]\s])\|(?:[^\\|]|\\.)*\|(?=[()\[\]\s]|$)/,
|
99 | lookbehind: true,
|
100 | greedy: true
|
101 | },
|
102 | 'punctuation': /[()\[\]']/
|
103 | };
|
104 |
|
105 | |
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 | function SortedBNF(grammar) {
|
112 | for (var key in grammar) {
|
113 | grammar[key] = grammar[key].replace(/<[\w\s]+>/g, function (key) {
|
114 | return '(?:' + grammar[key].trim() + ')';
|
115 | });
|
116 | }
|
117 |
|
118 | return grammar[key];
|
119 | }
|
120 |
|
121 | }(Prism));
|