2010-07-25 03:15:12 -04:00
|
|
|
(function() {
|
2010-10-19 11:07:10 -04:00
|
|
|
var Parser, _i, _j, _len, _len2, _ref, _result, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
|
2010-03-30 16:48:43 -04:00
|
|
|
var __hasProp = Object.prototype.hasOwnProperty;
|
2010-02-10 23:24:05 -05:00
|
|
|
Parser = require('jison').Parser;
|
2010-10-19 20:42:12 -04:00
|
|
|
unwrap = /^function\s*\(\)\s*\{\s*return\s*([\s\S]*);\s*\}/;
|
2010-06-12 19:05:13 -04:00
|
|
|
o = function(patternString, action, options) {
|
2010-02-10 23:24:05 -05:00
|
|
|
var match;
|
2010-10-19 20:42:12 -04:00
|
|
|
patternString = patternString.replace(/\s{2,}/g, ' ');
|
2010-10-07 07:05:22 -04:00
|
|
|
if (!action) {
|
2010-06-12 19:05:13 -04:00
|
|
|
return [patternString, '$$ = $1;', options];
|
2010-02-10 23:24:05 -05:00
|
|
|
}
|
2010-10-19 20:42:12 -04:00
|
|
|
action = (match = unwrap.exec(action)) ? match[1] : ("(" + action + "())");
|
|
|
|
action = action.replace(/\bnew /g, '$&yy.');
|
|
|
|
action = action.replace(/\bExpressions\.wrap\b/g, 'yy.$&');
|
2010-10-04 08:50:50 -04:00
|
|
|
return [patternString, ("$$ = " + action + ";"), options];
|
2010-02-10 23:24:05 -05:00
|
|
|
};
|
|
|
|
grammar = {
|
2010-04-26 23:46:35 -04:00
|
|
|
Root: [
|
|
|
|
o("", function() {
|
2010-09-25 04:39:19 -04:00
|
|
|
return new Expressions;
|
2010-02-10 23:24:05 -05:00
|
|
|
}), o("TERMINATOR", function() {
|
2010-09-25 04:39:19 -04:00
|
|
|
return new Expressions;
|
2010-04-05 10:26:23 -04:00
|
|
|
}), o("Body"), o("Block TERMINATOR")
|
2010-02-10 23:24:05 -05:00
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Body: [
|
|
|
|
o("Line", function() {
|
2010-02-10 23:24:05 -05:00
|
|
|
return Expressions.wrap([$1]);
|
2010-04-05 10:26:23 -04:00
|
|
|
}), o("Body TERMINATOR Line", function() {
|
2010-02-10 23:24:05 -05:00
|
|
|
return $1.push($3);
|
2010-04-05 10:26:23 -04:00
|
|
|
}), o("Body TERMINATOR")
|
|
|
|
],
|
|
|
|
Line: [o("Expression"), o("Statement")],
|
2010-04-26 23:46:35 -04:00
|
|
|
Statement: [
|
|
|
|
o("Return"), o("Throw"), o("BREAK", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Literal($1);
|
2010-04-05 10:26:23 -04:00
|
|
|
}), o("CONTINUE", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Literal($1);
|
2010-08-28 08:26:47 -04:00
|
|
|
}), o("DEBUGGER", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Literal($1);
|
2010-04-05 10:26:23 -04:00
|
|
|
})
|
2010-02-10 23:24:05 -05:00
|
|
|
],
|
2010-09-26 13:11:47 -04:00
|
|
|
Expression: [o("Value"), o("Invocation"), o("Code"), o("Operation"), o("Assign"), o("If"), o("Try"), o("While"), o("For"), o("Switch"), o("Extends"), o("Class"), o("Existence"), o("Comment")],
|
2010-04-26 23:46:35 -04:00
|
|
|
Block: [
|
|
|
|
o("INDENT Body OUTDENT", function() {
|
2010-02-10 23:24:05 -05:00
|
|
|
return $2;
|
|
|
|
}), o("INDENT OUTDENT", function() {
|
2010-09-25 04:39:19 -04:00
|
|
|
return new Expressions;
|
2010-07-01 21:26:33 -04:00
|
|
|
}), o("TERMINATOR Comment", function() {
|
|
|
|
return Expressions.wrap([$2]);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Identifier: [
|
|
|
|
o("IDENTIFIER", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Literal($1);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
AlphaNumeric: [
|
|
|
|
o("NUMBER", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Literal($1);
|
2010-02-10 23:24:05 -05:00
|
|
|
}), o("STRING", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Literal($1);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Literal: [
|
|
|
|
o("AlphaNumeric"), o("JS", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Literal($1);
|
2010-02-10 23:24:05 -05:00
|
|
|
}), o("REGEX", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Literal($1);
|
2010-10-11 04:05:50 -04:00
|
|
|
}), o("BOOL", function() {
|
|
|
|
return new Literal($1);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Assign: [
|
2010-07-25 01:23:37 -04:00
|
|
|
o("Assignable = Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Assign($1, $3);
|
2010-07-25 20:46:08 -04:00
|
|
|
}), o("Assignable = INDENT Expression OUTDENT", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Assign($1, $4);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
AssignObj: [
|
|
|
|
o("Identifier", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Value($1);
|
2010-10-19 20:42:12 -04:00
|
|
|
}), o("AlphaNumeric"), o("ThisProperty"), o("Identifier : Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Assign(new Value($1), $3, 'object');
|
2010-07-25 01:23:37 -04:00
|
|
|
}), o("AlphaNumeric : Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Assign(new Value($1), $3, 'object');
|
2010-10-19 20:42:12 -04:00
|
|
|
}), o("Identifier : INDENT Expression OUTDENT", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Assign(new Value($1), $4, 'object');
|
2010-07-25 02:52:02 -04:00
|
|
|
}), o("AlphaNumeric : INDENT Expression OUTDENT", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Assign(new Value($1), $4, 'object');
|
2010-07-01 21:26:33 -04:00
|
|
|
}), o("Comment")
|
2010-02-10 23:24:05 -05:00
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Return: [
|
|
|
|
o("RETURN Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Return($2);
|
2010-02-10 23:24:05 -05:00
|
|
|
}), o("RETURN", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Return;
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-07-01 21:26:33 -04:00
|
|
|
Comment: [
|
|
|
|
o("HERECOMMENT", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Comment($1);
|
2010-07-01 21:26:33 -04:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Existence: [
|
|
|
|
o("Expression ?", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Existence($1);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Code: [
|
|
|
|
o("PARAM_START ParamList PARAM_END FuncGlyph Block", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Code($2, $5, $4);
|
2010-02-10 23:24:05 -05:00
|
|
|
}), o("FuncGlyph Block", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Code([], $2, $1);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
FuncGlyph: [
|
|
|
|
o("->", function() {
|
2010-02-10 23:24:05 -05:00
|
|
|
return 'func';
|
|
|
|
}), o("=>", function() {
|
|
|
|
return 'boundfunc';
|
|
|
|
})
|
|
|
|
],
|
2010-04-25 21:17:46 -04:00
|
|
|
OptComma: [o(''), o(',')],
|
2010-04-26 23:46:35 -04:00
|
|
|
ParamList: [
|
|
|
|
o("", function() {
|
2010-02-15 18:03:00 -05:00
|
|
|
return [];
|
|
|
|
}), o("Param", function() {
|
2010-02-10 23:24:05 -05:00
|
|
|
return [$1];
|
|
|
|
}), o("ParamList , Param", function() {
|
2010-10-11 03:06:29 -04:00
|
|
|
return $1.concat($3);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Param: [
|
|
|
|
o("PARAM", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Literal($1);
|
2010-07-28 01:54:36 -04:00
|
|
|
}), o("@ PARAM", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Param($2, true);
|
2010-10-10 12:34:22 -04:00
|
|
|
}), o("PARAM ...", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Param($1, false, true);
|
2010-10-10 12:34:22 -04:00
|
|
|
}), o("@ PARAM ...", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Param($2, true, true);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Splat: [
|
2010-10-10 12:34:22 -04:00
|
|
|
o("Expression ...", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Splat($1);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
SimpleAssignable: [
|
|
|
|
o("Identifier", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Value($1);
|
2010-03-28 13:06:16 -04:00
|
|
|
}), o("Value Accessor", function() {
|
|
|
|
return $1.push($2);
|
|
|
|
}), o("Invocation Accessor", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Value($1, [$2]);
|
2010-03-28 13:06:16 -04:00
|
|
|
}), o("ThisProperty")
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Assignable: [
|
|
|
|
o("SimpleAssignable"), o("Array", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Value($1);
|
2010-03-28 13:14:35 -04:00
|
|
|
}), o("Object", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Value($1);
|
2010-03-28 13:14:35 -04:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Value: [
|
|
|
|
o("Assignable"), o("Literal", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Value($1);
|
2010-02-10 23:24:05 -05:00
|
|
|
}), o("Parenthetical", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Value($1);
|
2010-02-10 23:24:05 -05:00
|
|
|
}), o("Range", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Value($1);
|
2010-10-07 11:56:01 -04:00
|
|
|
}), o("This")
|
2010-02-10 23:24:05 -05:00
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Accessor: [
|
|
|
|
o("PROPERTY_ACCESS Identifier", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Accessor($2);
|
2010-02-10 23:24:05 -05:00
|
|
|
}), o("PROTOTYPE_ACCESS Identifier", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Accessor($2, 'prototype');
|
2010-03-16 17:39:36 -04:00
|
|
|
}), o("::", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Accessor(new Literal('prototype'));
|
2010-02-10 23:24:05 -05:00
|
|
|
}), o("SOAK_ACCESS Identifier", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Accessor($2, 'soak');
|
2010-02-10 23:24:05 -05:00
|
|
|
}), o("Index"), o("Slice", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Slice($1);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Index: [
|
|
|
|
o("INDEX_START Expression INDEX_END", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Index($2);
|
2010-05-31 22:32:43 -04:00
|
|
|
}), o("INDEX_SOAK Index", function() {
|
2010-06-12 19:05:13 -04:00
|
|
|
$2.soakNode = true;
|
2010-05-31 22:32:43 -04:00
|
|
|
return $2;
|
|
|
|
}), o("INDEX_PROTO Index", function() {
|
|
|
|
$2.proto = true;
|
|
|
|
return $2;
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Object: [
|
|
|
|
o("{ AssignList OptComma }", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new ObjectLiteral($2);
|
2010-02-27 18:57:45 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
AssignList: [
|
|
|
|
o("", function() {
|
2010-02-10 23:24:05 -05:00
|
|
|
return [];
|
|
|
|
}), o("AssignObj", function() {
|
|
|
|
return [$1];
|
|
|
|
}), o("AssignList , AssignObj", function() {
|
2010-10-11 03:06:29 -04:00
|
|
|
return $1.concat($3);
|
2010-05-12 18:28:40 -04:00
|
|
|
}), o("AssignList OptComma TERMINATOR AssignObj", function() {
|
2010-10-11 03:06:29 -04:00
|
|
|
return $1.concat($4);
|
2010-05-12 18:28:40 -04:00
|
|
|
}), o("AssignList OptComma INDENT AssignList OptComma OUTDENT", function() {
|
|
|
|
return $1.concat($4);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
2010-04-03 12:18:29 -04:00
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Class: [
|
|
|
|
o("CLASS SimpleAssignable", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Class($2);
|
2010-04-03 12:18:29 -04:00
|
|
|
}), o("CLASS SimpleAssignable EXTENDS Value", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Class($2, $4);
|
2010-04-03 12:18:29 -04:00
|
|
|
}), o("CLASS SimpleAssignable INDENT ClassBody OUTDENT", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Class($2, null, $4);
|
2010-04-03 12:18:29 -04:00
|
|
|
}), o("CLASS SimpleAssignable EXTENDS Value INDENT ClassBody OUTDENT", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Class($2, $4, $6);
|
2010-07-27 22:05:55 -04:00
|
|
|
}), o("CLASS INDENT ClassBody OUTDENT", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Class('__temp__', null, $3);
|
2010-09-27 23:59:47 -04:00
|
|
|
}), o("CLASS", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Class('__temp__', null, new Expressions);
|
2010-09-27 23:59:47 -04:00
|
|
|
}), o("CLASS EXTENDS Value", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Class('__temp__', $3, new Expressions);
|
2010-09-27 23:59:47 -04:00
|
|
|
}), o("CLASS EXTENDS Value INDENT ClassBody OUTDENT", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Class('__temp__', $3, $5);
|
2010-04-03 12:18:29 -04:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
ClassAssign: [
|
|
|
|
o("AssignObj", function() {
|
2010-04-03 12:18:29 -04:00
|
|
|
return $1;
|
2010-07-25 01:23:37 -04:00
|
|
|
}), o("ThisProperty : Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Assign(new Value($1), $3, 'this');
|
2010-09-18 22:25:45 -04:00
|
|
|
}), o("ThisProperty : INDENT Expression OUTDENT", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Assign(new Value($1), $4, 'this');
|
2010-04-03 12:18:29 -04:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
ClassBody: [
|
|
|
|
o("", function() {
|
2010-04-03 12:18:29 -04:00
|
|
|
return [];
|
|
|
|
}), o("ClassAssign", function() {
|
|
|
|
return [$1];
|
|
|
|
}), o("ClassBody TERMINATOR ClassAssign", function() {
|
|
|
|
return $1.concat($3);
|
2010-07-25 02:42:37 -04:00
|
|
|
}), o("{ ClassBody }", function() {
|
|
|
|
return $2;
|
2010-04-03 12:18:29 -04:00
|
|
|
})
|
2010-02-10 23:24:05 -05:00
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Extends: [
|
|
|
|
o("SimpleAssignable EXTENDS Value", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Extends($1, $3);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Invocation: [
|
2010-08-25 15:39:30 -04:00
|
|
|
o("Value OptFuncExist Arguments", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Call($1, $3, $2);
|
2010-08-25 15:39:30 -04:00
|
|
|
}), o("Invocation OptFuncExist Arguments", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Call($1, $3, $2);
|
2010-09-12 16:33:38 -04:00
|
|
|
}), o("SUPER", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Call('super', [new Splat(new Literal('arguments'))]);
|
2010-09-12 16:33:38 -04:00
|
|
|
}), o("SUPER Arguments", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Call('super', $2);
|
2010-08-25 15:39:30 -04:00
|
|
|
})
|
|
|
|
],
|
|
|
|
OptFuncExist: [
|
|
|
|
o("", function() {
|
|
|
|
return false;
|
|
|
|
}), o("FUNC_EXIST", function() {
|
|
|
|
return true;
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Arguments: [
|
2010-09-08 21:39:51 -04:00
|
|
|
o("CALL_START CALL_END", function() {
|
|
|
|
return [];
|
|
|
|
}), o("CALL_START ArgList OptComma CALL_END", function() {
|
2010-03-26 11:44:25 -04:00
|
|
|
return $2;
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
This: [
|
|
|
|
o("THIS", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Value(new Literal('this'));
|
2010-03-28 13:06:16 -04:00
|
|
|
}), o("@", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Value(new Literal('this'));
|
2010-03-28 13:06:16 -04:00
|
|
|
})
|
|
|
|
],
|
2010-09-04 06:48:20 -04:00
|
|
|
RangeDots: [
|
2010-10-10 12:34:22 -04:00
|
|
|
o("..", function() {
|
2010-09-04 06:48:20 -04:00
|
|
|
return 'inclusive';
|
2010-10-10 12:34:22 -04:00
|
|
|
}), o("...", function() {
|
2010-09-04 06:48:20 -04:00
|
|
|
return 'exclusive';
|
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
ThisProperty: [
|
|
|
|
o("@ Identifier", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Value(new Literal('this'), [new Accessor($2)], 'this');
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Range: [
|
2010-09-04 06:48:20 -04:00
|
|
|
o("[ Expression RangeDots Expression ]", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Range($2, $4, $3);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Slice: [
|
2010-09-04 06:48:20 -04:00
|
|
|
o("INDEX_START Expression RangeDots Expression INDEX_END", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Range($2, $4, $3);
|
2010-09-04 06:48:20 -04:00
|
|
|
}), o("INDEX_START Expression RangeDots INDEX_END", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Range($2, null, $3);
|
2010-09-04 06:48:20 -04:00
|
|
|
}), o("INDEX_START RangeDots Expression INDEX_END", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Range(null, $3, $2);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Array: [
|
2010-09-08 21:39:51 -04:00
|
|
|
o("[ ]", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new ArrayLiteral([]);
|
2010-09-08 21:39:51 -04:00
|
|
|
}), o("[ ArgList OptComma ]", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new ArrayLiteral($2);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
ArgList: [
|
2010-09-08 21:39:51 -04:00
|
|
|
o("Arg", function() {
|
2010-02-10 23:24:05 -05:00
|
|
|
return [$1];
|
2010-08-18 21:27:10 -04:00
|
|
|
}), o("ArgList , Arg", function() {
|
2010-10-11 03:06:29 -04:00
|
|
|
return $1.concat($3);
|
2010-08-18 21:27:10 -04:00
|
|
|
}), o("ArgList OptComma TERMINATOR Arg", function() {
|
2010-10-11 03:06:29 -04:00
|
|
|
return $1.concat($4);
|
2010-09-08 21:39:51 -04:00
|
|
|
}), o("INDENT ArgList OptComma OUTDENT", function() {
|
|
|
|
return $2;
|
2010-06-09 00:37:23 -04:00
|
|
|
}), o("ArgList OptComma INDENT ArgList OptComma OUTDENT", function() {
|
|
|
|
return $1.concat($4);
|
|
|
|
})
|
2010-02-10 23:24:05 -05:00
|
|
|
],
|
2010-08-18 21:27:10 -04:00
|
|
|
Arg: [o("Expression"), o("Splat")],
|
2010-04-26 23:46:35 -04:00
|
|
|
SimpleArgs: [
|
|
|
|
o("Expression"), o("SimpleArgs , Expression", function() {
|
2010-10-11 03:06:29 -04:00
|
|
|
return [].concat($1, $3);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Try: [
|
2010-10-04 16:53:32 -04:00
|
|
|
o("TRY Block", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Try($2);
|
2010-10-04 16:53:32 -04:00
|
|
|
}), o("TRY Block Catch", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Try($2, $3[0], $3[1]);
|
2010-02-10 23:24:05 -05:00
|
|
|
}), o("TRY Block FINALLY Block", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Try($2, null, null, $4);
|
2010-02-10 23:24:05 -05:00
|
|
|
}), o("TRY Block Catch FINALLY Block", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Try($2, $3[0], $3[1], $5);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Catch: [
|
|
|
|
o("CATCH Identifier Block", function() {
|
2010-02-10 23:24:05 -05:00
|
|
|
return [$2, $3];
|
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Throw: [
|
|
|
|
o("THROW Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Throw($2);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Parenthetical: [
|
2010-10-19 02:32:23 -04:00
|
|
|
o("( Expression )", function() {
|
2010-10-06 23:53:26 -04:00
|
|
|
return new Parens($2);
|
2010-08-17 21:31:32 -04:00
|
|
|
}), o("( )", function() {
|
2010-10-06 23:53:26 -04:00
|
|
|
return new Parens(new Literal(''));
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
WhileSource: [
|
|
|
|
o("WHILE Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new While($2);
|
2010-02-23 22:53:43 -05:00
|
|
|
}), o("WHILE Expression WHEN Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new While($2, {
|
2010-04-28 21:46:47 -04:00
|
|
|
guard: $4
|
2010-02-23 22:53:43 -05:00
|
|
|
});
|
2010-04-28 22:08:00 -04:00
|
|
|
}), o("UNTIL Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new While($2, {
|
2010-04-28 22:08:00 -04:00
|
|
|
invert: true
|
|
|
|
});
|
|
|
|
}), o("UNTIL Expression WHEN Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new While($2, {
|
2010-04-28 22:08:00 -04:00
|
|
|
invert: true,
|
|
|
|
guard: $4
|
|
|
|
});
|
2010-02-23 22:53:43 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
While: [
|
|
|
|
o("WhileSource Block", function() {
|
2010-06-12 19:05:13 -04:00
|
|
|
return $1.addBody($2);
|
2010-04-05 10:26:23 -04:00
|
|
|
}), o("Statement WhileSource", function() {
|
2010-06-12 19:05:13 -04:00
|
|
|
return $2.addBody(Expressions.wrap([$1]));
|
2010-02-23 22:53:43 -05:00
|
|
|
}), o("Expression WhileSource", function() {
|
2010-06-12 19:05:13 -04:00
|
|
|
return $2.addBody(Expressions.wrap([$1]));
|
2010-06-12 12:15:53 -04:00
|
|
|
}), o("Loop", function() {
|
|
|
|
return $1;
|
|
|
|
})
|
|
|
|
],
|
|
|
|
Loop: [
|
|
|
|
o("LOOP Block", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new While(new Literal('true')).addBody($2);
|
2010-06-12 12:15:53 -04:00
|
|
|
}), o("LOOP Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new While(new Literal('true')).addBody(Expressions.wrap([$2]));
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
For: [
|
2010-07-27 22:38:38 -04:00
|
|
|
o("Statement ForBody", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new For($1, $2, $2.vars[0], $2.vars[1]);
|
2010-07-27 22:38:38 -04:00
|
|
|
}), o("Expression ForBody", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new For($1, $2, $2.vars[0], $2.vars[1]);
|
2010-07-27 22:38:38 -04:00
|
|
|
}), o("ForBody Block", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new For($2, $1, $1.vars[0], $1.vars[1]);
|
2010-07-27 22:38:38 -04:00
|
|
|
})
|
|
|
|
],
|
|
|
|
ForBody: [
|
|
|
|
o("FOR Range", function() {
|
|
|
|
return {
|
2010-10-06 22:44:32 -04:00
|
|
|
source: new Value($2),
|
2010-07-27 22:38:38 -04:00
|
|
|
vars: []
|
|
|
|
};
|
|
|
|
}), o("ForStart ForSource", function() {
|
2010-07-15 21:18:35 -04:00
|
|
|
$2.raw = $1.raw;
|
2010-07-27 22:38:38 -04:00
|
|
|
$2.vars = $1;
|
|
|
|
return $2;
|
2010-07-15 21:18:35 -04:00
|
|
|
})
|
|
|
|
],
|
|
|
|
ForStart: [
|
|
|
|
o("FOR ForVariables", function() {
|
|
|
|
return $2;
|
|
|
|
}), o("FOR ALL ForVariables", function() {
|
|
|
|
$3.raw = true;
|
|
|
|
return $3;
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
ForValue: [
|
|
|
|
o("Identifier"), o("Array", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Value($1);
|
2010-04-26 14:35:35 -04:00
|
|
|
}), o("Object", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Value($1);
|
2010-04-26 14:35:35 -04:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
ForVariables: [
|
|
|
|
o("ForValue", function() {
|
2010-02-10 23:24:05 -05:00
|
|
|
return [$1];
|
2010-04-26 14:35:35 -04:00
|
|
|
}), o("ForValue , ForValue", function() {
|
2010-02-10 23:24:05 -05:00
|
|
|
return [$1, $3];
|
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
ForSource: [
|
2010-10-05 15:46:17 -04:00
|
|
|
o("FORIN Expression", function() {
|
2010-02-10 23:24:05 -05:00
|
|
|
return {
|
|
|
|
source: $2
|
|
|
|
};
|
2010-10-05 15:46:17 -04:00
|
|
|
}), o("FOROF Expression", function() {
|
2010-02-10 23:24:05 -05:00
|
|
|
return {
|
|
|
|
source: $2,
|
|
|
|
object: true
|
|
|
|
};
|
2010-10-05 15:46:17 -04:00
|
|
|
}), o("FORIN Expression WHEN Expression", function() {
|
2010-03-28 14:32:01 -04:00
|
|
|
return {
|
|
|
|
source: $2,
|
2010-04-28 21:46:47 -04:00
|
|
|
guard: $4
|
2010-03-28 14:32:01 -04:00
|
|
|
};
|
2010-10-05 15:46:17 -04:00
|
|
|
}), o("FOROF Expression WHEN Expression", function() {
|
2010-03-28 14:32:01 -04:00
|
|
|
return {
|
|
|
|
source: $2,
|
2010-04-28 21:46:47 -04:00
|
|
|
guard: $4,
|
2010-03-28 14:32:01 -04:00
|
|
|
object: true
|
|
|
|
};
|
2010-10-05 15:46:17 -04:00
|
|
|
}), o("FORIN Expression BY Expression", function() {
|
2010-03-28 14:32:01 -04:00
|
|
|
return {
|
|
|
|
source: $2,
|
|
|
|
step: $4
|
|
|
|
};
|
2010-10-05 15:46:17 -04:00
|
|
|
}), o("FORIN Expression WHEN Expression BY Expression", function() {
|
2010-03-28 14:32:01 -04:00
|
|
|
return {
|
|
|
|
source: $2,
|
2010-04-28 21:46:47 -04:00
|
|
|
guard: $4,
|
2010-03-28 14:32:01 -04:00
|
|
|
step: $6
|
|
|
|
};
|
2010-10-05 15:46:17 -04:00
|
|
|
}), o("FORIN Expression BY Expression WHEN Expression", function() {
|
2010-03-28 14:32:01 -04:00
|
|
|
return {
|
|
|
|
source: $2,
|
|
|
|
step: $4,
|
2010-04-28 21:46:47 -04:00
|
|
|
guard: $6
|
2010-03-28 14:32:01 -04:00
|
|
|
};
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Switch: [
|
|
|
|
o("SWITCH Expression INDENT Whens OUTDENT", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Switch($2, $4);
|
2010-02-10 23:24:05 -05:00
|
|
|
}), o("SWITCH Expression INDENT Whens ELSE Block OUTDENT", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Switch($2, $4, $6);
|
2010-05-10 22:57:51 -04:00
|
|
|
}), o("SWITCH INDENT Whens OUTDENT", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Switch(null, $3);
|
2010-05-10 22:57:51 -04:00
|
|
|
}), o("SWITCH INDENT Whens ELSE Block OUTDENT", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Switch(null, $3, $5);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Whens: [
|
|
|
|
o("When"), o("Whens When", function() {
|
2010-09-15 23:46:01 -04:00
|
|
|
return $1.concat($2);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
When: [
|
|
|
|
o("LEADING_WHEN SimpleArgs Block", function() {
|
2010-09-15 23:46:01 -04:00
|
|
|
return [[$2, $3]];
|
2010-02-10 23:24:05 -05:00
|
|
|
}), o("LEADING_WHEN SimpleArgs Block TERMINATOR", function() {
|
2010-09-15 23:46:01 -04:00
|
|
|
return [[$2, $3]];
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-06-27 11:46:30 -04:00
|
|
|
IfBlock: [
|
2010-04-26 23:46:35 -04:00
|
|
|
o("IF Expression Block", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new If($2, $3);
|
2010-04-27 19:35:15 -04:00
|
|
|
}), o("UNLESS Expression Block", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new If($2, $3, {
|
2010-04-27 19:35:15 -04:00
|
|
|
invert: true
|
|
|
|
});
|
2010-06-27 11:46:30 -04:00
|
|
|
}), o("IfBlock ELSE IF Expression Block", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return $1.addElse(new If($4, $5));
|
2010-06-27 11:46:30 -04:00
|
|
|
}), o("IfBlock ELSE Block", function() {
|
2010-06-12 19:05:13 -04:00
|
|
|
return $1.addElse($3);
|
2010-02-10 23:24:05 -05:00
|
|
|
})
|
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
If: [
|
2010-08-11 21:28:22 -04:00
|
|
|
o("IfBlock"), o("Statement POST_IF Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new If($3, Expressions.wrap([$1]), {
|
2010-04-05 10:26:23 -04:00
|
|
|
statement: true
|
|
|
|
});
|
2010-08-11 21:28:22 -04:00
|
|
|
}), o("Expression POST_IF Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new If($3, Expressions.wrap([$1]), {
|
2010-02-10 23:24:05 -05:00
|
|
|
statement: true
|
|
|
|
});
|
2010-08-11 21:28:22 -04:00
|
|
|
}), o("Statement POST_UNLESS Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new If($3, Expressions.wrap([$1]), {
|
2010-04-05 10:26:23 -04:00
|
|
|
statement: true,
|
|
|
|
invert: true
|
|
|
|
});
|
2010-08-11 21:28:22 -04:00
|
|
|
}), o("Expression POST_UNLESS Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new If($3, Expressions.wrap([$1]), {
|
2010-02-10 23:24:05 -05:00
|
|
|
statement: true,
|
|
|
|
invert: true
|
|
|
|
});
|
|
|
|
})
|
2010-03-07 11:41:56 -05:00
|
|
|
],
|
2010-04-26 23:46:35 -04:00
|
|
|
Operation: [
|
2010-08-11 22:24:43 -04:00
|
|
|
o("UNARY Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Op($1, $2);
|
2010-08-14 17:25:29 -04:00
|
|
|
}), o("- Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Op('-', $2);
|
2010-08-14 17:25:29 -04:00
|
|
|
}, {
|
2010-08-11 22:24:43 -04:00
|
|
|
prec: 'UNARY'
|
2010-08-14 17:25:29 -04:00
|
|
|
}), o("+ Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Op('+', $2);
|
2010-08-14 17:25:29 -04:00
|
|
|
}, {
|
2010-08-11 22:24:43 -04:00
|
|
|
prec: 'UNARY'
|
2010-10-19 03:48:39 -04:00
|
|
|
}), o("-- SimpleAssignable", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Op('--', $2);
|
2010-10-19 03:48:39 -04:00
|
|
|
}), o("++ SimpleAssignable", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Op('++', $2);
|
2010-10-19 03:48:39 -04:00
|
|
|
}), o("SimpleAssignable --", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Op('--', $1, null, true);
|
2010-10-19 03:48:39 -04:00
|
|
|
}), o("SimpleAssignable ++", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Op('++', $1, null, true);
|
2010-03-07 11:41:56 -05:00
|
|
|
}), o("Expression + Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Op('+', $1, $3);
|
2010-03-07 11:41:56 -05:00
|
|
|
}), o("Expression - Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Op('-', $1, $3);
|
2010-03-07 11:41:56 -05:00
|
|
|
}), o("Expression == Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Op('==', $1, $3);
|
2010-03-07 11:41:56 -05:00
|
|
|
}), o("Expression != Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Op('!=', $1, $3);
|
2010-08-11 22:24:43 -04:00
|
|
|
}), o("Expression MATH Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Op($2, $1, $3);
|
2010-08-11 22:24:43 -04:00
|
|
|
}), o("Expression SHIFT Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Op($2, $1, $3);
|
2010-08-11 22:24:43 -04:00
|
|
|
}), o("Expression COMPARE Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Op($2, $1, $3);
|
2010-08-11 22:24:43 -04:00
|
|
|
}), o("Expression LOGIC Expression", function() {
|
2010-10-06 22:44:32 -04:00
|
|
|
return new Op($2, $1, $3);
|
2010-10-19 03:48:39 -04:00
|
|
|
}), o("SimpleAssignable COMPOUND_ASSIGN Expression", function() {
|
2010-10-19 20:42:12 -04:00
|
|
|
return new Assign($1, $3, $2);
|
2010-10-19 03:48:39 -04:00
|
|
|
}), o("SimpleAssignable COMPOUND_ASSIGN INDENT Expression OUTDENT", function() {
|
2010-10-19 20:42:12 -04:00
|
|
|
return new Assign($1, $4, $2);
|
2010-10-05 15:46:17 -04:00
|
|
|
}), o("Expression RELATION Expression", function() {
|
2010-10-06 23:53:26 -04:00
|
|
|
return $2.charAt(0) === '!' ? ($2 === '!in' ? new Op('!', new In($1, $3)) : new Op('!', new Parens(new Op($2.slice(1), $1, $3)))) : ($2 === 'in' ? new In($1, $3) : new Op($2, $1, $3));
|
2010-03-07 11:41:56 -05:00
|
|
|
})
|
2010-02-10 23:24:05 -05:00
|
|
|
]
|
|
|
|
};
|
2010-10-19 20:42:12 -04:00
|
|
|
operators = [["left", 'CALL_START', 'CALL_END'], ["nonassoc", '++', '--'], ["left", '?'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'COMPARE'], ["left", 'RELATION'], ["left", '==', '!='], ["left", 'LOGIC'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS'], ["right", '=', ':', 'COMPOUND_ASSIGN', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']];
|
2010-02-10 23:24:05 -05:00
|
|
|
tokens = [];
|
2010-10-01 18:26:37 -04:00
|
|
|
for (name in grammar) {
|
|
|
|
if (!__hasProp.call(grammar, name)) continue;
|
|
|
|
alternatives = grammar[name];
|
2010-03-07 11:41:56 -05:00
|
|
|
grammar[name] = (function() {
|
2010-10-01 18:26:37 -04:00
|
|
|
_result = [];
|
2010-10-19 11:07:10 -04:00
|
|
|
for (_i = 0, _len = alternatives.length; _i < _len; _i++) {
|
|
|
|
alt = alternatives[_i];
|
2010-09-19 08:29:15 -04:00
|
|
|
_result.push((function() {
|
2010-10-19 11:07:10 -04:00
|
|
|
for (_j = 0, _len2 = (_ref = alt[0].split(' ')).length; _j < _len2; _j++) {
|
|
|
|
token = _ref[_j];
|
2010-10-07 07:05:22 -04:00
|
|
|
if (!grammar[token]) {
|
2010-03-07 11:41:56 -05:00
|
|
|
tokens.push(token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (name === 'Root') {
|
2010-04-04 02:59:44 -04:00
|
|
|
alt[1] = ("return " + (alt[1]));
|
2010-02-14 17:35:14 -05:00
|
|
|
}
|
2010-03-07 11:41:56 -05:00
|
|
|
return alt;
|
2010-04-10 14:40:05 -04:00
|
|
|
})());
|
2010-02-14 17:35:14 -05:00
|
|
|
}
|
2010-09-19 08:29:15 -04:00
|
|
|
return _result;
|
2010-04-10 14:40:05 -04:00
|
|
|
})();
|
2010-07-16 22:31:36 -04:00
|
|
|
}
|
2010-02-16 01:04:48 -05:00
|
|
|
exports.parser = new Parser({
|
2010-03-07 11:41:56 -05:00
|
|
|
tokens: tokens.join(' '),
|
|
|
|
bnf: grammar,
|
2010-02-11 23:29:12 -05:00
|
|
|
operators: operators.reverse(),
|
2010-02-10 23:24:05 -05:00
|
|
|
startSymbol: 'Root'
|
|
|
|
});
|
2010-09-21 03:53:58 -04:00
|
|
|
}).call(this);
|