gorillascript
Version:
GorillaScript is a compile-to-JavaScript language designed to empower the user while attempting to prevent some common errors.
1,827 lines (1,826 loc) • 283 kB
JavaScript
(function (GLOBAL) {
"use strict";
var __bind, __cmp, __compose, __create, __curry, __defer,
__generatorToPromise, __import, __in, __isArray, __owns, __promise,
__slice, __toArray, __toPromise, __typeof, _Block, _DefineMacro,
_FunctionBody, _FunctionDeclaration, _IdentifierOrAccess, _Name, _o, _ref,
_ref2, _SomeEmptyLinesWithCheckIndent, _Symbol, _this, addParamToScope,
allowSpaceBeforeAccess, AnyArrayLiteral, AnyObjectLiteral,
ArgumentsLiteral, ArrayLiteral, ArrayParameter, ArrayType,
AssignmentAsExpression, Ast, AsterixChar, AstExpression, AstPosition,
AstStatement, AtSignChar, BackslashChar, BackslashEscapeSequence,
BackslashStringLiteral, BasicInvocationOrAccess, BinaryDigit,
BinaryNumber, BinaryOperationByPrecedence, Block, Body, BodyNoEnd,
BodyNoIndent, BodyNoIndentNoEnd, BodyWithIndent, BOM, Box,
BracketedObjectKey, cache, CaretChar, Cascade, CascadePart,
CascadePartWithCascade, CheckPeriodNotDoublePeriod, CheckStop,
CloseCurlyBrace, CloseCurlyBraceChar, ClosedArguments, CloseParenthesis,
CloseSquareBracket, Colon, ColonChar, ColonEmbeddedClose,
ColonEmbeddedCloseWrite, ColonEqual, ColonNewline, Comma, CommaChar,
CommaOrNewline, CommaOrSomeEmptyLinesWithCheckIndent, ConstantLiteral,
ConstantLiteralAccessPart, ConstObjectKey, convertInvocationOrAccess,
CountIndent, CurrentArrayLength, CustomOperatorCloseParenthesis,
DecimalDigit, DecimalNumber, DedentedBody, DefineConstLiteral,
DefineHelper, DefineMacro, DefineOperator, DefineSyntax,
disallowEmbeddedText, DollarSign, DollarSignChar,
dontRequireParameterSequence, DoubleColonChar, DoubleQuote,
DoubleStringArrayLiteral, DoubleStringLiteral, DoubleStringLiteralInner,
DualObjectKey, EmbeddedBlock, EmbeddedClose, EmbeddedCloseComment,
EmbeddedCloseLiteral, EmbeddedCloseWrite, EmbeddedLiteralText,
EmbeddedLiteralTextInnerPart, EmbeddedLiteralTextInnerPartWithBlock,
EmbeddedOpen, EmbeddedOpenComment, EmbeddedOpenLiteral, EmbeddedOpenWrite,
EmbeddedRootGeneratorP, EmbeddedRootInnerP, EmbeddedRootP,
EmbeddedWriteExpression, EmptyLine, EmptyLines, EmptyLinesSpace,
EndNoIndent, EqualChar, EqualSign, EqualSignChar, Eval,
ExclamationPointChar, Expression, ExpressionAsStatement,
ExpressionOrAssignment, ExpressionOrAssignmentOrBody, fromCharCode,
FunctionBody, FunctionDeclaration, FunctionGlyph, FunctionLiteral,
FunctionType, GeneratorBody, GeneratorBodyNoEnd, GeneratorFunctionBody,
getPackageVersion, getReservedIdents, GetSetToken, GreaterThan,
GreaterThanChar, HashSignChar, HexDigit, HexEscapeSequence, HexNumber,
Identifier, IdentifierNameConst, IdentifierNameConstOrNumberLiteral,
IdentifierOrAccess, IdentifierOrSimpleAccess,
IdentifierOrSimpleAccessPart, IdentifierOrSimpleAccessStart,
IdentifierOrThisAccess, IdentifierParameter, Imports, inAst, inCascade,
IndentedUnclosedArrayLiteral, IndentedUnclosedArrayLiteralInner,
IndentedUnclosedObjectLiteral, IndentedUnclosedObjectLiteralInner,
INDENTS, inEvilAst, inExpression, inFunctionTypeParams, inMacro,
insideIndentedAccess, inStatement, InvocationArguments,
InvocationOrAccess, InvocationOrAccessPart, InvocationOrAccessParts,
KeyValuePair, KvpParameter, LAccess, LCall, LessThan, LessThanChar,
Letter, LicenseComment, Line, LInternalCall, Literal, Logic, LSymbol,
LValue, MacroBody, MacroContext, MacroError, MacroHolder, MacroName,
macroName, MacroNames, MacroOptions, MacroSyntax,
MacroSyntaxChoiceParameters, MacroSyntaxParameter,
MacroSyntaxParameterLookahead, MacroSyntaxParameters,
MacroSyntaxParameterType, makeEmbeddedRule, MapLiteral, MaybeAsType,
MaybeAtSignChar, MaybeComma, MaybeCommaOrNewline, MaybeComment,
MaybeExclamationPointChar, MaybeNotToken, MaybeQuestionMarkChar,
MaybeSpreadToken, MaybeUnderscores, MethodDeclaration, MinusChar, mutate,
Name, NameChar, NameOrSymbol, NamePart, NameStart, NoNewlineIfNoIndent,
NonUnionType, NoSpace, NoSpaceNewline, NotColon,
NotColonUnlessNoIndentAndNewline, NotEmbeddedOpenComment,
NotEmbeddedOpenLiteral, NotEmbeddedOpenWrite, Nothing,
notInFunctionTypeParams, NumberChar, NumberLiteral, ObjectKey,
ObjectKeyColon, ObjectLiteral, ObjectParameter, ObjectType,
ObjectTypePair, OctalDigit, OctalNumber, OpenCurlyBrace,
OpenCurlyBraceChar, OpenParenthesis, OpenParenthesisChar,
OpenSquareBracket, OpenSquareBracketChar, ParamDualObjectKey, Parameter,
ParameterOrNothing, Parameters, ParameterSequence, ParamSingularObjectKey,
Parenthetical, parse, Parser, ParserError, ParserNode, PercentSign,
PercentSignChar, Period, PeriodOrDoubleColonChar, Pipe, PipeChar,
PlusChar, PlusOrMinusChar, PostfixUnaryOperation, PrefixUnaryOperation,
preventUnclosedObjectLiteral, PrimaryExpression, PropertyDualObjectKey,
PropertyOrDualObjectKey, PropertyOrDualObjectKeyOrMethodDeclaration,
quote, RadixNumber, RegexLiteral, requireParameterSequence, RootInnerP,
RootP, Scope, Semicolon, SemicolonChar, Semicolons, setImmediate,
SetLiteral, Shebang, SHORT_CIRCUIT, SingleEscapeCharacter, SingleQuote,
SingleStringLiteral, SingularObjectKey, SomeEmptyLines,
SomeEmptyLinesWithCheckIndent, Space, SpaceChar, SpaceChars,
SpreadOrExpression, SpreadToken, Stack, Statement, StringInterpolation,
StringLiteral, stringRepeat, SuperInvocation, Symbol, symbol, SymbolChar,
ThisLiteral, ThisOrShorthandLiteral, ThisOrShorthandLiteralPeriod,
ThisShorthandLiteral, trimRight, TripleDoubleQuote,
TripleDoubleStringArrayLiteral, TripleDoubleStringLine,
TripleDoubleStringLiteral, TripleSingleQuote, TripleSingleStringLine,
TripleSingleStringLiteral, Type, TypeReference, UnclosedArguments,
UnclosedArrayLiteralElement, UnclosedObjectLiteral,
UnclosedObjectLiteralsAllowed, Underscore, UnicodeEscapeSequence, unique,
unusedCaches, UseMacro, word, wordOrSymbol, Zero;
_this = this;
__bind = function (parent, child) {
var func;
if (parent == null) {
throw new TypeError("Expected parent to be an object, got " + __typeof(parent));
}
func = parent[child];
if (typeof func !== "function") {
throw new Error("Trying to bind child '" + String(child) + "' which is not a function");
}
return function () {
return func.apply(parent, arguments);
};
};
__cmp = function (left, right) {
var type;
if (left === right) {
return 0;
} else {
type = typeof left;
if (type !== "number" && type !== "string") {
throw new TypeError("Cannot compare a non-number/string: " + type);
} else if (type !== typeof right) {
throw new TypeError("Cannot compare elements of different types: " + type + " vs " + typeof right);
} else if (left < right) {
return -1;
} else {
return 1;
}
}
};
__compose = function (left, right) {
if (typeof left !== "function") {
throw new TypeError("Expected left to be a Function, got " + __typeof(left));
}
if (typeof right !== "function") {
throw new TypeError("Expected right to be a Function, got " + __typeof(right));
}
return function () {
return left.call(this, right.apply(this, arguments));
};
};
__create = typeof Object.create === "function" ? Object.create
: function (x) {
function F() {}
F.prototype = x;
return new F();
};
__curry = function (numArgs, f) {
var currier;
if (typeof numArgs !== "number") {
throw new TypeError("Expected numArgs to be a Number, got " + __typeof(numArgs));
}
if (typeof f !== "function") {
throw new TypeError("Expected f to be a Function, got " + __typeof(f));
}
if (numArgs > 1) {
currier = function (args) {
var ret;
if (args.length >= numArgs) {
return f.apply(this, args);
} else {
ret = function () {
if (arguments.length === 0) {
return ret;
} else {
return currier.call(this, args.concat(__slice.call(arguments)));
}
};
return ret;
}
};
return currier([]);
} else {
return f;
}
};
__defer = (function () {
function __defer() {
var deferred, isError, value;
isError = false;
value = null;
deferred = [];
function complete(newIsError, newValue) {
var funcs;
if (deferred) {
funcs = deferred;
deferred = null;
isError = newIsError;
value = newValue;
if (funcs.length) {
setImmediate(function () {
var _end, i;
for (i = 0, _end = funcs.length; i < _end; ++i) {
funcs[i]();
}
});
}
}
}
return {
promise: {
then: function (onFulfilled, onRejected, allowSync) {
var _ref, fulfill, promise, reject;
if (allowSync !== true) {
allowSync = void 0;
}
_ref = __defer();
promise = _ref.promise;
fulfill = _ref.fulfill;
reject = _ref.reject;
_ref = null;
function step() {
var f, result;
try {
if (isError) {
f = onRejected;
} else {
f = onFulfilled;
}
if (typeof f === "function") {
result = f(value);
if (result && typeof result.then === "function") {
result.then(fulfill, reject, allowSync);
} else {
fulfill(result);
}
} else {
(isError ? reject : fulfill)(value);
}
} catch (e) {
reject(e);
}
}
if (deferred) {
deferred.push(step);
} else if (allowSync) {
step();
} else {
setImmediate(step);
}
return promise;
},
sync: function () {
var result, state;
state = 0;
result = 0;
this.then(
function (ret) {
state = 1;
result = ret;
},
function (err) {
state = 2;
result = err;
},
true
);
switch (state) {
case 0: throw new Error("Promise did not execute synchronously");
case 1: return result;
case 2: throw result;
default: throw new Error("Unknown state");
}
}
},
fulfill: function (value) {
complete(false, value);
},
reject: function (reason) {
complete(true, reason);
}
};
}
__defer.fulfilled = function (value) {
var d;
d = __defer();
d.fulfill(value);
return d.promise;
};
__defer.rejected = function (reason) {
var d;
d = __defer();
d.reject(reason);
return d.promise;
};
return __defer;
}());
__generatorToPromise = function (generator, allowSync) {
if (typeof generator !== "object" || generator === null) {
throw new TypeError("Expected generator to be an Object, got " + __typeof(generator));
} else {
if (typeof generator.send !== "function") {
throw new TypeError("Expected generator.send to be a Function, got " + __typeof(generator.send));
}
if (typeof generator["throw"] !== "function") {
throw new TypeError("Expected generator.throw to be a Function, got " + __typeof(generator["throw"]));
}
}
if (allowSync == null) {
allowSync = false;
} else if (typeof allowSync !== "boolean") {
throw new TypeError("Expected allowSync to be a Boolean, got " + __typeof(allowSync));
}
function continuer(verb, arg) {
var item;
try {
item = generator[verb](arg);
} catch (e) {
return __defer.rejected(e);
}
if (item.done) {
return __defer.fulfilled(item.value);
} else {
return item.value.then(callback, errback, allowSync);
}
}
function callback(value) {
return continuer("send", value);
}
function errback(value) {
return continuer("throw", value);
}
return callback(void 0);
};
__import = function (dest, source) {
var k;
for (k in source) {
if (__owns.call(source, k)) {
dest[k] = source[k];
}
}
return dest;
};
__in = typeof Array.prototype.indexOf === "function"
? (function (indexOf) {
return function (child, parent) {
return indexOf.call(parent, child) !== -1;
};
}(Array.prototype.indexOf))
: function (child, parent) {
var i, len;
len = +parent.length;
i = -1;
while (++i < len) {
if (child === parent[i] && i in parent) {
return true;
}
}
return false;
};
__isArray = typeof Array.isArray === "function" ? Array.isArray
: (function (_toString) {
return function (x) {
return _toString.call(x) === "[object Array]";
};
}(Object.prototype.toString));
__owns = Object.prototype.hasOwnProperty;
__promise = function (value, allowSync) {
var factory;
if (allowSync == null) {
allowSync = false;
} else if (typeof allowSync !== "boolean") {
throw new TypeError("Expected allowSync to be a Boolean, got " + __typeof(allowSync));
}
if (typeof value === "function") {
factory = function () {
return __generatorToPromise(value.apply(this, arguments));
};
factory.sync = function () {
return __generatorToPromise(
value.apply(this, arguments),
true
).sync();
};
factory.maybeSync = function () {
return __generatorToPromise(
value.apply(this, arguments),
true
);
};
return factory;
} else {
return __generatorToPromise(value, allowSync);
}
};
__slice = Array.prototype.slice;
__toArray = function (x) {
if (x == null) {
throw new TypeError("Expected an object, got " + __typeof(x));
} else if (__isArray(x)) {
return x;
} else if (typeof x === "string") {
return x.split("");
} else if (typeof x.length === "number") {
return __slice.call(x);
} else {
throw new TypeError("Expected an object with a length property, got " + __typeof(x));
}
};
__toPromise = function (func, context, args) {
var _ref, fulfill, promise, reject;
if (typeof func !== "function") {
throw new TypeError("Expected func to be a Function, got " + __typeof(func));
}
_ref = __defer();
promise = _ref.promise;
reject = _ref.reject;
fulfill = _ref.fulfill;
_ref = null;
func.apply(context, __toArray(args).concat([
function (err, value) {
if (err != null) {
reject(err);
} else {
fulfill(value);
}
}
]));
return promise;
};
__typeof = (function () {
var _toString;
_toString = Object.prototype.toString;
return function (o) {
if (o === void 0) {
return "Undefined";
} else if (o === null) {
return "Null";
} else {
return o.constructor && o.constructor.name || _toString.call(o).slice(8, -1);
}
};
}());
setImmediate = typeof GLOBAL.setImmediate === "function" ? GLOBAL.setImmediate
: typeof process !== "undefined" && typeof process.nextTick === "function"
? (function (nextTick) {
return function (func) {
var args;
if (typeof func !== "function") {
throw new TypeError("Expected func to be a Function, got " + __typeof(func));
}
args = __slice.call(arguments, 1);
if (args.length) {
return nextTick(function () {
func.apply(void 0, __toArray(args));
});
} else {
return nextTick(func);
}
};
}(process.nextTick))
: function (func) {
var args;
if (typeof func !== "function") {
throw new TypeError("Expected func to be a Function, got " + __typeof(func));
}
args = __slice.call(arguments, 1);
if (args.length) {
return setTimeout(
function () {
func.apply(void 0, args);
},
0
);
} else {
return setTimeout(func, 0);
}
};
ParserNode = require("./parser-nodes");
LValue = ParserNode.Value;
LCall = ParserNode.Call;
LInternalCall = ParserNode.InternalCall;
LAccess = ParserNode.Access;
LSymbol = ParserNode.Symbol;
Scope = require("./parser-scope");
MacroContext = require("./parser-macrocontext");
MacroHolder = require("./parser-macroholder");
Type = require("./types");
stringRepeat = require("./utils").stringRepeat;
addParamToScope = require("./parser-utils").addParamToScope;
_ref = require("./utils");
quote = _ref.quote;
unique = _ref.unique;
getPackageVersion = _ref.getPackageVersion;
_ref = null;
function isNothing(node) {
return node instanceof LSymbol.nothing;
}
ParserError = (function (Error) {
var _Error_prototype, _ParserError_prototype;
function ParserError(message, parser, index) {
var _this, err, pos;
_this = this instanceof ParserError ? this : __create(_ParserError_prototype);
if (message == null) {
message = "";
}
_this.message = message;
if (parser == null) {
parser = null;
}
if (index == null) {
index = 0;
}
_this.index = index;
if (parser) {
_this.source = parser.source;
_this.filename = parser.options.filename;
pos = parser.getPosition(index);
_this.line = pos.line;
_this.column = pos.column;
_this.message = message + (" at " + (_this.filename ? _this.filename + ":" : "") + _this.line + ":" + _this.column);
} else {
_this.line = 0;
_this.column = 0;
}
err = Error.call(_this, _this.message);
if (typeof Error.captureStackTrace === "function") {
Error.captureStackTrace(_this, ParserError);
} else if ("stack" in err) {
_this.stack = err.stack;
}
return _this;
}
_Error_prototype = Error.prototype;
_ParserError_prototype = ParserError.prototype = __create(_Error_prototype);
_ParserError_prototype.constructor = ParserError;
ParserError.displayName = "ParserError";
if (typeof Error.extended === "function") {
Error.extended(ParserError);
}
_ParserError_prototype.name = "ParserError";
return ParserError;
}(Error));
MacroError = (function (Error) {
var _Error_prototype, _MacroError_prototype;
function MacroError(inner, parser, index) {
var _this, err, msg, pos;
_this = this instanceof MacroError ? this : __create(_MacroError_prototype);
if (inner == null) {
inner = "";
}
if (parser == null) {
parser = null;
}
if (index == null) {
index = 0;
}
_this.index = index;
if (parser) {
_this.source = parser.source;
_this.filename = parser.options.filename;
pos = parser.getPosition(index);
_this.line = pos.line;
_this.column = pos.column;
msg = [];
if (inner instanceof Error) {
if (__typeof(inner) !== "Error") {
msg.push(__typeof(inner));
msg.push(": ");
}
msg.push(String(inner.message));
} else {
msg.push(String(inner));
}
msg.push(" at ");
if (_this.filename) {
msg.push(String(_this.filename));
msg.push(":");
}
_this._message = msg.join("");
msg.push(_this.line);
msg.push(":");
msg.push(_this.column);
_this.message = msg.join("");
} else {
_this.line = 0;
_this.column = 0;
_this._message = "";
_this.message = "";
}
err = Error.call(_this, _this.message);
if (typeof Error.captureStackTrace === "function") {
Error.captureStackTrace(_this, MacroError);
} else if ("stack" in err) {
_this.stack = err.stack;
}
if (inner instanceof Error) {
_this.inner = inner;
}
return _this;
}
_Error_prototype = Error.prototype;
_MacroError_prototype = MacroError.prototype = __create(_Error_prototype);
_MacroError_prototype.constructor = MacroError;
MacroError.displayName = "MacroError";
if (typeof Error.extended === "function") {
Error.extended(MacroError);
}
_MacroError_prototype.name = "MacroError";
_MacroError_prototype.setPosition = function (line, column) {};
return MacroError;
}(Error));
Box = (function () {
var _Box_prototype;
function Box(index, value) {
var _this;
_this = this instanceof Box ? this : __create(_Box_prototype);
_this.index = index;
_this.value = value;
if (index % 1 !== 0 || index < 0) {
throw new RangeError("Expected index to be a non-negative integer, got " + index);
}
return _this;
}
_Box_prototype = Box.prototype;
Box.displayName = "Box";
return Box;
}());
cache = (function () {
var id;
id = -1;
return function (rule) {
var cacheKey;
cacheKey = ++id;
function f(parser, index) {
var _ref, _ref2, cache, indent, indentCache, inner, item, result;
cache = parser.cache;
indent = parser.indent.peek();
if ((_ref = cache[indent]) != null) {
indentCache = _ref;
} else {
indentCache = cache[indent] = [];
}
if ((_ref = indentCache[_ref2 = index % 16]) != null) {
inner = _ref;
} else {
inner = indentCache[_ref2] = [];
}
item = inner[cacheKey];
if (item && item.start === index) {
return item.result;
} else {
result = rule(parser, index);
inner[cacheKey] = { start: index, result: result };
return result;
}
}
return f;
};
}());
function identity(x) {
return x;
}
function makeReturn(x) {
return function () {
return x;
};
}
function wrap(name, func) {
return func;
}
fromCharCode = (function () {
var f;
f = String.fromCharCode;
return function (charCode) {
if (charCode > 65535) {
return f((charCode - 65536 >> 10) + 55296) + f((charCode - 65536) % 1024 + 56320);
} else {
return f(charCode);
}
};
}());
function processCharCodes(codes, array, start) {
var _i, _len, code;
if (array == null) {
array = [];
}
if (start == null) {
start = 0;
}
for (_len = codes.length, _i = +start, _i < 0 && (_i += _len); _i < _len; ++_i) {
code = codes[_i];
array.push(fromCharCode(code));
}
return array;
}
function codesToString(codes) {
return processCharCodes(codes).join("");
}
function makeAlterStack(name, value) {
return function (rule) {
return function (parser, index) {
var stack;
stack = parser[name];
stack.push(value);
try {
return rule(parser, index);
} finally {
stack.pop();
}
};
};
}
function charsToFakeSet(array) {
var _arr, _end, _i, _len, c, item, obj;
obj = __create(null);
for (_arr = __toArray(array), _i = 0, _len = _arr.length; _i < _len; ++_i) {
item = _arr[_i];
if (typeof item === "number") {
obj[item] = true;
} else {
for (c = +item[0], _end = +item[1]; c <= _end; ++c) {
obj[c] = true;
}
}
}
return obj;
}
function stackWrap(func) {
return func;
}
function character(name, expected) {
return function (parser, index) {
if (parser.source.charCodeAt(index) === expected) {
return Box(index + 1, expected);
} else {
return parser.fail(name, index);
}
};
}
function characters(name, expected) {
return function (parser, index) {
var c;
c = parser.source.charCodeAt(index);
if (expected[c]) {
return Box(index + 1, c);
} else {
return parser.fail(name, index);
}
};
}
mutate = __curry(2, function (mutator, rule) {
if (mutator === identity) {
return rule;
}
if (typeof mutator !== "function") {
mutator = makeReturn(mutator);
}
function f(parser, index) {
var result;
result = rule(parser, index);
if (result) {
return Box(result.index, mutator(result.value, parser, index, result.index));
}
}
f.rule = rule;
f.mutator = mutator;
return f;
});
function bool(rule) {
if (typeof rule.mutator === "function" && typeof rule.rule === "function") {
return bool(rule.rule);
} else {
return mutate(
function (x) {
return !!x;
},
rule
);
}
}
function multiple(rule, minimum, maximum, ignoreValue) {
var mutator;
if (minimum == null) {
minimum = 0;
}
if (maximum == null) {
maximum = 1/0;
}
if (ignoreValue == null) {
ignoreValue = false;
}
if (minimum % 1 !== 0 || minimum < 0) {
throw new RangeError("Expected minimum to be a non-negative integer, got " + minimum);
}
if (maximum !== 1/0 && maximum % 1 !== 0 || maximum < minimum) {
throw new RangeError("Expected maximum to be Infinity or an integer of at least " + minimum + ", got " + maximum);
}
mutator = identity;
if (typeof rule.mutator === "function" && typeof rule.rule === "function" && false) {
mutator = rule.mutator;
rule = rule.rule;
}
if (ignoreValue) {
return function (parser, index) {
var count, item, newIndex;
count = 0;
while (count < maximum) {
item = rule(parser, index);
if (!item) {
if (count < minimum) {
return;
} else {
break;
}
}
++count;
newIndex = item.index;
if (newIndex === index) {
throw new Error("Infinite loop detected");
} else {
index = newIndex;
}
}
return Box(index, count);
};
} else if (mutator === identity) {
return function (parser, index) {
var count, item, newIndex, result;
result = [];
count = 0;
while (count < maximum) {
item = rule(parser, index);
if (!item) {
if (count < minimum) {
return;
} else {
break;
}
}
result[count] = item.value;
++count;
newIndex = item.index;
if (newIndex === index) {
throw new Error("Infinite loop detected");
} else {
index = newIndex;
}
}
return Box(index, result);
};
} else {
return mutate(
function (items, parser, index) {
var _arr, _arr2, _i, _len, item;
_arr = [];
for (_arr2 = __toArray(items), _i = 0, _len = _arr2.length; _i < _len; ++_i) {
item = _arr2[_i];
_arr.push(mutator(item.value, parser, item.startIndex, item.endIndex));
}
return _arr;
},
function (parser, index) {
var count, item, newIndex, result;
result = [];
count = 0;
while (count < maximum) {
item = rule(parser, index);
if (!item) {
if (count < minimum) {
return;
} else {
break;
}
}
newIndex = item.index;
result[count] = { startIndex: index, endIndex: newIndex, value: item.value };
if (newIndex === index) {
throw new Error("Infinite loop detected");
} else {
index = newIndex;
}
++count;
}
return Box(index, result);
}
);
}
}
function zeroOrMore(rule, ignoreValue) {
return multiple(rule, 0, 1/0, ignoreValue);
}
function oneOrMore(rule, ignoreValue) {
return multiple(rule, 1, 1/0, ignoreValue);
}
function maybe(rule, defaultValue) {
var MISSING, mutator, subrule;
MISSING = {};
if (typeof rule.mutator === "function" && typeof rule.rule === "function" && false) {
subrule = rule.rule;
mutator = rule.mutator;
return mutate(
typeof defaultValue === "function"
? function (value, parser, startIndex, endIndex) {
if (value === MISSING) {
return defaultValue(parser, startIndex);
} else {
return mutator(value, parser, startIndex, endIndex);
}
}
: function (value, parser, startIndex, endIndex) {
if (value === MISSING) {
return defaultValue;
} else {
return mutator(value, parser, startIndex, endIndex);
}
},
function (parser, index) {
return subrule(parser, index) || Box(index, MISSING);
}
);
} else if (typeof defaultValue === "function") {
return mutate(
function (value, parser, startIndex, endIndex) {
if (value === MISSING) {
return defaultValue(parser, startIndex);
} else {
return value;
}
},
function (parser, index) {
return rule(parser, index) || Box(index, MISSING);
}
);
} else {
return function (parser, index) {
return rule(parser, index) || Box(index, defaultValue);
};
}
}
function oneOf() {
var _arr, _i, _i2, _len, _len2, expandedRules, func, rule, rules, subrule;
rules = __slice.call(arguments);
switch (rules.length) {
case 0: throw new Error("Expected rules to be non-empty");
case 1: return rules[0];
default:
expandedRules = [];
for (_i = 0, _len = rules.length; _i < _len; ++_i) {
rule = rules[_i];
if (rule.oneOf) {
for (_arr = __toArray(rule.oneOf), _i2 = 0, _len2 = _arr.length; _i2 < _len2; ++_i2) {
subrule = _arr[_i2];
expandedRules.push(subrule);
}
} else {
expandedRules.push(rule);
}
}
func = function (parser, index) {
var _len, i, result, rule;
for (i = 0, _len = expandedRules.length; i < _len; ++i) {
rule = expandedRules[i];
result = rule(parser, index);
if (result) {
return result;
}
}
};
func.oneOf = expandedRules;
return func;
}
}
function zeroOrMoreOf() {
var rules;
rules = __slice.call(arguments);
return zeroOrMore(oneOf.apply(void 0, rules));
}
function oneOrMoreOf() {
var rules;
rules = __slice.call(arguments);
return oneOrMore(oneOf.apply(void 0, rules));
}
function check(rule) {
if (typeof rule.mutator === "function" && typeof rule.rule === "function" && false) {
rule = rule.rule;
}
return function (parser, index) {
var result;
result = rule(parser, index);
if (result) {
return Box(index);
}
};
}
SHORT_CIRCUIT = {};
function sequential() {
var _len, hasMutations, hasOther, i, item, items, key, keys, mapping,
mutations, mutator, rule, rules, shortCircuitIndex, thisIndex;
items = __slice.call(arguments);
if (items.length === 0) {
throw new Error("Expected items to be non-empty");
}
if (items.length === 1) {
if (__isArray(items[0])) {
if (items[0][0] === "this") {
return items[0][1];
}
} else if (typeof items[0] === "function") {
rule = items[0];
return function (parser, index) {
var item;
item = rule(parser, index);
if (!item) {
return;
}
return Box(item.index);
};
}
}
rules = [];
mapping = [];
keys = [];
mutations = [];
thisIndex = -1;
hasOther = false;
shortCircuitIndex = 1/0;
hasMutations = false;
for (i = 0, _len = items.length; i < _len; ++i) {
item = items[i];
key = void 0;
rule = void 0;
if (__isArray(item)) {
if (item.length !== 2) {
throw new Error("Found an array with " + item.length + " length at index #" + i);
}
if (typeof item[0] !== "string") {
throw new TypeError("Array in index #" + i + " has an improper key: " + __typeof(item[0]));
}
if (typeof item[1] !== "function") {
throw new TypeError("Array in index #" + i + " has an improper rule: " + __typeof(item[1]));
}
key = item[0];
if (__in(key, keys)) {
throw new Error("Can only have one " + JSON.stringify(key) + " key in sequential");
}
keys.push(key);
rule = item[1];
if (key === "this") {
thisIndex = rules.length;
} else {
hasOther = true;
}
} else if (typeof item === "function") {
rule = item;
} else if (item === SHORT_CIRCUIT) {
if (shortCircuitIndex !== 1/0) {
throw new Error("Can only have one SHORT_CIRCUIT per sequential");
}
shortCircuitIndex = i;
continue;
} else {
throw new TypeError("Found a non-array, non-function in index #" + i + ": " + __typeof(item));
}
if (key && typeof rule.mutator === "function" && typeof rule.rule === "function" && false) {
hasMutations = true;
mutations.push(rule.mutator);
rules.push(rule.rule);
} else {
mutations.push(null);
rules.push(rule);
}
mapping.push(key);
}
if (thisIndex !== -1) {
if (hasOther) {
throw new Error("Cannot specify both the 'this' key and another key");
}
if (!hasMutations) {
return function (parser, index) {
var _len, i, item, result, rule;
for (i = 0, _len = rules.length; i < _len; ++i) {
rule = rules[i];
item = rule(parser, index);
if (!item) {
if (i < shortCircuitIndex) {
return;
} else {
throw SHORT_CIRCUIT;
}
}
index = item.index;
if (i === thisIndex) {
result = item.value;
}
}
return Box(index, result);
};
} else {
mutator = mutations[thisIndex];
return mutate(
function (item, parser, index) {
return mutator(item.value, parser, item.startIndex, item.endIndex);
},
function (parser, index) {
var _len, i, item, result, rule, valueIndex;
valueIndex = 0;
for (i = 0, _len = rules.length; i < _len; ++i) {
rule = rules[i];
item = rule(parser, index);
if (!item) {
if (i < shortCircuitIndex) {
return;
} else {
throw SHORT_CIRCUIT;
}
}
if (i === thisIndex) {
result = { value: item.value, startIndex: index, endIndex: item.index };
}
index = item.index;
}
return Box(index, result);
}
);
}
} else if (hasOther) {
if (hasMutations) {
return mutate(
function (value, parser, index) {
var _len, i, item, key, mutator, result;
result = {};
for (i = 0, _len = keys.length; i < _len; ++i) {
key = keys[i];
if (key) {
item = value[key];
mutator = mutations[i];
if (mutator) {
result[key] = mutator(item.value, parser, item.startIndex, item.endIndex);
} else {
result[key] = item.value;
}
}
}
return result;
},
function (parser, index) {
var _len, i, indexes, item, key, result, rule;
result = {};
indexes = {};
for (i = 0, _len = rules.length; i < _len; ++i) {
rule = rules[i];
item = rule(parser, index);
if (!item) {
if (i < shortCircuitIndex) {
return;
} else {
throw SHORT_CIRCUIT;
}
}
key = mapping[i];
if (key) {
result[key] = { value: item.value, startIndex: index, endIndex: item.index };
}
index = item.index;
}
return Box(index, result);
}
);
} else {
return function (parser, index) {
var i, item, key, length, rule, value;
value = {};
i = 0;
length = rules.length;
for (; i < length; ++i) {
rule = rules[i];
item = rule(parser, index);
if (!item) {
if (i < shortCircuitIndex) {
return;
} else {
throw SHORT_CIRCUIT;
}
}
index = item.index;
key = mapping[i];
if (key) {
value[key] = item.value;
}
}
return Box(index, value);
};
}
} else {
if (hasMutations) {
throw new Error("Cannot use a mutator on a sequential without keys");
}
return function (parser, index) {
var _len, i, item, rule;
for (i = 0, _len = rules.length; i < _len; ++i) {
rule = rules[i];
item = rule(parser, index);
if (!item) {
if (i < shortCircuitIndex) {
return;
} else {
throw SHORT_CIRCUIT;
}
}
index = item.index;
}
return Box(index);
};
}
}
function cons(headRule, tailRule) {
return function (parser, index) {
var head, tail;
head = headRule(parser, index);
if (!head) {
return;
}
tail = tailRule(parser, head.index);
if (!tail) {
return;
}
return Box(tail.index, [head.value].concat(tail.value));
};
}
function concat(leftRule, rightRule) {
return function (parser, index) {
var left, right;
left = leftRule(parser, index);
if (!left) {
return;
}
right = rightRule(parser, left.index);
if (!right) {
return;
}
return Box(right.index, left.value.concat(right.value));
};
}
function nothingRule(parser, index) {
return Box(index);
}
function separatedList(itemRule, separatorRule, tailRule) {
if (separatorRule == null) {
separatorRule = nothingRule;
}
if (tailRule == null) {
tailRule = itemRule;
}
return function (parser, index) {
var currentIndex, head, i, item, newIndex, result, separator;
head = itemRule(parser, index);
if (!head) {
return;
}
currentIndex = head.index;
result = [head.value];
i = 0;
for (; ; ++i) {
separator = separatorRule(parser, currentIndex);
if (!separator) {
break;
}
item = tailRule(parser, separator.index);
if (!item) {
break;
}
newIndex = item.index;
if (newIndex === currentIndex) {
throw new Error("Infinite loop detected");
} else {
currentIndex = newIndex;
}
result.push(item.value);
}
return Box(currentIndex, result);
};
}
function except(rule) {
if (typeof rule.mutator === "function" && typeof rule.rule === "function" && false) {
rule = rule.rule;
}
return function (parser, index) {
if (!rule(parser, index)) {
return Box(index);
}
};
}
function anyExcept(rule) {
if (typeof rule.mutator === "function" && typeof rule.rule === "function" && false) {
rule = rule.rule;
}
return function (parser, index) {
if (!rule(parser, index)) {
return AnyChar(parser, index);
}
};
}
SpaceChar = characters("space", charsToFakeSet([
9,
11,
12,
32,
160,
5760,
6158,
[8192, 8202],
8239,
8287,
12288,
65263
]));
SpaceChars = cache(zeroOrMore(SpaceChar, true));
Zero = character('"0"', 48);
DecimalDigit = characters("[0-9]", charsToFakeSet([[48, 57]]));
Period = character('"."', 46);
ColonChar = character('":"', 58);
DoubleColonChar = cache((_ref = sequential(ColonChar, ColonChar), mutate("::")(_ref)));
PipeChar = character('"|"', 124);
EqualChar = character('"="', 61);
MinusChar = character('"-"', 45);
PlusChar = character('"+"', 43);
PlusOrMinusChar = characters("[+\\-]", charsToFakeSet([43, 45]));
Letter = characters("letter", charsToFakeSet([
[65, 90],
[97, 122],
170,
181,
186,
[192, 214],
[216, 246],
[248, 705],
[710, 721],
[736, 740],
748,
750,
[880, 884],
886,
887,
[890, 893],
902,
[904, 906],
908,
[910, 929],
[931, 1013],
[1015, 1153],
[1162, 1317],
[1329, 1366],
1369,
[1377, 1415],
[1488, 1514],
[1520, 1522],
[1569, 1610],
1646,
1647,
[1649, 1747],
1749,
1765,
1766,
1774,
1775,
[1786, 1788],
1791,
1808,
[1810, 1839],
[1869, 1957],
1969,
[1994, 2026],
2036,
2037,
2042,
[2048, 2069],
2074,
2084,
2088,
[2308, 2361],
2365,
2384,
[2392, 2401],
2417,
2418,
[2425, 2431],
[2437, 2444],
2447,
2448,
[2451, 2472],
[2474, 2480],
2482,
[2486, 2489],
2493,
2510,
2524,
2525,
[2527, 2529],
2544,
2545,
[2565, 2570],
2575,
2576,
[2579, 2600],
[2602, 2608],
2610,
2611,
2613,
2614,
2616,
2617,
[2649, 2652],
2654,
[2674, 2676],
[2693, 2701],
[2703, 2705],
[2707, 2728],
[2730, 2736],
2738,
2739,
[2741, 2745],
2749,
2768,
2784,
2785,
[2821, 2828],
2831,
2832,
[2835, 2856],
[2858, 2864],
2866,
2867,
[2869, 2873],
2877,
2908,
2909,
[2911, 2913],
2929,
2947,
[2949, 2954],
[2958, 2960],
[2962, 2965],
2969,
2970,
2972,
2974,
2975,
2979,
2980,
[2984, 2986],
[2990, 3001],
3024,
[3077, 3084],
[3086, 3088],
[3090, 3112],
[3114, 3123],
[3125, 3129],
3133,
3160,
3161,
3168,
3169,
[3205, 3212],
[3214, 3216],
[3218, 3240],
[3242, 3251],
[3253, 3257],
3261,
3294,
3296,
3297,
[3333, 3340],
[3342, 3344],
[3346, 3368],
[3370, 3385],
3389,
3424,
3425,
[3450, 3455],
[3461, 3478],
[3482, 3505],
[3507, 3515],
3517,
[3520, 3526],
[3585, 3632],
3634,
3635,
[3648, 3654],
3713,
3714,
3716,
3719,
3720,
3722,
3725,
[3732, 3735],
[3737, 3743],
[3745, 3747],
3749,
3751,
3754,
3755,
[3757, 3760],
3762,
3763,
3773,
[3776, 3780],
3782,
3804,
3805,
3840,
[3904, 3911],
[3913, 3948],
[3976, 3979],
[4096, 4138],
4159,
[4176, 4181],
[4186, 4189],
4193,
4197,
4198,
[4206, 4208],
[4213, 4225],
4238,
[4256, 4293],
[4304, 4346],
4348,
[4352, 4680],
[4682, 4685],
[4688, 4694],
4696,
[4698, 4701],
[4704, 4744],
[4746, 4749],
[4752, 4784],
[4786, 4789],
[4792, 4798],
4800,
[4802, 4805],
[4808, 4822],
[4824, 4880],
[4882, 4885],
[4888, 4954],
[4992, 5007],
[5024, 5108],
[5121, 5740],
[5743, 5759],
[5761, 5786],
[5792, 5866],
[5888, 5900],
[5902, 5905],
[5920, 5937],
[5952, 5969],
[5984, 5996],
[5998, 6000],
[6016, 6067],
6103,
6108,
[6176, 6263],
[6272, 6312],
6314,
[6320, 6389],
[6400, 6428],
[6480, 6509],
[6512, 6516],
[6528, 6571],
[6593, 6599],
[6656, 6678],
[6688, 6740],
6823,
[6917, 6963],
[6981, 6987],
[7043, 7072],
7086,
7087,
[7168, 7203],
[7245, 7247],
[7258, 7293],
[7401, 7404],
[7406, 7409],
[7424, 7615],
[7680, 7957],
[7960, 7965],
[7968, 8005],
[8008, 8013],
[8016, 8023],
8025,
8027,
8029,
[8031, 8061],
[8064, 8116],
[8118, 8124],
8126,
[8130, 8132],
[8134, 8140],
[8144, 8147],
[8150, 8155],
[8160, 8172],
[8178, 8180],
[8182, 8188],
8305,
8319,
[8336, 8340],
8450,
8455,
[8458, 8467],
8469,
[8473, 8477],
8484,
8486,
8488,
[8490, 8493],
[8495, 8505],
[8508, 8511],
[8517, 8521],
8526,
8579,
8580,
[11264, 11310],
[11312, 11358],
[11360, 11492],
[11499, 11502],
[11520, 11557],
[11568, 11621],
11631,
[11648, 11670],
[11680, 11686],
[11688, 11694],
[11696, 11702],
[11704, 11710],
[11712, 11718],
[11720, 11726],
[11728, 11734],
[11736, 11742],
11823,
12293,
12294,
[12337, 12341],
12347,
12348,
[12353, 12438],
[12445, 12447],
[12449, 12538],
[12540, 12543],
[12549, 12589],
[12593, 12686],
[12704, 12727],
[12784, 12799],
[13312, 19893],
[19968, 40907],
[40960, 42124],
[42192, 42237],
[42240, 42508],
[42512, 42527],
42538,
42539,
[42560, 42591],
[42594, 42606],
[42623, 42647],
[42656, 42725],
[42775, 42783],
[42786, 42888],
42891,
42892,
[43003, 43009],
[43011, 43013],
[43015, 43018],
[43020, 43042],
[43072, 43123],
[43138, 43187],
[43250, 43255],
43259,
[43274, 43301],
[43312, 43334],
[43360, 43388],
[43396, 43442],
43471,
[43520, 43560],
[43584, 43586],
[43588, 43595],
[43616, 43638],
43642,
[43648, 43695],
43697,
43701,
43702,
[43705, 43709],
43712,
43714,
[43739, 43741],
[43968, 44002],
[44032, 55203],
[55216, 55238],
[55243, 55291],
[63744, 64045],
[64048, 64109],
[64112, 64217],
[64256, 64262],
[64275, 64279],
64285,
[64287, 64296],
[64298, 64310],
[64312, 64316],
64318,
64320,
64321,
64323,
64324,
[64326, 64433],
[64467, 64829],
[64848, 64911],
[64914, 64967],
[65008, 65019],
[65136, 65140],
[65142, 65262],
[65264, 65276],
[65313, 65338],
[65345, 65370],
[65382, 65470],
[65474, 65479],
[65482, 65487],
[65490, 65495],
[65498, 65500]
]));
NumberChar = characters("number", charsToFakeSet([
[48, 57],
178,
179,
185,
[188, 190],
[1632, 1641],
[1776, 1785],
[1984, 1993],
[2406, 2415],
[2534, 2543],
[2548, 2553],
[2662, 2671],
[2790, 2799],
[2918, 2927],
[3046, 3058],
[3174, 3183],
[3192, 3198],
[3302, 3311],
[3430, 3445],
[3664, 3673],
[3792, 3801],
[3872, 3891],
[4160, 4169],
[4240, 4249],
[4969, 4988],
[5870, 5872],
[6112, 6121],
[6128, 6137],
[6160, 6169],
[6470, 6479],
[6608, 6618],
[6784, 6793],
[6800, 6809],
[6992, 7001],
[7088, 7097],
[7232, 7241],
[7248, 7257],
8304,
[8308, 8313],
[8320, 8329],
[8528, 8578],
[8581, 8585],
[9312, 9371],
[9450, 9471],
[10102, 10131],
11517,
12295,
[12321, 12329],
[12344, 12346],
[12690, 12693],
[12832, 12841],
[12881, 12895],
[12928, 12937],
[12977, 12991],
[42528, 42537],
[42726, 42735],
[43056, 43061],
[43216, 43225],
[43264, 43273],
[43472, 43481],
[43600, 43609],
[44016, 44025],
[65296, 65305]
]));
Underscore = character('"_"', 95);
DollarSignChar = character('"$"', 36);
AtSignChar = character('"@"', 64);
HashSignChar = character('"#"', 35);
PercentSignChar = character('"%"', 37);
EqualSignChar = character('"="', 61);
SymbolChar = characters("symbolic", charsToFakeSet([
33,
35,
37,
38,
42,
43,
45,
47,
[60, 63],
92,
94,
96,
124,
126,
127,
[128, 159],
[161, 169],
[171, 177],
180,
[182, 184],
187,
191,
215,
247,
[706, 709],
[722, 735],
[741, 747],
749,
[751, 879],
885,
888,
889,
[894, 901],
903,
907,
909,
930,
1014,
[1154, 1161],
[1318, 1328],
1367,
1368,
[1370, 1376],
[1416, 1487],
[1515, 1519],
[1523, 1568],
[1611, 1631],
[1642, 1645],
1648,