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