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