]>
git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/space-pen/node_modules/grim/node_modules/coffeestack/node_modules/coffee-script/lib/coffee-script/grammar.js
cfcab24cf3c3380e658c997b516a82558af5270d
1 // Generated by CoffeeScript 1.8.0
3 var Parser
, alt
, alternatives
, grammar
, name
, o
, operators
, token
, tokens
, unwrap
;
5 Parser
= require('jison').Parser
;
7 unwrap
= /^function\s*\(\)\s*\{\s*return\s*([\s\S]*);\s*\}/;
9 o = function(patternString
, action
, options
) {
10 var addLocationDataFn
, match
, patternCount
;
11 patternString
= patternString
.replace(/\s{2,}/g, ' ');
12 patternCount
= patternString
.split(' ').length
;
14 return [patternString
, '$$ = $1;', options
];
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
) {
21 return "yy.addLocationDataFn(@" + first
+ ")";
23 return "yy.addLocationDataFn(@" + first
+ ", @" + last
+ ")";
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
];
38 o('Line', function() {
39 return Block
.wrap([$1]);
40 }), o('Body TERMINATOR Line', function() {
42 }), o('Body TERMINATOR')
44 Line: [o('Expression'), o('Statement')],
46 o('Return'), o('Comment'), o('STATEMENT', function() {
47 return new Literal($1);
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')],
52 o('INDENT OUTDENT', function() {
54 }), o('INDENT Body OUTDENT', function() {
59 o('IDENTIFIER', function() {
60 return new Literal($1);
64 o('NUMBER', function() {
65 return new Literal($1);
66 }), o('STRING', function() {
67 return new Literal($1);
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() {
79 }), o('NULL', function() {
81 }), o('BOOL', function() {
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);
95 o('ObjAssignable', function() {
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');
103 ObjAssignable: [o('Identifier'), o('AlphaNumeric'), o('ThisProperty')],
105 o('RETURN Expression', function() {
106 return new Return($2);
107 }), o('RETURN', function() {
112 o('HERECOMMENT', function() {
113 return new Comment($1);
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);
126 }), o('=>', function() {
130 OptComma: [o(''), o(',')],
134 }), o('Param', function() {
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);
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
;
155 ParamVar: [o('Identifier'), o('ThisProperty'), o('Array'), o('Object')],
157 o('Expression ...', function() {
158 return new Splat($1);
162 o('Identifier', function() {
163 return new Value($1);
164 }), o('Value Accessor', function() {
166 }), o('Invocation Accessor', function() {
167 return new Value($1, [].concat($2));
168 }), o('ThisProperty')
171 o('SimpleAssignable'), o('Array', function() {
172 return new Value($1);
173 }), o('Object', function() {
174 return new Value($1);
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);
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'));
200 o('INDEX_START IndexValue INDEX_END', function() {
202 }), o('INDEX_SOAK Index', function() {
209 o('Expression', function() {
210 return new Index($1);
211 }), o('Slice', function() {
212 return new Slice($1);
216 o('{ AssignList OptComma }', function() {
217 return new Obj($2, $1.generated
);
223 }), o('AssignObj', function() {
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);
234 o('CLASS', function() {
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);
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);
266 }), o('FUNC_EXIST', function() {
271 o('CALL_START CALL_END', function() {
273 }), o('CALL_START ArgList OptComma CALL_END', function() {
278 o('THIS', function() {
279 return new Value(new Literal('this'));
280 }), o('@', function() {
281 return new Value(new Literal('this'));
285 o('@ Identifier', function() {
286 return new Value(LOC(1)(new Literal('this')), [LOC(2)(new Access($2))], 'this');
290 o('[ ]', function() {
292 }), o('[ ArgList OptComma ]', function() {
299 }), o('...', function() {
304 o('[ Expression RangeDots Expression ]', function() {
305 return new Range($2, $4, $3);
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);
320 o('Arg', function() {
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() {
328 }), o('ArgList OptComma INDENT ArgList OptComma OUTDENT', function() {
329 return $1.concat($4);
333 o('Expression'), o('Splat'), o('...', function() {
334 return new Expansion
;
338 o('Expression'), o('SimpleArgs , Expression', function() {
339 return [].concat($1, $3);
343 o('TRY Block', function() {
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);
354 o('CATCH Identifier Block', function() {
356 }), o('CATCH Object Block', function() {
357 return [LOC(2)(new Value($2)), $3];
358 }), o('CATCH Block', function() {
363 o('THROW Expression', function() {
364 return new Throw($2);
368 o('( Body )', function() {
369 return new Parens($2);
370 }), o('( INDENT Body OUTDENT )', function() {
371 return new Parens($3);
375 o('WHILE Expression', function() {
376 return new While($2);
377 }), o('WHILE Expression WHEN Expression', function() {
378 return new While($2, {
381 }), o('UNTIL Expression', function() {
382 return new While($2, {
385 }), o('UNTIL Expression WHEN Expression', function() {
386 return new While($2, {
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() {
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])));
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);
420 o('FOR Range', function() {
422 source: LOC(2)(new Value($2))
424 }), o('ForStart ForSource', function() {
432 o('FOR ForVariables', function() {
434 }), o('FOR OWN ForVariables', function() {
440 o('Identifier'), o('ThisProperty'), o('Array', function() {
441 return new Value($1);
442 }), o('Object', function() {
443 return new Value($1);
447 o('ForValue', function() {
449 }), o('ForValue , ForValue', function() {
454 o('FORIN Expression', function() {
458 }), o('FOROF Expression', function() {
463 }), o('FORIN Expression WHEN Expression', function() {
468 }), o('FOROF Expression WHEN Expression', function() {
474 }), o('FORIN Expression BY Expression', function() {
479 }), o('FORIN Expression WHEN Expression BY Expression', function() {
485 }), o('FORIN Expression BY Expression WHEN Expression', function() {
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);
505 o('When'), o('Whens When', function() {
506 return $1.concat($2);
510 o('LEADING_WHEN SimpleArgs Block', function() {
512 }), o('LEADING_WHEN SimpleArgs Block TERMINATOR', function() {
517 o('IF Expression Block', function() {
518 return new If($2, $3, {
521 }), o('IfBlock ELSE IF Expression Block', function() {
522 return $1.addElse(LOC(3, 5)(new If($4, $5, {
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])), {
535 }), o('Expression POST_IF Expression', function() {
536 return new If($3, LOC(1)(Block
.wrap([$1])), {
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);
551 }), o('+ Expression', (function() {
552 return new Op('+', $2);
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();
583 return new Op($2, $1, $3);
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);
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']];
601 for (name
in grammar
) {
602 alternatives
= grammar
[name
];
603 grammar
[name
] = (function() {
604 var _i
, _j
, _len
, _len1
, _ref
, _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
++) {
611 if (!grammar
[token
]) {
615 if (name
=== 'Root') {
616 alt
[1] = "return " + alt
[1];
624 exports
.parser
= new Parser({
625 tokens: tokens
.join(' '),
627 operators: operators
.reverse(),