]> git.r.bdr.sh - rbdr/dotfiles/blob
cfcab24cf3c3380e658c997b516a82558af5270d
[rbdr/dotfiles] /
1 // Generated by CoffeeScript 1.8.0
2 (function() {
3 var Parser, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
4
5 Parser = require('jison').Parser;
6
7 unwrap = /^function\s*\(\)\s*\{\s*return\s*([\s\S]*);\s*\}/;
8
9 o = function(patternString, action, options) {
10 var addLocationDataFn, match, patternCount;
11 patternString = patternString.replace(/\s{2,}/g, ' ');
12 patternCount = patternString.split(' ').length;
13 if (!action) {
14 return [patternString, '$$ = $1;', options];
15 }
16 action = (match = unwrap.exec(action)) ? match[1] : "(" + action + "())";
17 action = action.replace(/\bnew /g, '$&yy.');
18 action = action.replace(/\b(?:Block\.wrap|extend)\b/g, 'yy.$&');
19 addLocationDataFn = function(first, last) {
20 if (!last) {
21 return "yy.addLocationDataFn(@" + first + ")";
22 } else {
23 return "yy.addLocationDataFn(@" + first + ", @" + last + ")";
24 }
25 };
26 action = action.replace(/LOC\(([0-9]*)\)/g, addLocationDataFn('$1'));
27 action = action.replace(/LOC\(([0-9]*),\s*([0-9]*)\)/g, addLocationDataFn('$1', '$2'));
28 return [patternString, "$$ = " + (addLocationDataFn(1, patternCount)) + "(" + action + ");", options];
29 };
30
31 grammar = {
32 Root: [
33 o('', function() {
34 return new Block;
35 }), o('Body')
36 ],
37 Body: [
38 o('Line', function() {
39 return Block.wrap([$1]);
40 }), o('Body TERMINATOR Line', function() {
41 return $1.push($3);
42 }), o('Body TERMINATOR')
43 ],
44 Line: [o('Expression'), o('Statement')],
45 Statement: [
46 o('Return'), o('Comment'), o('STATEMENT', function() {
47 return new Literal($1);
48 })
49 ],
50 Expression: [o('Value'), o('Invocation'), o('Code'), o('Operation'), o('Assign'), o('If'), o('Try'), o('While'), o('For'), o('Switch'), o('Class'), o('Throw')],
51 Block: [
52 o('INDENT OUTDENT', function() {
53 return new Block;
54 }), o('INDENT Body OUTDENT', function() {
55 return $2;
56 })
57 ],
58 Identifier: [
59 o('IDENTIFIER', function() {
60 return new Literal($1);
61 })
62 ],
63 AlphaNumeric: [
64 o('NUMBER', function() {
65 return new Literal($1);
66 }), o('STRING', function() {
67 return new Literal($1);
68 })
69 ],
70 Literal: [
71 o('AlphaNumeric'), o('JS', function() {
72 return new Literal($1);
73 }), o('REGEX', function() {
74 return new Literal($1);
75 }), o('DEBUGGER', function() {
76 return new Literal($1);
77 }), o('UNDEFINED', function() {
78 return new Undefined;
79 }), o('NULL', function() {
80 return new Null;
81 }), o('BOOL', function() {
82 return new Bool($1);
83 })
84 ],
85 Assign: [
86 o('Assignable = Expression', function() {
87 return new Assign($1, $3);
88 }), o('Assignable = TERMINATOR Expression', function() {
89 return new Assign($1, $4);
90 }), o('Assignable = INDENT Expression OUTDENT', function() {
91 return new Assign($1, $4);
92 })
93 ],
94 AssignObj: [
95 o('ObjAssignable', function() {
96 return new Value($1);
97 }), o('ObjAssignable : Expression', function() {
98 return new Assign(LOC(1)(new Value($1)), $3, 'object');
99 }), o('ObjAssignable : INDENT Expression OUTDENT', function() {
100 return new Assign(LOC(1)(new Value($1)), $4, 'object');
101 }), o('Comment')
102 ],
103 ObjAssignable: [o('Identifier'), o('AlphaNumeric'), o('ThisProperty')],
104 Return: [
105 o('RETURN Expression', function() {
106 return new Return($2);
107 }), o('RETURN', function() {
108 return new Return;
109 })
110 ],
111 Comment: [
112 o('HERECOMMENT', function() {
113 return new Comment($1);
114 })
115 ],
116 Code: [
117 o('PARAM_START ParamList PARAM_END FuncGlyph Block', function() {
118 return new Code($2, $5, $4);
119 }), o('FuncGlyph Block', function() {
120 return new Code([], $2, $1);
121 })
122 ],
123 FuncGlyph: [
124 o('->', function() {
125 return 'func';
126 }), o('=>', function() {
127 return 'boundfunc';
128 })
129 ],
130 OptComma: [o(''), o(',')],
131 ParamList: [
132 o('', function() {
133 return [];
134 }), o('Param', function() {
135 return [$1];
136 }), o('ParamList , Param', function() {
137 return $1.concat($3);
138 }), o('ParamList OptComma TERMINATOR Param', function() {
139 return $1.concat($4);
140 }), o('ParamList OptComma INDENT ParamList OptComma OUTDENT', function() {
141 return $1.concat($4);
142 })
143 ],
144 Param: [
145 o('ParamVar', function() {
146 return new Param($1);
147 }), o('ParamVar ...', function() {
148 return new Param($1, null, true);
149 }), o('ParamVar = Expression', function() {
150 return new Param($1, $3);
151 }), o('...', function() {
152 return new Expansion;
153 })
154 ],
155 ParamVar: [o('Identifier'), o('ThisProperty'), o('Array'), o('Object')],
156 Splat: [
157 o('Expression ...', function() {
158 return new Splat($1);
159 })
160 ],
161 SimpleAssignable: [
162 o('Identifier', function() {
163 return new Value($1);
164 }), o('Value Accessor', function() {
165 return $1.add($2);
166 }), o('Invocation Accessor', function() {
167 return new Value($1, [].concat($2));
168 }), o('ThisProperty')
169 ],
170 Assignable: [
171 o('SimpleAssignable'), o('Array', function() {
172 return new Value($1);
173 }), o('Object', function() {
174 return new Value($1);
175 })
176 ],
177 Value: [
178 o('Assignable'), o('Literal', function() {
179 return new Value($1);
180 }), o('Parenthetical', function() {
181 return new Value($1);
182 }), o('Range', function() {
183 return new Value($1);
184 }), o('This')
185 ],
186 Accessor: [
187 o('. Identifier', function() {
188 return new Access($2);
189 }), o('?. Identifier', function() {
190 return new Access($2, 'soak');
191 }), o(':: Identifier', function() {
192 return [LOC(1)(new Access(new Literal('prototype'))), LOC(2)(new Access($2))];
193 }), o('?:: Identifier', function() {
194 return [LOC(1)(new Access(new Literal('prototype'), 'soak')), LOC(2)(new Access($2))];
195 }), o('::', function() {
196 return new Access(new Literal('prototype'));
197 }), o('Index')
198 ],
199 Index: [
200 o('INDEX_START IndexValue INDEX_END', function() {
201 return $2;
202 }), o('INDEX_SOAK Index', function() {
203 return extend($2, {
204 soak: true
205 });
206 })
207 ],
208 IndexValue: [
209 o('Expression', function() {
210 return new Index($1);
211 }), o('Slice', function() {
212 return new Slice($1);
213 })
214 ],
215 Object: [
216 o('{ AssignList OptComma }', function() {
217 return new Obj($2, $1.generated);
218 })
219 ],
220 AssignList: [
221 o('', function() {
222 return [];
223 }), o('AssignObj', function() {
224 return [$1];
225 }), o('AssignList , AssignObj', function() {
226 return $1.concat($3);
227 }), o('AssignList OptComma TERMINATOR AssignObj', function() {
228 return $1.concat($4);
229 }), o('AssignList OptComma INDENT AssignList OptComma OUTDENT', function() {
230 return $1.concat($4);
231 })
232 ],
233 Class: [
234 o('CLASS', function() {
235 return new Class;
236 }), o('CLASS Block', function() {
237 return new Class(null, null, $2);
238 }), o('CLASS EXTENDS Expression', function() {
239 return new Class(null, $3);
240 }), o('CLASS EXTENDS Expression Block', function() {
241 return new Class(null, $3, $4);
242 }), o('CLASS SimpleAssignable', function() {
243 return new Class($2);
244 }), o('CLASS SimpleAssignable Block', function() {
245 return new Class($2, null, $3);
246 }), o('CLASS SimpleAssignable EXTENDS Expression', function() {
247 return new Class($2, $4);
248 }), o('CLASS SimpleAssignable EXTENDS Expression Block', function() {
249 return new Class($2, $4, $5);
250 })
251 ],
252 Invocation: [
253 o('Value OptFuncExist Arguments', function() {
254 return new Call($1, $3, $2);
255 }), o('Invocation OptFuncExist Arguments', function() {
256 return new Call($1, $3, $2);
257 }), o('SUPER', function() {
258 return new Call('super', [new Splat(new Literal('arguments'))]);
259 }), o('SUPER Arguments', function() {
260 return new Call('super', $2);
261 })
262 ],
263 OptFuncExist: [
264 o('', function() {
265 return false;
266 }), o('FUNC_EXIST', function() {
267 return true;
268 })
269 ],
270 Arguments: [
271 o('CALL_START CALL_END', function() {
272 return [];
273 }), o('CALL_START ArgList OptComma CALL_END', function() {
274 return $2;
275 })
276 ],
277 This: [
278 o('THIS', function() {
279 return new Value(new Literal('this'));
280 }), o('@', function() {
281 return new Value(new Literal('this'));
282 })
283 ],
284 ThisProperty: [
285 o('@ Identifier', function() {
286 return new Value(LOC(1)(new Literal('this')), [LOC(2)(new Access($2))], 'this');
287 })
288 ],
289 Array: [
290 o('[ ]', function() {
291 return new Arr([]);
292 }), o('[ ArgList OptComma ]', function() {
293 return new Arr($2);
294 })
295 ],
296 RangeDots: [
297 o('..', function() {
298 return 'inclusive';
299 }), o('...', function() {
300 return 'exclusive';
301 })
302 ],
303 Range: [
304 o('[ Expression RangeDots Expression ]', function() {
305 return new Range($2, $4, $3);
306 })
307 ],
308 Slice: [
309 o('Expression RangeDots Expression', function() {
310 return new Range($1, $3, $2);
311 }), o('Expression RangeDots', function() {
312 return new Range($1, null, $2);
313 }), o('RangeDots Expression', function() {
314 return new Range(null, $2, $1);
315 }), o('RangeDots', function() {
316 return new Range(null, null, $1);
317 })
318 ],
319 ArgList: [
320 o('Arg', function() {
321 return [$1];
322 }), o('ArgList , Arg', function() {
323 return $1.concat($3);
324 }), o('ArgList OptComma TERMINATOR Arg', function() {
325 return $1.concat($4);
326 }), o('INDENT ArgList OptComma OUTDENT', function() {
327 return $2;
328 }), o('ArgList OptComma INDENT ArgList OptComma OUTDENT', function() {
329 return $1.concat($4);
330 })
331 ],
332 Arg: [
333 o('Expression'), o('Splat'), o('...', function() {
334 return new Expansion;
335 })
336 ],
337 SimpleArgs: [
338 o('Expression'), o('SimpleArgs , Expression', function() {
339 return [].concat($1, $3);
340 })
341 ],
342 Try: [
343 o('TRY Block', function() {
344 return new Try($2);
345 }), o('TRY Block Catch', function() {
346 return new Try($2, $3[0], $3[1]);
347 }), o('TRY Block FINALLY Block', function() {
348 return new Try($2, null, null, $4);
349 }), o('TRY Block Catch FINALLY Block', function() {
350 return new Try($2, $3[0], $3[1], $5);
351 })
352 ],
353 Catch: [
354 o('CATCH Identifier Block', function() {
355 return [$2, $3];
356 }), o('CATCH Object Block', function() {
357 return [LOC(2)(new Value($2)), $3];
358 }), o('CATCH Block', function() {
359 return [null, $2];
360 })
361 ],
362 Throw: [
363 o('THROW Expression', function() {
364 return new Throw($2);
365 })
366 ],
367 Parenthetical: [
368 o('( Body )', function() {
369 return new Parens($2);
370 }), o('( INDENT Body OUTDENT )', function() {
371 return new Parens($3);
372 })
373 ],
374 WhileSource: [
375 o('WHILE Expression', function() {
376 return new While($2);
377 }), o('WHILE Expression WHEN Expression', function() {
378 return new While($2, {
379 guard: $4
380 });
381 }), o('UNTIL Expression', function() {
382 return new While($2, {
383 invert: true
384 });
385 }), o('UNTIL Expression WHEN Expression', function() {
386 return new While($2, {
387 invert: true,
388 guard: $4
389 });
390 })
391 ],
392 While: [
393 o('WhileSource Block', function() {
394 return $1.addBody($2);
395 }), o('Statement WhileSource', function() {
396 return $2.addBody(LOC(1)(Block.wrap([$1])));
397 }), o('Expression WhileSource', function() {
398 return $2.addBody(LOC(1)(Block.wrap([$1])));
399 }), o('Loop', function() {
400 return $1;
401 })
402 ],
403 Loop: [
404 o('LOOP Block', function() {
405 return new While(LOC(1)(new Literal('true'))).addBody($2);
406 }), o('LOOP Expression', function() {
407 return new While(LOC(1)(new Literal('true'))).addBody(LOC(2)(Block.wrap([$2])));
408 })
409 ],
410 For: [
411 o('Statement ForBody', function() {
412 return new For($1, $2);
413 }), o('Expression ForBody', function() {
414 return new For($1, $2);
415 }), o('ForBody Block', function() {
416 return new For($2, $1);
417 })
418 ],
419 ForBody: [
420 o('FOR Range', function() {
421 return {
422 source: LOC(2)(new Value($2))
423 };
424 }), o('ForStart ForSource', function() {
425 $2.own = $1.own;
426 $2.name = $1[0];
427 $2.index = $1[1];
428 return $2;
429 })
430 ],
431 ForStart: [
432 o('FOR ForVariables', function() {
433 return $2;
434 }), o('FOR OWN ForVariables', function() {
435 $3.own = true;
436 return $3;
437 })
438 ],
439 ForValue: [
440 o('Identifier'), o('ThisProperty'), o('Array', function() {
441 return new Value($1);
442 }), o('Object', function() {
443 return new Value($1);
444 })
445 ],
446 ForVariables: [
447 o('ForValue', function() {
448 return [$1];
449 }), o('ForValue , ForValue', function() {
450 return [$1, $3];
451 })
452 ],
453 ForSource: [
454 o('FORIN Expression', function() {
455 return {
456 source: $2
457 };
458 }), o('FOROF Expression', function() {
459 return {
460 source: $2,
461 object: true
462 };
463 }), o('FORIN Expression WHEN Expression', function() {
464 return {
465 source: $2,
466 guard: $4
467 };
468 }), o('FOROF Expression WHEN Expression', function() {
469 return {
470 source: $2,
471 guard: $4,
472 object: true
473 };
474 }), o('FORIN Expression BY Expression', function() {
475 return {
476 source: $2,
477 step: $4
478 };
479 }), o('FORIN Expression WHEN Expression BY Expression', function() {
480 return {
481 source: $2,
482 guard: $4,
483 step: $6
484 };
485 }), o('FORIN Expression BY Expression WHEN Expression', function() {
486 return {
487 source: $2,
488 step: $4,
489 guard: $6
490 };
491 })
492 ],
493 Switch: [
494 o('SWITCH Expression INDENT Whens OUTDENT', function() {
495 return new Switch($2, $4);
496 }), o('SWITCH Expression INDENT Whens ELSE Block OUTDENT', function() {
497 return new Switch($2, $4, $6);
498 }), o('SWITCH INDENT Whens OUTDENT', function() {
499 return new Switch(null, $3);
500 }), o('SWITCH INDENT Whens ELSE Block OUTDENT', function() {
501 return new Switch(null, $3, $5);
502 })
503 ],
504 Whens: [
505 o('When'), o('Whens When', function() {
506 return $1.concat($2);
507 })
508 ],
509 When: [
510 o('LEADING_WHEN SimpleArgs Block', function() {
511 return [[$2, $3]];
512 }), o('LEADING_WHEN SimpleArgs Block TERMINATOR', function() {
513 return [[$2, $3]];
514 })
515 ],
516 IfBlock: [
517 o('IF Expression Block', function() {
518 return new If($2, $3, {
519 type: $1
520 });
521 }), o('IfBlock ELSE IF Expression Block', function() {
522 return $1.addElse(LOC(3, 5)(new If($4, $5, {
523 type: $3
524 })));
525 })
526 ],
527 If: [
528 o('IfBlock'), o('IfBlock ELSE Block', function() {
529 return $1.addElse($3);
530 }), o('Statement POST_IF Expression', function() {
531 return new If($3, LOC(1)(Block.wrap([$1])), {
532 type: $2,
533 statement: true
534 });
535 }), o('Expression POST_IF Expression', function() {
536 return new If($3, LOC(1)(Block.wrap([$1])), {
537 type: $2,
538 statement: true
539 });
540 })
541 ],
542 Operation: [
543 o('UNARY Expression', function() {
544 return new Op($1, $2);
545 }), o('UNARY_MATH Expression', function() {
546 return new Op($1, $2);
547 }), o('- Expression', (function() {
548 return new Op('-', $2);
549 }), {
550 prec: 'UNARY_MATH'
551 }), o('+ Expression', (function() {
552 return new Op('+', $2);
553 }), {
554 prec: 'UNARY_MATH'
555 }), o('-- SimpleAssignable', function() {
556 return new Op('--', $2);
557 }), o('++ SimpleAssignable', function() {
558 return new Op('++', $2);
559 }), o('SimpleAssignable --', function() {
560 return new Op('--', $1, null, true);
561 }), o('SimpleAssignable ++', function() {
562 return new Op('++', $1, null, true);
563 }), o('Expression ?', function() {
564 return new Existence($1);
565 }), o('Expression + Expression', function() {
566 return new Op('+', $1, $3);
567 }), o('Expression - Expression', function() {
568 return new Op('-', $1, $3);
569 }), o('Expression MATH Expression', function() {
570 return new Op($2, $1, $3);
571 }), o('Expression ** Expression', function() {
572 return new Op($2, $1, $3);
573 }), o('Expression SHIFT Expression', function() {
574 return new Op($2, $1, $3);
575 }), o('Expression COMPARE Expression', function() {
576 return new Op($2, $1, $3);
577 }), o('Expression LOGIC Expression', function() {
578 return new Op($2, $1, $3);
579 }), o('Expression RELATION Expression', function() {
580 if ($2.charAt(0) === '!') {
581 return new Op($2.slice(1), $1, $3).invert();
582 } else {
583 return new Op($2, $1, $3);
584 }
585 }), o('SimpleAssignable COMPOUND_ASSIGN Expression', function() {
586 return new Assign($1, $3, $2);
587 }), o('SimpleAssignable COMPOUND_ASSIGN INDENT Expression OUTDENT', function() {
588 return new Assign($1, $4, $2);
589 }), o('SimpleAssignable COMPOUND_ASSIGN TERMINATOR Expression', function() {
590 return new Assign($1, $4, $2);
591 }), o('SimpleAssignable EXTENDS Expression', function() {
592 return new Extends($1, $3);
593 })
594 ]
595 };
596
597 operators = [['left', '.', '?.', '::', '?::'], ['left', 'CALL_START', 'CALL_END'], ['nonassoc', '++', '--'], ['left', '?'], ['right', 'UNARY'], ['right', '**'], ['right', 'UNARY_MATH'], ['left', 'MATH'], ['left', '+', '-'], ['left', 'SHIFT'], ['left', 'RELATION'], ['left', 'COMPARE'], ['left', 'LOGIC'], ['nonassoc', 'INDENT', 'OUTDENT'], ['right', '=', ':', 'COMPOUND_ASSIGN', 'RETURN', 'THROW', 'EXTENDS'], ['right', 'FORIN', 'FOROF', 'BY', 'WHEN'], ['right', 'IF', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS'], ['left', 'POST_IF']];
598
599 tokens = [];
600
601 for (name in grammar) {
602 alternatives = grammar[name];
603 grammar[name] = (function() {
604 var _i, _j, _len, _len1, _ref, _results;
605 _results = [];
606 for (_i = 0, _len = alternatives.length; _i < _len; _i++) {
607 alt = alternatives[_i];
608 _ref = alt[0].split(' ');
609 for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
610 token = _ref[_j];
611 if (!grammar[token]) {
612 tokens.push(token);
613 }
614 }
615 if (name === 'Root') {
616 alt[1] = "return " + alt[1];
617 }
618 _results.push(alt);
619 }
620 return _results;
621 })();
622 }
623
624 exports.parser = new Parser({
625 tokens: tokens.join(' '),
626 bnf: grammar,
627 operators: operators.reverse(),
628 startSymbol: 'Root'
629 });
630
631 }).call(this);