"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/coffee-script/lib/coffee-script/grammar.js" (7 Feb 2017, 20056 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Generated by CoffeeScript 1.9.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('FOR Range BY Expression', function() {
  425         return {
  426           source: LOC(2)(new Value($2)),
  427           step: $4
  428         };
  429       }), o('ForStart ForSource', function() {
  430         $2.own = $1.own;
  431         $2.name = $1[0];
  432         $2.index = $1[1];
  433         return $2;
  434       })
  435     ],
  436     ForStart: [
  437       o('FOR ForVariables', function() {
  438         return $2;
  439       }), o('FOR OWN ForVariables', function() {
  440         $3.own = true;
  441         return $3;
  442       })
  443     ],
  444     ForValue: [
  445       o('Identifier'), o('ThisProperty'), o('Array', function() {
  446         return new Value($1);
  447       }), o('Object', function() {
  448         return new Value($1);
  449       })
  450     ],
  451     ForVariables: [
  452       o('ForValue', function() {
  453         return [$1];
  454       }), o('ForValue , ForValue', function() {
  455         return [$1, $3];
  456       })
  457     ],
  458     ForSource: [
  459       o('FORIN Expression', function() {
  460         return {
  461           source: $2
  462         };
  463       }), o('FOROF Expression', function() {
  464         return {
  465           source: $2,
  466           object: true
  467         };
  468       }), o('FORIN Expression WHEN Expression', function() {
  469         return {
  470           source: $2,
  471           guard: $4
  472         };
  473       }), o('FOROF Expression WHEN Expression', function() {
  474         return {
  475           source: $2,
  476           guard: $4,
  477           object: true
  478         };
  479       }), o('FORIN Expression BY Expression', function() {
  480         return {
  481           source: $2,
  482           step: $4
  483         };
  484       }), o('FORIN Expression WHEN Expression BY Expression', function() {
  485         return {
  486           source: $2,
  487           guard: $4,
  488           step: $6
  489         };
  490       }), o('FORIN Expression BY Expression WHEN Expression', function() {
  491         return {
  492           source: $2,
  493           step: $4,
  494           guard: $6
  495         };
  496       })
  497     ],
  498     Switch: [
  499       o('SWITCH Expression INDENT Whens OUTDENT', function() {
  500         return new Switch($2, $4);
  501       }), o('SWITCH Expression INDENT Whens ELSE Block OUTDENT', function() {
  502         return new Switch($2, $4, $6);
  503       }), o('SWITCH INDENT Whens OUTDENT', function() {
  504         return new Switch(null, $3);
  505       }), o('SWITCH INDENT Whens ELSE Block OUTDENT', function() {
  506         return new Switch(null, $3, $5);
  507       })
  508     ],
  509     Whens: [
  510       o('When'), o('Whens When', function() {
  511         return $1.concat($2);
  512       })
  513     ],
  514     When: [
  515       o('LEADING_WHEN SimpleArgs Block', function() {
  516         return [[$2, $3]];
  517       }), o('LEADING_WHEN SimpleArgs Block TERMINATOR', function() {
  518         return [[$2, $3]];
  519       })
  520     ],
  521     IfBlock: [
  522       o('IF Expression Block', function() {
  523         return new If($2, $3, {
  524           type: $1
  525         });
  526       }), o('IfBlock ELSE IF Expression Block', function() {
  527         return $1.addElse(LOC(3, 5)(new If($4, $5, {
  528           type: $3
  529         })));
  530       })
  531     ],
  532     If: [
  533       o('IfBlock'), o('IfBlock ELSE Block', function() {
  534         return $1.addElse($3);
  535       }), o('Statement  POST_IF Expression', function() {
  536         return new If($3, LOC(1)(Block.wrap([$1])), {
  537           type: $2,
  538           statement: true
  539         });
  540       }), o('Expression POST_IF Expression', function() {
  541         return new If($3, LOC(1)(Block.wrap([$1])), {
  542           type: $2,
  543           statement: true
  544         });
  545       })
  546     ],
  547     Operation: [
  548       o('UNARY Expression', function() {
  549         return new Op($1, $2);
  550       }), o('UNARY_MATH Expression', function() {
  551         return new Op($1, $2);
  552       }), o('-     Expression', (function() {
  553         return new Op('-', $2);
  554       }), {
  555         prec: 'UNARY_MATH'
  556       }), o('+     Expression', (function() {
  557         return new Op('+', $2);
  558       }), {
  559         prec: 'UNARY_MATH'
  560       }), o('YIELD Statement', function() {
  561         return new Op($1, $2);
  562       }), o('YIELD Expression', function() {
  563         return new Op($1, $2);
  564       }), o('YIELD FROM Expression', function() {
  565         return new Op($1.concat($2), $3);
  566       }), o('-- SimpleAssignable', function() {
  567         return new Op('--', $2);
  568       }), o('++ SimpleAssignable', function() {
  569         return new Op('++', $2);
  570       }), o('SimpleAssignable --', function() {
  571         return new Op('--', $1, null, true);
  572       }), o('SimpleAssignable ++', function() {
  573         return new Op('++', $1, null, true);
  574       }), o('Expression ?', function() {
  575         return new Existence($1);
  576       }), o('Expression +  Expression', function() {
  577         return new Op('+', $1, $3);
  578       }), o('Expression -  Expression', function() {
  579         return new Op('-', $1, $3);
  580       }), o('Expression MATH     Expression', function() {
  581         return new Op($2, $1, $3);
  582       }), o('Expression **       Expression', function() {
  583         return new Op($2, $1, $3);
  584       }), o('Expression SHIFT    Expression', function() {
  585         return new Op($2, $1, $3);
  586       }), o('Expression COMPARE  Expression', function() {
  587         return new Op($2, $1, $3);
  588       }), o('Expression LOGIC    Expression', function() {
  589         return new Op($2, $1, $3);
  590       }), o('Expression RELATION Expression', function() {
  591         if ($2.charAt(0) === '!') {
  592           return new Op($2.slice(1), $1, $3).invert();
  593         } else {
  594           return new Op($2, $1, $3);
  595         }
  596       }), o('SimpleAssignable COMPOUND_ASSIGN Expression', function() {
  597         return new Assign($1, $3, $2);
  598       }), o('SimpleAssignable COMPOUND_ASSIGN INDENT Expression OUTDENT', function() {
  599         return new Assign($1, $4, $2);
  600       }), o('SimpleAssignable COMPOUND_ASSIGN TERMINATOR Expression', function() {
  601         return new Assign($1, $4, $2);
  602       }), o('SimpleAssignable EXTENDS Expression', function() {
  603         return new Extends($1, $3);
  604       })
  605     ]
  606   };
  607 
  608   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']];
  609 
  610   tokens = [];
  611 
  612   for (name in grammar) {
  613     alternatives = grammar[name];
  614     grammar[name] = (function() {
  615       var _i, _j, _len, _len1, _ref, _results;
  616       _results = [];
  617       for (_i = 0, _len = alternatives.length; _i < _len; _i++) {
  618         alt = alternatives[_i];
  619         _ref = alt[0].split(' ');
  620         for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
  621           token = _ref[_j];
  622           if (!grammar[token]) {
  623             tokens.push(token);
  624           }
  625         }
  626         if (name === 'Root') {
  627           alt[1] = "return " + alt[1];
  628         }
  629         _results.push(alt);
  630       }
  631       return _results;
  632     })();
  633   }
  634 
  635   exports.parser = new Parser({
  636     tokens: tokens.join(' '),
  637     bnf: grammar,
  638     operators: operators.reverse(),
  639     startSymbol: 'Root'
  640   });
  641 
  642 }).call(this);