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