1 | 'use strict'
|
---|
2 |
|
---|
3 | module.exports = factor
|
---|
4 | factor.displayName = 'factor'
|
---|
5 | factor.aliases = []
|
---|
6 | function factor(Prism) {
|
---|
7 | ;(function (Prism) {
|
---|
8 | var comment_inside = {
|
---|
9 | function:
|
---|
10 | /\b(?:BUGS?|FIX(?:MES?)?|NOTES?|TODOS?|XX+|HACKS?|WARN(?:ING)?|\?{2,}|!{2,})\b/
|
---|
11 | }
|
---|
12 | var string_inside = {
|
---|
13 | number: /\\[^\s']|%\w/
|
---|
14 | }
|
---|
15 | var factor = {
|
---|
16 | comment: [
|
---|
17 | {
|
---|
18 | // ! single-line exclamation point comments with whitespace after/around the !
|
---|
19 | pattern: /(^|\s)(?:! .*|!$)/,
|
---|
20 | lookbehind: true,
|
---|
21 | inside: comment_inside
|
---|
22 | },
|
---|
23 | /* from basis/multiline: */
|
---|
24 | {
|
---|
25 | // /* comment */, /* comment*/
|
---|
26 | pattern: /(^|\s)\/\*\s[\s\S]*?\*\/(?=\s|$)/,
|
---|
27 | lookbehind: true,
|
---|
28 | greedy: true,
|
---|
29 | inside: comment_inside
|
---|
30 | },
|
---|
31 | {
|
---|
32 | // ![[ comment ]] , ![===[ comment]===]
|
---|
33 | pattern: /(^|\s)!\[(={0,6})\[\s[\s\S]*?\]\2\](?=\s|$)/,
|
---|
34 | lookbehind: true,
|
---|
35 | greedy: true,
|
---|
36 | inside: comment_inside
|
---|
37 | }
|
---|
38 | ],
|
---|
39 | number: [
|
---|
40 | {
|
---|
41 | // basic base 10 integers 9, -9
|
---|
42 | pattern: /(^|\s)[+-]?\d+(?=\s|$)/,
|
---|
43 | lookbehind: true
|
---|
44 | },
|
---|
45 | {
|
---|
46 | // base prefix integers 0b010 0o70 0xad 0d10 0XAD -0xa9
|
---|
47 | pattern: /(^|\s)[+-]?0(?:b[01]+|o[0-7]+|d\d+|x[\dA-F]+)(?=\s|$)/i,
|
---|
48 | lookbehind: true
|
---|
49 | },
|
---|
50 | {
|
---|
51 | // fractional ratios 1/5 -1/5 and the literal float approximations 1/5. -1/5.
|
---|
52 | pattern: /(^|\s)[+-]?\d+\/\d+\.?(?=\s|$)/,
|
---|
53 | lookbehind: true
|
---|
54 | },
|
---|
55 | {
|
---|
56 | // positive mixed numbers 23+1/5 +23+1/5
|
---|
57 | pattern: /(^|\s)\+?\d+\+\d+\/\d+(?=\s|$)/,
|
---|
58 | lookbehind: true
|
---|
59 | },
|
---|
60 | {
|
---|
61 | // negative mixed numbers -23-1/5
|
---|
62 | pattern: /(^|\s)-\d+-\d+\/\d+(?=\s|$)/,
|
---|
63 | lookbehind: true
|
---|
64 | },
|
---|
65 | {
|
---|
66 | // basic decimal floats -0.01 0. .0 .1 -.1 -1. -12.13 +12.13
|
---|
67 | // and scientific notation with base 10 exponents 3e4 3e-4 .3e-4
|
---|
68 | pattern:
|
---|
69 | /(^|\s)[+-]?(?:\d*\.\d+|\d+\.\d*|\d+)(?:e[+-]?\d+)?(?=\s|$)/i,
|
---|
70 | lookbehind: true
|
---|
71 | },
|
---|
72 | {
|
---|
73 | // NAN literal syntax NAN: 80000deadbeef, NAN: a
|
---|
74 | pattern: /(^|\s)NAN:\s+[\da-fA-F]+(?=\s|$)/,
|
---|
75 | lookbehind: true
|
---|
76 | },
|
---|
77 | {
|
---|
78 | /*
|
---|
79 | base prefix floats 0x1.0p3 (8.0) 0b1.010p2 (5.0) 0x1.p1 0b1.11111111p11111...
|
---|
80 | "The normalized hex form ±0x1.MMMMMMMMMMMMM[pP]±EEEE allows any floating-point number to be specified precisely.
|
---|
81 | The values of MMMMMMMMMMMMM and EEEE map directly to the mantissa and exponent fields of the binary IEEE 754 representation."
|
---|
82 | <https://docs.factorcode.org/content/article-syntax-floats.html>
|
---|
83 | */
|
---|
84 | pattern:
|
---|
85 | /(^|\s)[+-]?0(?:b1\.[01]*|o1\.[0-7]*|d1\.\d*|x1\.[\dA-F]*)p\d+(?=\s|$)/i,
|
---|
86 | lookbehind: true
|
---|
87 | }
|
---|
88 | ],
|
---|
89 | // R/ regexp?\/\\/
|
---|
90 | regexp: {
|
---|
91 | pattern:
|
---|
92 | /(^|\s)R\/\s(?:\\\S|[^\\/])*\/(?:[idmsr]*|[idmsr]+-[idmsr]+)(?=\s|$)/,
|
---|
93 | lookbehind: true,
|
---|
94 | alias: 'number',
|
---|
95 | inside: {
|
---|
96 | variable: /\\\S/,
|
---|
97 | keyword: /[+?*\[\]^$(){}.|]/,
|
---|
98 | operator: {
|
---|
99 | pattern: /(\/)[idmsr]+(?:-[idmsr]+)?/,
|
---|
100 | lookbehind: true
|
---|
101 | }
|
---|
102 | }
|
---|
103 | },
|
---|
104 | boolean: {
|
---|
105 | pattern: /(^|\s)[tf](?=\s|$)/,
|
---|
106 | lookbehind: true
|
---|
107 | },
|
---|
108 | // SBUF" asd", URL" ://...", P" /etc/"
|
---|
109 | 'custom-string': {
|
---|
110 | pattern: /(^|\s)[A-Z0-9\-]+"\s(?:\\\S|[^"\\])*"/,
|
---|
111 | lookbehind: true,
|
---|
112 | greedy: true,
|
---|
113 | alias: 'string',
|
---|
114 | inside: {
|
---|
115 | number: /\\\S|%\w|\//
|
---|
116 | }
|
---|
117 | },
|
---|
118 | 'multiline-string': [
|
---|
119 | {
|
---|
120 | // STRING: name \n content \n ; -> CONSTANT: name "content" (symbol)
|
---|
121 | pattern: /(^|\s)STRING:\s+\S+(?:\n|\r\n).*(?:\n|\r\n)\s*;(?=\s|$)/,
|
---|
122 | lookbehind: true,
|
---|
123 | greedy: true,
|
---|
124 | alias: 'string',
|
---|
125 | inside: {
|
---|
126 | number: string_inside.number,
|
---|
127 | // trailing semicolon on its own line
|
---|
128 | 'semicolon-or-setlocal': {
|
---|
129 | pattern: /([\r\n][ \t]*);(?=\s|$)/,
|
---|
130 | lookbehind: true,
|
---|
131 | alias: 'function'
|
---|
132 | }
|
---|
133 | }
|
---|
134 | },
|
---|
135 | {
|
---|
136 | // HEREDOC: marker \n content \n marker ; -> "content" (immediate)
|
---|
137 | pattern: /(^|\s)HEREDOC:\s+\S+(?:\n|\r\n).*(?:\n|\r\n)\s*\S+(?=\s|$)/,
|
---|
138 | lookbehind: true,
|
---|
139 | greedy: true,
|
---|
140 | alias: 'string',
|
---|
141 | inside: string_inside
|
---|
142 | },
|
---|
143 | {
|
---|
144 | // [[ string ]], [==[ string]==]
|
---|
145 | pattern: /(^|\s)\[(={0,6})\[\s[\s\S]*?\]\2\](?=\s|$)/,
|
---|
146 | lookbehind: true,
|
---|
147 | greedy: true,
|
---|
148 | alias: 'string',
|
---|
149 | inside: string_inside
|
---|
150 | }
|
---|
151 | ],
|
---|
152 | 'special-using': {
|
---|
153 | pattern: /(^|\s)USING:(?:\s\S+)*(?=\s+;(?:\s|$))/,
|
---|
154 | lookbehind: true,
|
---|
155 | alias: 'function',
|
---|
156 | inside: {
|
---|
157 | // this is essentially a regex for vocab names, which i don't want to specify
|
---|
158 | // but the USING: gets picked up as a vocab name
|
---|
159 | string: {
|
---|
160 | pattern: /(\s)[^:\s]+/,
|
---|
161 | lookbehind: true
|
---|
162 | }
|
---|
163 | }
|
---|
164 | },
|
---|
165 | /* this description of stack effect literal syntax is not complete and not as specific as theoretically possible
|
---|
166 | trying to do better is more work and regex-computation-time than it's worth though.
|
---|
167 | - we'd like to have the "delimiter" parts of the stack effect [ (, --, and ) ] be a different (less-important or comment-like) colour to the stack effect contents
|
---|
168 | - we'd like if nested stack effects were treated as such rather than just appearing flat (with `inside`)
|
---|
169 | - we'd like if the following variable name conventions were recognised specifically:
|
---|
170 | special row variables = ..a b..
|
---|
171 | type and stack effect annotations end with a colon = ( quot: ( a: ( -- ) -- b ) -- x ), ( x: number -- )
|
---|
172 | word throws unconditional error = *
|
---|
173 | any other word-like variable name = a ? q' etc
|
---|
174 | https://docs.factorcode.org/content/article-effects.html
|
---|
175 | these are pretty complicated to highlight properly without a real parser, and therefore out of scope
|
---|
176 | the old pattern, which may be later useful, was: (^|\s)(?:call|execute|eval)?\((?:\s+[^"\r\n\t ]\S*)*?\s+--(?:\s+[^"\n\t ]\S*)*?\s+\)(?=\s|$)
|
---|
177 | */
|
---|
178 | // current solution is not great
|
---|
179 | 'stack-effect-delimiter': [
|
---|
180 | {
|
---|
181 | // opening parenthesis
|
---|
182 | pattern: /(^|\s)(?:call|eval|execute)?\((?=\s)/,
|
---|
183 | lookbehind: true,
|
---|
184 | alias: 'operator'
|
---|
185 | },
|
---|
186 | {
|
---|
187 | // middle --
|
---|
188 | pattern: /(\s)--(?=\s)/,
|
---|
189 | lookbehind: true,
|
---|
190 | alias: 'operator'
|
---|
191 | },
|
---|
192 | {
|
---|
193 | // closing parenthesis
|
---|
194 | pattern: /(\s)\)(?=\s|$)/,
|
---|
195 | lookbehind: true,
|
---|
196 | alias: 'operator'
|
---|
197 | }
|
---|
198 | ],
|
---|
199 | combinators: {
|
---|
200 | pattern: null,
|
---|
201 | lookbehind: true,
|
---|
202 | alias: 'keyword'
|
---|
203 | },
|
---|
204 | 'kernel-builtin': {
|
---|
205 | pattern: null,
|
---|
206 | lookbehind: true,
|
---|
207 | alias: 'variable'
|
---|
208 | },
|
---|
209 | 'sequences-builtin': {
|
---|
210 | pattern: null,
|
---|
211 | lookbehind: true,
|
---|
212 | alias: 'variable'
|
---|
213 | },
|
---|
214 | 'math-builtin': {
|
---|
215 | pattern: null,
|
---|
216 | lookbehind: true,
|
---|
217 | alias: 'variable'
|
---|
218 | },
|
---|
219 | 'constructor-word': {
|
---|
220 | // <array> but not <=>
|
---|
221 | pattern: /(^|\s)<(?!=+>|-+>)\S+>(?=\s|$)/,
|
---|
222 | lookbehind: true,
|
---|
223 | alias: 'keyword'
|
---|
224 | },
|
---|
225 | 'other-builtin-syntax': {
|
---|
226 | pattern: null,
|
---|
227 | lookbehind: true,
|
---|
228 | alias: 'operator'
|
---|
229 | },
|
---|
230 | /*
|
---|
231 | full list of supported word naming conventions: (the convention appears outside of the [brackets])
|
---|
232 | set-[x]
|
---|
233 | change-[x]
|
---|
234 | with-[x]
|
---|
235 | new-[x]
|
---|
236 | >[string]
|
---|
237 | [base]>
|
---|
238 | [string]>[number]
|
---|
239 | +[symbol]+
|
---|
240 | [boolean-word]?
|
---|
241 | ?[of]
|
---|
242 | [slot-reader]>>
|
---|
243 | >>[slot-setter]
|
---|
244 | [slot-writer]<<
|
---|
245 | ([implementation-detail])
|
---|
246 | [mutater]!
|
---|
247 | [variant]*
|
---|
248 | [prettyprint].
|
---|
249 | $[help-markup]
|
---|
250 | <constructors>, SYNTAX:, etc are supported by their own patterns.
|
---|
251 | `with` and `new` from `kernel` are their own builtins.
|
---|
252 | see <https://docs.factorcode.org/content/article-conventions.html>
|
---|
253 | */
|
---|
254 | 'conventionally-named-word': {
|
---|
255 | pattern:
|
---|
256 | /(^|\s)(?!")(?:(?:change|new|set|with)-\S+|\$\S+|>[^>\s]+|[^:>\s]+>|[^>\s]+>[^>\s]+|\+[^+\s]+\+|[^?\s]+\?|\?[^?\s]+|[^>\s]+>>|>>[^>\s]+|[^<\s]+<<|\([^()\s]+\)|[^!\s]+!|[^*\s]\S*\*|[^.\s]\S*\.)(?=\s|$)/,
|
---|
257 | lookbehind: true,
|
---|
258 | alias: 'keyword'
|
---|
259 | },
|
---|
260 | 'colon-syntax': {
|
---|
261 | pattern: /(^|\s)(?:[A-Z0-9\-]+#?)?:{1,2}\s+(?:;\S+|(?!;)\S+)(?=\s|$)/,
|
---|
262 | lookbehind: true,
|
---|
263 | greedy: true,
|
---|
264 | alias: 'function'
|
---|
265 | },
|
---|
266 | 'semicolon-or-setlocal': {
|
---|
267 | pattern: /(\s)(?:;|:>)(?=\s|$)/,
|
---|
268 | lookbehind: true,
|
---|
269 | alias: 'function'
|
---|
270 | },
|
---|
271 | // do not highlight leading } or trailing X{ at the begin/end of the file as it's invalid syntax
|
---|
272 | 'curly-brace-literal-delimiter': [
|
---|
273 | {
|
---|
274 | // opening
|
---|
275 | pattern: /(^|\s)[a-z]*\{(?=\s)/i,
|
---|
276 | lookbehind: true,
|
---|
277 | alias: 'operator'
|
---|
278 | },
|
---|
279 | {
|
---|
280 | // closing
|
---|
281 | pattern: /(\s)\}(?=\s|$)/,
|
---|
282 | lookbehind: true,
|
---|
283 | alias: 'operator'
|
---|
284 | }
|
---|
285 | ],
|
---|
286 | // do not highlight leading ] or trailing [ at the begin/end of the file as it's invalid syntax
|
---|
287 | 'quotation-delimiter': [
|
---|
288 | {
|
---|
289 | // opening
|
---|
290 | pattern: /(^|\s)\[(?=\s)/,
|
---|
291 | lookbehind: true,
|
---|
292 | alias: 'operator'
|
---|
293 | },
|
---|
294 | {
|
---|
295 | // closing
|
---|
296 | pattern: /(\s)\](?=\s|$)/,
|
---|
297 | lookbehind: true,
|
---|
298 | alias: 'operator'
|
---|
299 | }
|
---|
300 | ],
|
---|
301 | 'normal-word': {
|
---|
302 | pattern: /(^|\s)[^"\s]\S*(?=\s|$)/,
|
---|
303 | lookbehind: true
|
---|
304 | },
|
---|
305 | /*
|
---|
306 | basic first-class string "a"
|
---|
307 | with escaped double-quote "a\""
|
---|
308 | escaped backslash "\\"
|
---|
309 | and general escapes since Factor has so many "\N"
|
---|
310 | syntax that works in the reference implementation that isn't fully
|
---|
311 | supported because it's an implementation detail:
|
---|
312 | "string 1""string 2" -> 2 strings (works anyway)
|
---|
313 | "string"5 -> string, 5
|
---|
314 | "string"[ ] -> string, quotation
|
---|
315 | { "a"} -> array<string>
|
---|
316 | the rest of those examples all properly recognise the string, but not
|
---|
317 | the other object (number, quotation, etc)
|
---|
318 | this is fine for a regex-only implementation.
|
---|
319 | */
|
---|
320 | string: {
|
---|
321 | pattern: /"(?:\\\S|[^"\\])*"/,
|
---|
322 | greedy: true,
|
---|
323 | inside: string_inside
|
---|
324 | }
|
---|
325 | }
|
---|
326 | var escape = function (str) {
|
---|
327 | return (str + '').replace(/([.?*+\^$\[\]\\(){}|\-])/g, '\\$1')
|
---|
328 | }
|
---|
329 | var arrToWordsRegExp = function (arr) {
|
---|
330 | return new RegExp('(^|\\s)(?:' + arr.map(escape).join('|') + ')(?=\\s|$)')
|
---|
331 | }
|
---|
332 | var builtins = {
|
---|
333 | 'kernel-builtin': [
|
---|
334 | 'or',
|
---|
335 | '2nipd',
|
---|
336 | '4drop',
|
---|
337 | 'tuck',
|
---|
338 | 'wrapper',
|
---|
339 | 'nip',
|
---|
340 | 'wrapper?',
|
---|
341 | 'callstack>array',
|
---|
342 | 'die',
|
---|
343 | 'dupd',
|
---|
344 | 'callstack',
|
---|
345 | 'callstack?',
|
---|
346 | '3dup',
|
---|
347 | 'hashcode',
|
---|
348 | 'pick',
|
---|
349 | '4nip',
|
---|
350 | 'build',
|
---|
351 | '>boolean',
|
---|
352 | 'nipd',
|
---|
353 | 'clone',
|
---|
354 | '5nip',
|
---|
355 | 'eq?',
|
---|
356 | '?',
|
---|
357 | '=',
|
---|
358 | 'swapd',
|
---|
359 | '2over',
|
---|
360 | 'clear',
|
---|
361 | '2dup',
|
---|
362 | 'get-retainstack',
|
---|
363 | 'not',
|
---|
364 | 'tuple?',
|
---|
365 | 'dup',
|
---|
366 | '3nipd',
|
---|
367 | 'call',
|
---|
368 | '-rotd',
|
---|
369 | 'object',
|
---|
370 | 'drop',
|
---|
371 | 'assert=',
|
---|
372 | 'assert?',
|
---|
373 | '-rot',
|
---|
374 | 'execute',
|
---|
375 | 'boa',
|
---|
376 | 'get-callstack',
|
---|
377 | 'curried?',
|
---|
378 | '3drop',
|
---|
379 | 'pickd',
|
---|
380 | 'overd',
|
---|
381 | 'over',
|
---|
382 | 'roll',
|
---|
383 | '3nip',
|
---|
384 | 'swap',
|
---|
385 | 'and',
|
---|
386 | '2nip',
|
---|
387 | 'rotd',
|
---|
388 | 'throw',
|
---|
389 | '(clone)',
|
---|
390 | 'hashcode*',
|
---|
391 | 'spin',
|
---|
392 | 'reach',
|
---|
393 | '4dup',
|
---|
394 | 'equal?',
|
---|
395 | 'get-datastack',
|
---|
396 | 'assert',
|
---|
397 | '2drop',
|
---|
398 | '<wrapper>',
|
---|
399 | 'boolean?',
|
---|
400 | 'identity-hashcode',
|
---|
401 | 'identity-tuple?',
|
---|
402 | 'null',
|
---|
403 | 'composed?',
|
---|
404 | 'new',
|
---|
405 | '5drop',
|
---|
406 | 'rot',
|
---|
407 | '-roll',
|
---|
408 | 'xor',
|
---|
409 | 'identity-tuple',
|
---|
410 | 'boolean'
|
---|
411 | ],
|
---|
412 | 'other-builtin-syntax': [
|
---|
413 | // syntax
|
---|
414 | '=======',
|
---|
415 | 'recursive',
|
---|
416 | 'flushable',
|
---|
417 | '>>',
|
---|
418 | '<<<<<<',
|
---|
419 | 'M\\',
|
---|
420 | 'B',
|
---|
421 | 'PRIVATE>',
|
---|
422 | '\\',
|
---|
423 | '======',
|
---|
424 | 'final',
|
---|
425 | 'inline',
|
---|
426 | 'delimiter',
|
---|
427 | 'deprecated',
|
---|
428 | '<PRIVATE',
|
---|
429 | '>>>>>>',
|
---|
430 | '<<<<<<<',
|
---|
431 | 'parse-complex',
|
---|
432 | 'malformed-complex',
|
---|
433 | 'read-only',
|
---|
434 | '>>>>>>>',
|
---|
435 | 'call-next-method',
|
---|
436 | '<<',
|
---|
437 | 'foldable', // literals
|
---|
438 | '$',
|
---|
439 | '$[',
|
---|
440 | '${'
|
---|
441 | ],
|
---|
442 | 'sequences-builtin': [
|
---|
443 | 'member-eq?',
|
---|
444 | 'mismatch',
|
---|
445 | 'append',
|
---|
446 | 'assert-sequence=',
|
---|
447 | 'longer',
|
---|
448 | 'repetition',
|
---|
449 | 'clone-like',
|
---|
450 | '3sequence',
|
---|
451 | 'assert-sequence?',
|
---|
452 | 'last-index-from',
|
---|
453 | 'reversed',
|
---|
454 | 'index-from',
|
---|
455 | 'cut*',
|
---|
456 | 'pad-tail',
|
---|
457 | 'join-as',
|
---|
458 | 'remove-eq!',
|
---|
459 | 'concat-as',
|
---|
460 | 'but-last',
|
---|
461 | 'snip',
|
---|
462 | 'nths',
|
---|
463 | 'nth',
|
---|
464 | 'sequence',
|
---|
465 | 'longest',
|
---|
466 | 'slice?',
|
---|
467 | '<slice>',
|
---|
468 | 'remove-nth',
|
---|
469 | 'tail-slice',
|
---|
470 | 'empty?',
|
---|
471 | 'tail*',
|
---|
472 | 'member?',
|
---|
473 | 'virtual-sequence?',
|
---|
474 | 'set-length',
|
---|
475 | 'drop-prefix',
|
---|
476 | 'iota',
|
---|
477 | 'unclip',
|
---|
478 | 'bounds-error?',
|
---|
479 | 'unclip-last-slice',
|
---|
480 | 'non-negative-integer-expected',
|
---|
481 | 'non-negative-integer-expected?',
|
---|
482 | 'midpoint@',
|
---|
483 | 'longer?',
|
---|
484 | '?set-nth',
|
---|
485 | '?first',
|
---|
486 | 'rest-slice',
|
---|
487 | 'prepend-as',
|
---|
488 | 'prepend',
|
---|
489 | 'fourth',
|
---|
490 | 'sift',
|
---|
491 | 'subseq-start',
|
---|
492 | 'new-sequence',
|
---|
493 | '?last',
|
---|
494 | 'like',
|
---|
495 | 'first4',
|
---|
496 | '1sequence',
|
---|
497 | 'reverse',
|
---|
498 | 'slice',
|
---|
499 | 'virtual@',
|
---|
500 | 'repetition?',
|
---|
501 | 'set-last',
|
---|
502 | 'index',
|
---|
503 | '4sequence',
|
---|
504 | 'max-length',
|
---|
505 | 'set-second',
|
---|
506 | 'immutable-sequence',
|
---|
507 | 'first2',
|
---|
508 | 'first3',
|
---|
509 | 'supremum',
|
---|
510 | 'unclip-slice',
|
---|
511 | 'suffix!',
|
---|
512 | 'insert-nth',
|
---|
513 | 'tail',
|
---|
514 | '3append',
|
---|
515 | 'short',
|
---|
516 | 'suffix',
|
---|
517 | 'concat',
|
---|
518 | 'flip',
|
---|
519 | 'immutable?',
|
---|
520 | 'reverse!',
|
---|
521 | '2sequence',
|
---|
522 | 'sum',
|
---|
523 | 'delete-all',
|
---|
524 | 'indices',
|
---|
525 | 'snip-slice',
|
---|
526 | '<iota>',
|
---|
527 | 'check-slice',
|
---|
528 | 'sequence?',
|
---|
529 | 'head',
|
---|
530 | 'append-as',
|
---|
531 | 'halves',
|
---|
532 | 'sequence=',
|
---|
533 | 'collapse-slice',
|
---|
534 | '?second',
|
---|
535 | 'slice-error?',
|
---|
536 | 'product',
|
---|
537 | 'bounds-check?',
|
---|
538 | 'bounds-check',
|
---|
539 | 'immutable',
|
---|
540 | 'virtual-exemplar',
|
---|
541 | 'harvest',
|
---|
542 | 'remove',
|
---|
543 | 'pad-head',
|
---|
544 | 'last',
|
---|
545 | 'set-fourth',
|
---|
546 | 'cartesian-product',
|
---|
547 | 'remove-eq',
|
---|
548 | 'shorten',
|
---|
549 | 'shorter',
|
---|
550 | 'reversed?',
|
---|
551 | 'shorter?',
|
---|
552 | 'shortest',
|
---|
553 | 'head-slice',
|
---|
554 | 'pop*',
|
---|
555 | 'tail-slice*',
|
---|
556 | 'but-last-slice',
|
---|
557 | 'iota?',
|
---|
558 | 'append!',
|
---|
559 | 'cut-slice',
|
---|
560 | 'new-resizable',
|
---|
561 | 'head-slice*',
|
---|
562 | 'sequence-hashcode',
|
---|
563 | 'pop',
|
---|
564 | 'set-nth',
|
---|
565 | '?nth',
|
---|
566 | 'second',
|
---|
567 | 'join',
|
---|
568 | 'immutable-sequence?',
|
---|
569 | '<reversed>',
|
---|
570 | '3append-as',
|
---|
571 | 'virtual-sequence',
|
---|
572 | 'subseq?',
|
---|
573 | 'remove-nth!',
|
---|
574 | 'length',
|
---|
575 | 'last-index',
|
---|
576 | 'lengthen',
|
---|
577 | 'assert-sequence',
|
---|
578 | 'copy',
|
---|
579 | 'move',
|
---|
580 | 'third',
|
---|
581 | 'first',
|
---|
582 | 'tail?',
|
---|
583 | 'set-first',
|
---|
584 | 'prefix',
|
---|
585 | 'bounds-error',
|
---|
586 | '<repetition>',
|
---|
587 | 'exchange',
|
---|
588 | 'surround',
|
---|
589 | 'cut',
|
---|
590 | 'min-length',
|
---|
591 | 'set-third',
|
---|
592 | 'push-all',
|
---|
593 | 'head?',
|
---|
594 | 'subseq-start-from',
|
---|
595 | 'delete-slice',
|
---|
596 | 'rest',
|
---|
597 | 'sum-lengths',
|
---|
598 | 'head*',
|
---|
599 | 'infimum',
|
---|
600 | 'remove!',
|
---|
601 | 'glue',
|
---|
602 | 'slice-error',
|
---|
603 | 'subseq',
|
---|
604 | 'push',
|
---|
605 | 'replace-slice',
|
---|
606 | 'subseq-as',
|
---|
607 | 'unclip-last'
|
---|
608 | ],
|
---|
609 | 'math-builtin': [
|
---|
610 | 'number=',
|
---|
611 | 'next-power-of-2',
|
---|
612 | '?1+',
|
---|
613 | 'fp-special?',
|
---|
614 | 'imaginary-part',
|
---|
615 | 'float>bits',
|
---|
616 | 'number?',
|
---|
617 | 'fp-infinity?',
|
---|
618 | 'bignum?',
|
---|
619 | 'fp-snan?',
|
---|
620 | 'denominator',
|
---|
621 | 'gcd',
|
---|
622 | '*',
|
---|
623 | '+',
|
---|
624 | 'fp-bitwise=',
|
---|
625 | '-',
|
---|
626 | 'u>=',
|
---|
627 | '/',
|
---|
628 | '>=',
|
---|
629 | 'bitand',
|
---|
630 | 'power-of-2?',
|
---|
631 | 'log2-expects-positive',
|
---|
632 | 'neg?',
|
---|
633 | '<',
|
---|
634 | 'log2',
|
---|
635 | '>',
|
---|
636 | 'integer?',
|
---|
637 | 'number',
|
---|
638 | 'bits>double',
|
---|
639 | '2/',
|
---|
640 | 'zero?',
|
---|
641 | 'bits>float',
|
---|
642 | 'float?',
|
---|
643 | 'shift',
|
---|
644 | 'ratio?',
|
---|
645 | 'rect>',
|
---|
646 | 'even?',
|
---|
647 | 'ratio',
|
---|
648 | 'fp-sign',
|
---|
649 | 'bitnot',
|
---|
650 | '>fixnum',
|
---|
651 | 'complex?',
|
---|
652 | '/i',
|
---|
653 | 'integer>fixnum',
|
---|
654 | '/f',
|
---|
655 | 'sgn',
|
---|
656 | '>bignum',
|
---|
657 | 'next-float',
|
---|
658 | 'u<',
|
---|
659 | 'u>',
|
---|
660 | 'mod',
|
---|
661 | 'recip',
|
---|
662 | 'rational',
|
---|
663 | '>float',
|
---|
664 | '2^',
|
---|
665 | 'integer',
|
---|
666 | 'fixnum?',
|
---|
667 | 'neg',
|
---|
668 | 'fixnum',
|
---|
669 | 'sq',
|
---|
670 | 'bignum',
|
---|
671 | '>rect',
|
---|
672 | 'bit?',
|
---|
673 | 'fp-qnan?',
|
---|
674 | 'simple-gcd',
|
---|
675 | 'complex',
|
---|
676 | '<fp-nan>',
|
---|
677 | 'real',
|
---|
678 | '>fraction',
|
---|
679 | 'double>bits',
|
---|
680 | 'bitor',
|
---|
681 | 'rem',
|
---|
682 | 'fp-nan-payload',
|
---|
683 | 'real-part',
|
---|
684 | 'log2-expects-positive?',
|
---|
685 | 'prev-float',
|
---|
686 | 'align',
|
---|
687 | 'unordered?',
|
---|
688 | 'float',
|
---|
689 | 'fp-nan?',
|
---|
690 | 'abs',
|
---|
691 | 'bitxor',
|
---|
692 | 'integer>fixnum-strict',
|
---|
693 | 'u<=',
|
---|
694 | 'odd?',
|
---|
695 | '<=',
|
---|
696 | '/mod',
|
---|
697 | '>integer',
|
---|
698 | 'real?',
|
---|
699 | 'rational?',
|
---|
700 | 'numerator'
|
---|
701 | ] // that's all for now
|
---|
702 | }
|
---|
703 | Object.keys(builtins).forEach(function (k) {
|
---|
704 | factor[k].pattern = arrToWordsRegExp(builtins[k])
|
---|
705 | })
|
---|
706 | var combinators = [
|
---|
707 | // kernel
|
---|
708 | '2bi',
|
---|
709 | 'while',
|
---|
710 | '2tri',
|
---|
711 | 'bi*',
|
---|
712 | '4dip',
|
---|
713 | 'both?',
|
---|
714 | 'same?',
|
---|
715 | 'tri@',
|
---|
716 | 'curry',
|
---|
717 | 'prepose',
|
---|
718 | '3bi',
|
---|
719 | '?if',
|
---|
720 | 'tri*',
|
---|
721 | '2keep',
|
---|
722 | '3keep',
|
---|
723 | 'curried',
|
---|
724 | '2keepd',
|
---|
725 | 'when',
|
---|
726 | '2bi*',
|
---|
727 | '2tri*',
|
---|
728 | '4keep',
|
---|
729 | 'bi@',
|
---|
730 | 'keepdd',
|
---|
731 | 'do',
|
---|
732 | 'unless*',
|
---|
733 | 'tri-curry',
|
---|
734 | 'if*',
|
---|
735 | 'loop',
|
---|
736 | 'bi-curry*',
|
---|
737 | 'when*',
|
---|
738 | '2bi@',
|
---|
739 | '2tri@',
|
---|
740 | 'with',
|
---|
741 | '2with',
|
---|
742 | 'either?',
|
---|
743 | 'bi',
|
---|
744 | 'until',
|
---|
745 | '3dip',
|
---|
746 | '3curry',
|
---|
747 | 'tri-curry*',
|
---|
748 | 'tri-curry@',
|
---|
749 | 'bi-curry',
|
---|
750 | 'keepd',
|
---|
751 | 'compose',
|
---|
752 | '2dip',
|
---|
753 | 'if',
|
---|
754 | '3tri',
|
---|
755 | 'unless',
|
---|
756 | 'tuple',
|
---|
757 | 'keep',
|
---|
758 | '2curry',
|
---|
759 | 'tri',
|
---|
760 | 'most',
|
---|
761 | 'while*',
|
---|
762 | 'dip',
|
---|
763 | 'composed',
|
---|
764 | 'bi-curry@', // sequences
|
---|
765 | 'find-last-from',
|
---|
766 | 'trim-head-slice',
|
---|
767 | 'map-as',
|
---|
768 | 'each-from',
|
---|
769 | 'none?',
|
---|
770 | 'trim-tail',
|
---|
771 | 'partition',
|
---|
772 | 'if-empty',
|
---|
773 | 'accumulate*',
|
---|
774 | 'reject!',
|
---|
775 | 'find-from',
|
---|
776 | 'accumulate-as',
|
---|
777 | 'collector-for-as',
|
---|
778 | 'reject',
|
---|
779 | 'map',
|
---|
780 | 'map-sum',
|
---|
781 | 'accumulate!',
|
---|
782 | '2each-from',
|
---|
783 | 'follow',
|
---|
784 | 'supremum-by',
|
---|
785 | 'map!',
|
---|
786 | 'unless-empty',
|
---|
787 | 'collector',
|
---|
788 | 'padding',
|
---|
789 | 'reduce-index',
|
---|
790 | 'replicate-as',
|
---|
791 | 'infimum-by',
|
---|
792 | 'trim-tail-slice',
|
---|
793 | 'count',
|
---|
794 | 'find-index',
|
---|
795 | 'filter',
|
---|
796 | 'accumulate*!',
|
---|
797 | 'reject-as',
|
---|
798 | 'map-integers',
|
---|
799 | 'map-find',
|
---|
800 | 'reduce',
|
---|
801 | 'selector',
|
---|
802 | 'interleave',
|
---|
803 | '2map',
|
---|
804 | 'filter-as',
|
---|
805 | 'binary-reduce',
|
---|
806 | 'map-index-as',
|
---|
807 | 'find',
|
---|
808 | 'produce',
|
---|
809 | 'filter!',
|
---|
810 | 'replicate',
|
---|
811 | 'cartesian-map',
|
---|
812 | 'cartesian-each',
|
---|
813 | 'find-index-from',
|
---|
814 | 'map-find-last',
|
---|
815 | '3map-as',
|
---|
816 | '3map',
|
---|
817 | 'find-last',
|
---|
818 | 'selector-as',
|
---|
819 | '2map-as',
|
---|
820 | '2map-reduce',
|
---|
821 | 'accumulate',
|
---|
822 | 'each',
|
---|
823 | 'each-index',
|
---|
824 | 'accumulate*-as',
|
---|
825 | 'when-empty',
|
---|
826 | 'all?',
|
---|
827 | 'collector-as',
|
---|
828 | 'push-either',
|
---|
829 | 'new-like',
|
---|
830 | 'collector-for',
|
---|
831 | '2selector',
|
---|
832 | 'push-if',
|
---|
833 | '2all?',
|
---|
834 | 'map-reduce',
|
---|
835 | '3each',
|
---|
836 | 'any?',
|
---|
837 | 'trim-slice',
|
---|
838 | '2reduce',
|
---|
839 | 'change-nth',
|
---|
840 | 'produce-as',
|
---|
841 | '2each',
|
---|
842 | 'trim',
|
---|
843 | 'trim-head',
|
---|
844 | 'cartesian-find',
|
---|
845 | 'map-index', // math
|
---|
846 | 'if-zero',
|
---|
847 | 'each-integer',
|
---|
848 | 'unless-zero',
|
---|
849 | '(find-integer)',
|
---|
850 | 'when-zero',
|
---|
851 | 'find-last-integer',
|
---|
852 | '(all-integers?)',
|
---|
853 | 'times',
|
---|
854 | '(each-integer)',
|
---|
855 | 'find-integer',
|
---|
856 | 'all-integers?', // math.combinators
|
---|
857 | 'unless-negative',
|
---|
858 | 'if-positive',
|
---|
859 | 'when-positive',
|
---|
860 | 'when-negative',
|
---|
861 | 'unless-positive',
|
---|
862 | 'if-negative', // combinators
|
---|
863 | 'case',
|
---|
864 | '2cleave',
|
---|
865 | 'cond>quot',
|
---|
866 | 'case>quot',
|
---|
867 | '3cleave',
|
---|
868 | 'wrong-values',
|
---|
869 | 'to-fixed-point',
|
---|
870 | 'alist>quot',
|
---|
871 | 'cond',
|
---|
872 | 'cleave',
|
---|
873 | 'call-effect',
|
---|
874 | 'recursive-hashcode',
|
---|
875 | 'spread',
|
---|
876 | 'deep-spread>quot', // combinators.short-circuit
|
---|
877 | '2||',
|
---|
878 | '0||',
|
---|
879 | 'n||',
|
---|
880 | '0&&',
|
---|
881 | '2&&',
|
---|
882 | '3||',
|
---|
883 | '1||',
|
---|
884 | '1&&',
|
---|
885 | 'n&&',
|
---|
886 | '3&&', // combinators.smart
|
---|
887 | 'smart-unless*',
|
---|
888 | 'keep-inputs',
|
---|
889 | 'reduce-outputs',
|
---|
890 | 'smart-when*',
|
---|
891 | 'cleave>array',
|
---|
892 | 'smart-with',
|
---|
893 | 'smart-apply',
|
---|
894 | 'smart-if',
|
---|
895 | 'inputs/outputs',
|
---|
896 | 'output>sequence-n',
|
---|
897 | 'map-outputs',
|
---|
898 | 'map-reduce-outputs',
|
---|
899 | 'dropping',
|
---|
900 | 'output>array',
|
---|
901 | 'smart-map-reduce',
|
---|
902 | 'smart-2map-reduce',
|
---|
903 | 'output>array-n',
|
---|
904 | 'nullary',
|
---|
905 | 'input<sequence',
|
---|
906 | 'append-outputs',
|
---|
907 | 'drop-inputs',
|
---|
908 | 'inputs',
|
---|
909 | 'smart-2reduce',
|
---|
910 | 'drop-outputs',
|
---|
911 | 'smart-reduce',
|
---|
912 | 'preserving',
|
---|
913 | 'smart-when',
|
---|
914 | 'outputs',
|
---|
915 | 'append-outputs-as',
|
---|
916 | 'smart-unless',
|
---|
917 | 'smart-if*',
|
---|
918 | 'sum-outputs',
|
---|
919 | 'input<sequence-unsafe',
|
---|
920 | 'output>sequence' // tafn
|
---|
921 | ]
|
---|
922 | factor.combinators.pattern = arrToWordsRegExp(combinators)
|
---|
923 | Prism.languages.factor = factor
|
---|
924 | })(Prism)
|
---|
925 | }
|
---|