babel-bridge
Version:
a 'runtime' parsing expression grammar parser
1,694 lines (1,437 loc) • 126 kB
JavaScript
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 22);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
module.exports = require("art-standard-lib");
/***/ }),
/* 1 */
/***/ (function(module, exports) {
module.exports = require("art-class-system");
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(5);
module.exports.addModules({
EmptyNode: __webpack_require__(10),
EmptyOptionalNode: __webpack_require__(26),
Node: __webpack_require__(11),
ScratchNode: __webpack_require__(27)
});
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
var Stats,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
module.exports = Stats = (function(superClass) {
extend(Stats, superClass);
function Stats() {
return Stats.__super__.constructor.apply(this, arguments);
}
Stats._stats = {};
Stats.reset = function() {
return this._stats = {};
};
Stats.add = function(statName, amount) {
if (amount == null) {
amount = 1;
}
return this._stats[statName] = (this._stats[statName] || 0) + amount;
};
Stats.get = function() {
return this._stats;
};
return Stats;
})(__webpack_require__(1).BaseClass);
/***/ }),
/* 4 */
/***/ (function(module, exports) {
module.exports = function(module) {
if(!module.webpackPolyfill) {
module.deprecate = function() {};
module.paths = [];
// module.parent = undefined by default
if(!module.children) module.children = [];
Object.defineProperty(module, "loaded", {
enumerable: true,
get: function() {
return module.l;
}
});
Object.defineProperty(module, "id", {
enumerable: true,
get: function() {
return module.i;
}
});
module.webpackPolyfill = 1;
}
return module;
};
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
var Nodes,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
module.exports = (__webpack_require__(7)).addNamespace('Nodes', Nodes = (function(superClass) {
extend(Nodes, superClass);
function Nodes() {
return Nodes.__super__.constructor.apply(this, arguments);
}
return Nodes;
})(Neptune.PackageNamespace));
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(module) {var Repl, defineModule, formattedInspect, isClass, log, ref;
ref = __webpack_require__(0), defineModule = ref.defineModule, formattedInspect = ref.formattedInspect, isClass = ref.isClass, log = ref.log;
__webpack_require__(32);
defineModule(module, Repl = (function() {
function Repl() {}
Repl.babelBridgeRepl = function(parser) {
if (isClass(parser)) {
parser = new parser;
}
return __webpack_require__(34).start({
prompt: ((parser.getClassName()) + "> ").grey,
"eval": function(command, context, filename, callback) {
var e, parsed, result;
try {
parsed = parser.parse(command.trim());
try {
if (result = typeof parsed.evaluate === "function" ? parsed.evaluate() : void 0) {
return callback(null, result);
} else {
log(formattedInspect(parsed, {
color: true
}));
return callback();
}
} catch (error) {
e = error;
return callback(e);
}
} catch (error) {
e = error;
return callback(parser.getParseFailureInfo({
color: true
}).replace("<HERE>", "<HERE>".red));
}
}
});
};
return Repl;
})());
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4)(module)))
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
var BabelBridge,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
module.exports = (__webpack_require__(33)).addNamespace('BabelBridge', BabelBridge = (function(superClass) {
extend(BabelBridge, superClass);
function BabelBridge() {
return BabelBridge.__super__.constructor.apply(this, arguments);
}
BabelBridge.version = __webpack_require__(19).version;
return BabelBridge;
})(Neptune.PackageNamespace));
__webpack_require__(9);
__webpack_require__(5);
/***/ }),
/* 8 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(module) {var BabelBridgeCompileError, ErrorWithInfo, defineModule, formattedInspect, isFunction, log, mergeInto, ref,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
ref = __webpack_require__(0), defineModule = ref.defineModule, log = ref.log, mergeInto = ref.mergeInto, isFunction = ref.isFunction, formattedInspect = ref.formattedInspect, ErrorWithInfo = ref.ErrorWithInfo;
defineModule(module, BabelBridgeCompileError = (function(superClass) {
extend(BabelBridgeCompileError, superClass);
function BabelBridgeCompileError(message, info) {
BabelBridgeCompileError.__super__.constructor.call(this, message, info, "BabelBridgeCompileError");
}
return BabelBridgeCompileError;
})(ErrorWithInfo));
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4)(module)))
/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
var Extensions,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
module.exports = (__webpack_require__(7)).addNamespace('Extensions', Extensions = (function(superClass) {
extend(Extensions, superClass);
function Extensions() {
return Extensions.__super__.constructor.apply(this, arguments);
}
return Extensions;
})(Neptune.PackageNamespace));
/***/ }),
/* 10 */
/***/ (function(module, exports, __webpack_require__) {
var EmptyNode,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
module.exports = EmptyNode = (function(superClass) {
extend(EmptyNode, superClass);
function EmptyNode() {
return EmptyNode.__super__.constructor.apply(this, arguments);
}
EmptyNode.getter({
present: function() {
return false;
}
});
return EmptyNode;
})(__webpack_require__(11));
/***/ }),
/* 11 */
/***/ (function(module, exports, __webpack_require__) {
var BaseClass, Node, Nodes, Stats, array, arrayWith, compactFlatten, inspectedObjectLiteral, isPlainArray, isPlainObject, log, merge, mergeInto, objectWithout, peek, push, ref,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
ref = __webpack_require__(0), arrayWith = ref.arrayWith, array = ref.array, peek = ref.peek, log = ref.log, push = ref.push, compactFlatten = ref.compactFlatten, objectWithout = ref.objectWithout, isPlainArray = ref.isPlainArray, isPlainObject = ref.isPlainObject, inspectedObjectLiteral = ref.inspectedObjectLiteral, merge = ref.merge, mergeInto = ref.mergeInto;
Nodes = __webpack_require__(5);
BaseClass = __webpack_require__(1).BaseClass;
Stats = __webpack_require__(3);
module.exports = Node = (function(superClass) {
var emptyArray;
extend(Node, superClass);
function Node(parent, options) {
var ref1;
Node.__super__.constructor.apply(this, arguments);
Stats.add("newNode");
this._parent = parent;
this._parser = parent._parser;
this._offset = ((ref1 = options != null ? options.offset : void 0) != null ? ref1 : this._parent.getNextOffset()) | 0;
this._matchLength = 0;
this._ruleName = this._pluralRuleName = this._label = this._pluralLabel = this._pattern = this._nonMatches = this._ruleVariant = this._matches = this._matchPatterns = null;
this._labelsApplied = this._nonMatch = false;
if (options) {
this._matchLength = (options.matchLength || 0) | 0;
this._ruleVariant = options.ruleVariant;
this._matches = options.matches;
this._matchPatterns = options.matchPatterns;
}
}
Node._createSubclassBase = function() {
var NodeSubclass;
return NodeSubclass = (function(superClass1) {
extend(NodeSubclass, superClass1);
function NodeSubclass() {
return NodeSubclass.__super__.constructor.apply(this, arguments);
}
return NodeSubclass;
})(this);
};
Node.createSubclass = function(options) {
var klass;
klass = this._createSubclassBase();
if (options.name) {
klass._name = klass.prototype._name = options.name;
}
if (options.ruleVarient) {
klass.ruleVarient = options.ruleVarient;
klass.rule = klass.ruleVariant.rule;
}
mergeInto(klass.prototype, objectWithout(options, "getter"));
if (options.getter) {
klass.getter(options.getter);
}
return klass;
};
Node.prototype.toString = function() {
return this.text;
};
emptyArray = [];
Node.setter("matches offset matchLength ruleVariant pattern matchPatterns");
Node.getter("parent parser offset matchLength matchPatterns label pluralLabel ruleName pluralRuleName pattern nonMatch", {
realNode: function() {
return this;
},
name: function() {
return this._name || this.ruleName || this["class"].getName();
},
present: function() {
return this._matchLength > 0 || this._nonMatch;
},
matches: function() {
return this._matches || (this._matches = []);
},
source: function() {
return this._parser.source;
},
isRoot: function() {
return this._parser === this._parent;
},
absoluteOffset: function() {
return this._parser.offsetInRootParserSource(this._offset);
},
ancestors: function(into) {
if (into == null) {
into = [];
}
this.parent.getAncestors(into);
into.push(this);
return into;
},
parseInfo: function() {
if (this.subparseInfo) {
return "subparse:" + this.ruleName + ":" + this.offset;
} else {
return this.ruleName + ":" + this.offset;
}
},
rulePath: function() {
var ancestor, ancestorRuleNames;
ancestorRuleNames = (function() {
var j, len, ref1, results;
ref1 = this.ancestors;
results = [];
for (j = 0, len = ref1.length; j < len; j++) {
ancestor = ref1[j];
results.push(ancestor.parseInfo);
}
return results;
}).call(this);
return ancestorRuleNames.join(" > ");
},
nextOffset: function() {
return this.offset + this.matchLength;
},
text: function() {
var matchLength, offset, ref1, source;
ref1 = this.subparseInfo || this, matchLength = ref1.matchLength, offset = ref1.offset, source = ref1.source;
if (matchLength === 0) {
return "";
} else {
return source.slice(offset, offset + matchLength);
}
},
ruleVariant: function() {
var ref1;
return this._ruleVariant || ((ref1 = this._parent) != null ? ref1.ruleVariant : void 0);
},
ruleName: function() {
var ref1;
return this.ruleNameOrNull || ((ref1 = this.parent) != null ? ref1.ruleName : void 0) || ("" + (this.pattern || 'no rule'));
},
ruleNameOrNull: function() {
var ref1, ref2;
return ((ref1 = this["class"].rule) != null ? ref1.getName() : void 0) || ((ref2 = this._ruleVariant) != null ? ref2.rule.getName() : void 0);
},
ruleNameOrPattern: function() {
var ref1;
return this.ruleNameOrNull || ("" + (((ref1 = this.pattern) != null ? ref1.pattern : void 0) || 'no rule'));
},
isRuleNode: function() {
return this["class"].rule;
},
isPassThrough: function() {
var ref1;
return (ref1 = this.ruleVariant) != null ? ref1.isPassThrough : void 0;
},
nonPassThrough: function() {
var ref1;
return !((ref1 = this.ruleVariant) != null ? ref1.isPassThrough : void 0);
}
});
Node.prototype.getNextText = function(length) {
var nextOffset;
nextOffset = this.nextOffset;
return this.source.slice(nextOffset, nextOffset + length);
};
Node.prototype.formattedInspect = function() {
return "CUSTOM";
};
Node.getter({
parseTreePath: function() {
var ref1;
return compactFlatten([(ref1 = this.parent) != null ? ref1.parseTreePath : void 0, this["class"].getName()]);
},
presentMatches: function() {
var j, len, m, ref1, results;
ref1 = this.matches;
results = [];
for (j = 0, len = ref1.length; j < len; j++) {
m = ref1[j];
if (typeof m.getPresent === "function" ? m.getPresent() : void 0) {
results.push(m);
}
}
return results;
},
isNonMatch: function() {
return !!this.nonMatch;
},
isPartialMatch: function() {
var j, len, match, ref1;
if (!this.nonMatch) {
return false;
}
ref1 = this.presentMatches;
for (j = 0, len = ref1.length; j < len; j++) {
match = ref1[j];
if (!match.nonMatch) {
return true;
}
}
return false;
},
isMatch: function() {
return !this.nonMatch;
},
nonMatchingLeaf: function() {
return this.nonMatch && peek(this.matches);
},
firstPartialMatchParent: function() {
if (this.parent === this.parser || this.isPartialMatch) {
return this;
} else {
return this.parent.firstPartialMatchParent;
}
},
inspectedObjects: function(verbose) {
var children, hasOneOrMoreMatchingChildren, label, match, matches, nonMatch, obj, parts, path, ref1, ref2, ref3, ruleName;
match = this;
matches = this.presentMatches;
if (matches.length > 0) {
path = [];
while (matches.length === 1 && ((ref1 = matches[0].matches) != null ? ref1.length : void 0) > 0) {
path.push("" + (match.label ? match.label + ":" : "") + match.ruleName);
match = matches[0];
matches = match.presentMatches;
}
label = match.label, ruleName = match.ruleName, nonMatch = match.nonMatch;
path.push(ruleName);
path = path.join('.');
hasOneOrMoreMatchingChildren = false;
children = (function() {
var j, len, results;
results = [];
for (j = 0, len = matches.length; j < len; j++) {
match = matches[j];
if (!match.nonMatch) {
hasOneOrMoreMatchingChildren = true;
}
results.push(match.getInspectedObjects(verbose));
}
return results;
})();
parts = compactFlatten([
label ? {
label: label
} : void 0, children.length > 0 ? children : match.toString()
]);
if (parts.length === 1) {
parts = parts[0];
}
return (
obj = {},
obj["" + (nonMatch ? hasOneOrMoreMatchingChildren ? 'partialMatch-' : 'nonMatch-' : '') + path] = parts,
obj
);
} else if (this.nonMatch) {
return {
nonMatch: {
offset: this.offset,
pattern: "" + ((ref2 = this.pattern) != null ? ref2.pattern : void 0)
}
};
} else {
if (verbose) {
return {
token: {
offset: this.offset,
length: this.matchLength,
text: this.text,
pattern: "" + ((ref3 = this.pattern) != null ? ref3.pattern : void 0),
"class": this["class"].getName(),
ruleName: this.ruleName
}
};
} else {
return this.text;
}
}
},
detailedInspectedObjects: function() {
var children, match, matches, ret;
matches = this.matches;
if (matches.length > 0) {
children = (function() {
var j, len, results;
results = [];
for (j = 0, len = matches.length; j < len; j++) {
match = matches[j];
results.push(match.detailedInspectedObjects);
}
return results;
})();
ret = {};
ret[this.name] = children.length === 1 ? children[0] : children;
return ret;
} else {
return this.text;
}
},
plainObjects: function() {
var match, ref1, ret;
ret = [
{
inspect: (function(_this) {
return function() {
return _this["class"].getName();
};
})(this)
}
];
if (((ref1 = this._matches) != null ? ref1.length : void 0) > 0) {
ret = ret.concat((function() {
var j, len, ref2, results;
ref2 = this.matches;
results = [];
for (j = 0, len = ref2.length; j < len; j++) {
match = ref2[j];
results.push(match.getPlainObjects());
}
return results;
}).call(this));
} else {
ret = this.text;
}
return ret;
}
});
Node.prototype.find = function(searchName, out) {
var j, len, m, ref1;
if (out == null) {
out = [];
}
ref1 = this.matches;
for (j = 0, len = ref1.length; j < len; j++) {
m = ref1[j];
if (m.getName() === searchName) {
out.push(m);
} else {
m.find(searchName, out);
}
}
return out;
};
Node.prototype.subparse = function(subSource, options) {
return this._parser.subparse(subSource, merge(options, {
parentNode: this
}));
};
/*
IN: pattern, match - instanceof Node
OUT: true if match was added
*/
Node.prototype.addMatch = function(pattern, match) {
if (!match) {
return false;
}
this._matches = push(this._matches, match);
this._matchPatterns = push(this._matchPatterns, pattern);
this._matchLength = match.nextOffset - this.offset;
return true;
};
Node.prototype.applyLabels = function() {
if (!this._matches || this._labelsApplied) {
return;
}
this._labelsApplied = true;
return array(this._matches, (function(_this) {
return function(match, i) {
var label, pattern, pluralLabel, pluralRuleName, ruleName;
pattern = _this._matchPatterns[i];
match._parent = _this;
if (pattern) {
label = pattern.label, ruleName = pattern.ruleName;
match._pattern = pattern;
match._label = label;
match._ruleName = ruleName;
}
if (label) {
match._pluralLabel = pluralLabel = _this.parser.pluralize(label);
}
if (ruleName) {
match._pluralRuleName = pluralRuleName = _this.parser.pluralize(ruleName);
}
label || (label = ruleName);
pluralLabel || (pluralLabel = pluralRuleName);
if (label && !(match instanceof Nodes.EmptyNode)) {
_this._bindToLabelLists(pluralLabel, match);
_this._bindToSingleLabels(label, match);
}
return match.applyLabels();
};
})(this));
};
Node.prototype._bindToLabelLists = function(pluralLabel, match) {
if (this.__proto__[pluralLabel] == null) {
return this[pluralLabel] = push(this[pluralLabel], match);
}
};
Node.prototype._bindToSingleLabels = function(label, match) {
if (this.__proto__[label] == null) {
return this[label] = match;
}
};
Node.prototype._addNonMatch = function(node) {
return (this._nonMatches || (this._nonMatches = [])).push(node);
};
Node.prototype._addToParentAsNonMatch = function() {
if (this._matchLength === 0) {
this._matchLength = 1;
}
if (this.parent) {
if (this.parent.matches) {
if (!(0 <= this.parent.matches.indexOf(this))) {
this._nonMatch = true;
this.parent.matches.push(this);
this.parent._presentMatches = null;
if (this.parent._matchLength === 0) {
this.parent._matchLength = 1;
}
}
return this.parent._addToParentAsNonMatch();
} else {
return this;
}
} else {
return this;
}
};
return Node;
})(BaseClass);
/***/ }),
/* 12 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(module) {var BaseClass, NonMatch, defineModule, log, ref,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
ref = __webpack_require__(0), log = ref.log, defineModule = ref.defineModule;
BaseClass = __webpack_require__(1).BaseClass;
defineModule(module, NonMatch = (function(superClass) {
extend(NonMatch, superClass);
function NonMatch(_node, _patternElement) {
this._node = _node;
this._patternElement = _patternElement;
}
NonMatch.getter("node patternElement", {
inspectedObjects: function() {
return {
NonMatch: {
patternElement: this.toString(),
offset: this.node.offset
}
};
}
});
NonMatch.prototype.toString = function() {
return this.patternElement.ruleVariant.toString();
};
return NonMatch;
})(BaseClass));
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4)(module)))
/***/ }),
/* 13 */
/***/ (function(module, exports, __webpack_require__) {
var EmptyNode, EmptyOptionalNode, Node, PatternElement, inspect, isPlainObject, isRegExp, isString, log, ref, ref1,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
ref = __webpack_require__(2), Node = ref.Node, EmptyNode = ref.EmptyNode, EmptyOptionalNode = ref.EmptyOptionalNode;
ref1 = __webpack_require__(0), isPlainObject = ref1.isPlainObject, isString = ref1.isString, isRegExp = ref1.isRegExp, inspect = ref1.inspect, log = ref1.log;
module.exports = PatternElement = (function(superClass) {
var escapeRegExp;
extend(PatternElement, superClass);
PatternElement.escapeRegExp = escapeRegExp = function(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
};
PatternElement.regExpRegExp = /\/((?:[^\\\/]|\\.)+)\//;
PatternElement.ruleRegExp = /([a-zA-Z0-9_]+)/;
PatternElement.singleQuotedStringRegExp = /'((?:[^\\']|\\.)+)'/;
PatternElement.doubleQuotedStringRegExp = /"((?:[^\\"]|\\.)+)"/;
PatternElement.labelRegExp = /([a-zA-Z0-9_]+)\:/;
PatternElement.patternElementRegExp = RegExp("(?:" + PatternElement.labelRegExp.source + ")?([!&])?(?:" + PatternElement.ruleRegExp.source + "|" + PatternElement.regExpRegExp.source + "|" + PatternElement.singleQuotedStringRegExp.source + "|" + PatternElement.doubleQuotedStringRegExp.source + ")([?*+])?");
PatternElement.allPatternElementsRegExp = RegExp("" + PatternElement.patternElementRegExp.source, "g");
function PatternElement(pattern1, arg) {
this.pattern = pattern1;
this.ruleVariant = (arg != null ? arg : {}).ruleVariant;
PatternElement.__super__.constructor.apply(this, arguments);
this.parse = null;
this._init();
}
PatternElement.prototype.toString = function() {
return "PatternElement(" + this.pattern + ")";
};
PatternElement.getter("isTokenPattern");
PatternElement.property({
label: null,
optional: false,
negative: false,
couldMatch: false,
zeroOrMore: false,
oneOrMore: false,
pattern: null,
ruleName: null
});
PatternElement.getter({
isBasicRulePattern: function() {
return this.ruleName && !this.optional && !this.negative && !this.zeroOrMore && !this.oneOrMore && !this.couldMatch;
},
inspectedObjects: function() {
return {
PatternElement: this.props
};
},
props: function() {
var props;
props = {
pattern: this.pattern
};
if (this.ruleName) {
props.ruleName = this.ruleName;
}
if (this.negative) {
props.negative = true;
}
if (this.zeroOrMore) {
props.zeroOrMore = true;
}
if (this.oneOrMore) {
props.oneOrMore = true;
}
if (this.couldMatch) {
props.couldMatch = true;
}
return props;
}
});
PatternElement.prototype.parse = function(parentNode) {
throw new Error("should be overridden");
};
PatternElement.prototype.parseInto = function(parentNode) {
return !!parentNode.addMatch(this, this.parse(parentNode));
};
PatternElement.prototype._applyParseFlags = function() {
var singleParser;
singleParser = this.parse;
if (this._optional) {
this.parse = function(parentNode) {
var match;
if (match = singleParser(parentNode)) {
return match;
} else {
return new EmptyOptionalNode(parentNode);
}
};
}
if (this._negative) {
this.parse = function(parentNode) {
return parentNode.parser._matchNegative(function() {
var match;
if (match = singleParser(parentNode)) {
return null;
} else {
return new EmptyNode(parentNode);
}
});
};
}
if (this.couldMatch) {
this.parse = function(parentNode) {
if (singleParser(parentNode)) {
return new EmptyNode(parentNode);
}
};
}
if (this._zeroOrMore) {
this.parseInto = (function(_this) {
return function(parentNode) {
var m, matchCount;
matchCount = 0;
while (parentNode.addMatch(_this, m = singleParser(parentNode))) {
matchCount++;
if (m.matchLength === 0) {
break;
}
}
return true;
};
})(this);
}
if (this._oneOrMore) {
return this.parseInto = (function(_this) {
return function(parentNode) {
var m, matchCount;
matchCount = 0;
while (parentNode.addMatch(_this, m = singleParser(parentNode))) {
matchCount++;
if (m.matchLength === 0) {
break;
}
}
return matchCount > 0;
};
})(this);
}
};
PatternElement.prototype._init = function() {
var __, doubleQuotedString, pattern, prefix, ref2, regExp, res, singleQuotedString, string, suffix;
this.parse = this.label = this.ruleName = null;
this.negative = this.couldMatch = this.oneOrMore = this.optional = this.zeroOrMore = false;
this._isTokenPattern = false;
pattern = this.pattern;
if (isPlainObject(pattern)) {
this._initPlainObject(pattern);
} else if (isString(pattern)) {
ref2 = res = pattern.match(PatternElement.patternElementRegExp), __ = ref2[0], this.label = ref2[1], prefix = ref2[2], this.ruleName = ref2[3], regExp = ref2[4], singleQuotedString = ref2[5], doubleQuotedString = ref2[6], suffix = ref2[7];
if (prefix && suffix) {
throw new Error("pattern can only have one prefix: !/& or one suffix: ?/+/*");
}
switch (prefix) {
case "!":
this.negative = true;
break;
case "&":
this.couldMatch = true;
}
switch (suffix) {
case "?":
this.optional = true;
break;
case "+":
this.oneOrMore = true;
break;
case "*":
this.zeroOrMore = true;
}
string = singleQuotedString || doubleQuotedString;
if (this.ruleName) {
this._initRule(this.ruleName);
} else if (regExp) {
this._initRegExp(new RegExp(regExp));
} else if (string) {
this._initRegExp(new RegExp(escapeRegExp(string)));
} else {
throw new Error("invalid pattern: " + pattern);
}
} else if (isRegExp(pattern)) {
this._initRegExp(pattern);
} else {
throw new Error("invalid pattern type: " + (inspect(pattern)));
}
return this._applyParseFlags();
};
PatternElement.prototype._initPlainObject = function(object) {
var parseInto;
this.negative = object.negative, this.oneOrMore = object.oneOrMore, this.zeroOrMore = object.zeroOrMore, this.optional = object.optional, this.parse = object.parse, parseInto = object.parseInto;
if (parseInto) {
this.parseInto = parseInto;
}
if (!(this.parse || parseInto)) {
throw new Error("plain-object pattern definition requires 'parse' or 'parseInto'");
}
};
PatternElement.prototype._initRule = function(ruleName) {
var matchRule;
matchRule = null;
return this.parse = function(parentNode) {
matchRule || (matchRule = parentNode.parser.getRule(ruleName));
return matchRule.parse(parentNode);
};
};
/*
NOTE: regExp.test is 3x faster than .exec in Safari, but about the
same in node/chrome. Safari is 2.5x faster than Chrome/Node in this.
Regexp must have the global flag set, even if we are using the y-flag,
to make .test() set .lastIndex correctly.
SEE: https://jsperf.com/regex-match-length
*/
PatternElement.prototype._initRegExp = function(regExp) {
var flags;
this._isTokenPattern = true;
flags = "yg";
if (regExp.ignoreCase) {
flags += "i";
}
regExp = RegExp(regExp.source, flags);
return this.parse = function(parentNode) {
var nextOffset, source;
nextOffset = parentNode.nextOffset, source = parentNode.source;
regExp.lastIndex = nextOffset;
if (regExp.test(source)) {
return new Node(parentNode, {
offset: nextOffset,
matchLength: regExp.lastIndex - nextOffset
});
}
};
};
return PatternElement;
})(__webpack_require__(1).BaseClass);
/***/ }),
/* 14 */
/***/ (function(module, exports, __webpack_require__) {
var Rule, RuleVariant, Stats, log, merge, objectName, ref, upperCamelCase,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
RuleVariant = __webpack_require__(15);
Stats = __webpack_require__(3);
ref = __webpack_require__(0), merge = ref.merge, upperCamelCase = ref.upperCamelCase, objectName = ref.objectName, log = ref.log;
module.exports = Rule = (function(superClass) {
extend(Rule, superClass);
function Rule(_name, _parserClass, _variants) {
this._name = _name;
this._parserClass = _parserClass;
this._variants = _variants != null ? _variants : [];
}
Rule.getter("nodeClassName name variantNodeClasses", {
numVariants: function() {
return this._variants.length;
}
});
Rule.prototype.addVariant = function(options) {
var v;
this._variants.push(v = new RuleVariant(merge(options, {
variantNumber: this._variants.length + 1,
rule: this,
parserClass: this._parserClass
})));
return v;
};
Rule.getter({
inspectObjects: function() {
return [
{
inspect: (function(_this) {
return function() {
return "<Rule: " + _this._name + ">";
};
})(this)
}, this._variants
];
}
});
Rule.prototype.clone = function() {
return new Rule(this._name, this._parserClass, this._variants.slice());
};
/*
IN:
parentNode: node instance
This provides critical info:
parentNode.source: the source string
parentNode.nextOffset: the index in the source where parsing starts
parentNode.parser: access to the parser object
EFFECT: If returning a new Node, it is expected that node's parent is already set to parentNode
OUT: Node instance if parsing was successful
*/
Rule.prototype.parse = function(parentNode) {
var cached, i, len, match, nextOffset, parser, ref1, v;
Stats.add("parseRule");
parser = parentNode.parser, nextOffset = parentNode.nextOffset;
if (cached = parser._cached(this.name, nextOffset)) {
if (cached === "no_match") {
Stats.add("cacheHitNoMatch");
return null;
} else {
Stats.add("cacheHit");
return cached;
}
}
ref1 = this._variants;
for (i = 0, len = ref1.length; i < len; i++) {
v = ref1[i];
if (match = v.parse(parentNode)) {
return parser._cacheMatch(this.name, match);
}
}
return parser._cacheNoMatch(this.name, nextOffset);
};
return Rule;
})(__webpack_require__(1).BaseClass);
/***/ }),
/* 15 */
/***/ (function(module, exports, __webpack_require__) {
var BaseClass, Node, PatternElement, RuleVariant, ScratchNode, Stats, allPatternElementsRegExp, compactFlatten, inspect, isPlainObject, isString, log, merge, pad, push, ref, ref1, toInspectedObjects, upperCamelCase,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
PatternElement = __webpack_require__(13);
Stats = __webpack_require__(3);
ref = __webpack_require__(2), Node = ref.Node, ScratchNode = ref.ScratchNode;
ref1 = __webpack_require__(0), log = ref1.log, toInspectedObjects = ref1.toInspectedObjects, isPlainObject = ref1.isPlainObject, push = ref1.push, isString = ref1.isString, compactFlatten = ref1.compactFlatten, inspect = ref1.inspect, pad = ref1.pad, upperCamelCase = ref1.upperCamelCase, merge = ref1.merge;
allPatternElementsRegExp = PatternElement.allPatternElementsRegExp;
BaseClass = __webpack_require__(1).BaseClass;
module.exports = RuleVariant = (function(superClass) {
extend(RuleVariant, superClass);
function RuleVariant(options1) {
var ref2;
this.options = options1;
this._toString = null;
if (!isPlainObject(this.options)) {
this.options = {
pattern: this.options
};
}
ref2 = this.options, this.pattern = ref2.pattern, this.rule = ref2.rule, this.parserClass = ref2.parserClass;
this._variantNodeClassName = this.options.variantNodeClassName;
this._initVariantNodeClass(this.options);
if (this.options.parse) {
this.parse = this.options.parse;
}
}
RuleVariant.property({
passThroughRuleName: null
});
RuleVariant.setter("variantNodeClassName");
RuleVariant.getter({
isPassThrough: function() {
return this._passThroughRuleName;
},
name: function() {
return this.variantNodeClassName + "Variant";
},
numVariants: function() {
return this.rule.numVariants;
},
patternElements: function() {
return this._patternElements || (this._patternElements = this._generatePatternElements());
}
});
RuleVariant.prototype._generatePatternElements = function() {
var part, parts, pes;
pes = (function() {
var i, len, results;
if (isString(this.pattern)) {
parts = this.pattern.match(allPatternElementsRegExp);
if (!parts) {
throw new Error("no pattern-parts found in: " + (inspect(this.pattern)));
}
results = [];
for (i = 0, len = parts.length; i < len; i++) {
part = parts[i];
results.push(new PatternElement(part, {
ruleVariant: this
}));
}
return results;
} else {
return [
new PatternElement(this.pattern, {
ruleVariant: this
})
];
}
}).call(this);
pes = compactFlatten(pes);
if (pes.length === 1 && pes[0].isBasicRulePattern) {
this.passThroughRuleName = pes[0].ruleName;
}
return pes;
};
RuleVariant.prototype.inspect = function() {
return this.toString();
};
RuleVariant.prototype.toString = function() {
return this._toString || (this._toString = this.name + ": " + this.patternString);
};
RuleVariant.getter({
patternString: function() {
return this.pattern || (this.options.parse && 'function()');
}
});
/*
see: BabelBridge.Rule#parse
*/
RuleVariant.prototype.parse = function(parentNode) {
var activeRuleVariantParserOffsets, i, len, name, nextOffset, parser, patternElement, previousActiveRuleVariantParserOffset, ref2, scratchNode;
name = this.name;
parser = parentNode.parser, nextOffset = parentNode.nextOffset;
activeRuleVariantParserOffsets = parser.activeRuleVariantParserOffsets;
if (nextOffset === (previousActiveRuleVariantParserOffset = activeRuleVariantParserOffsets[name])) {
throw new Error("leftRecursion detected: RuleVariant: " + name + ", offset: " + nextOffset);
}
activeRuleVariantParserOffsets[name] = nextOffset;
try {
Stats.add("parseVariant");
scratchNode = ScratchNode.checkout(parentNode, this);
parser = parentNode.parser;
ref2 = this.patternElements;
for (i = 0, len = ref2.length; i < len; i++) {
patternElement = ref2[i];
if (!parser.tryPatternElement(patternElement, scratchNode, this)) {
scratchNode.checkin();
return false;
}
}
scratchNode.checkin();
return scratchNode.getRealNode();
} finally {
activeRuleVariantParserOffsets[name] = previousActiveRuleVariantParserOffset;
}
};
RuleVariant.getter({
variantNodeClassName: function() {
var baseName, ref2;
if (this._variantNodeClassName) {
return this._variantNodeClassName;
}
baseName = upperCamelCase(this.rule.name) + "Rule" + (this.pattern ? upperCamelCase(((ref2 = ("" + this.pattern).match(/[a-zA-Z0-9_]+/g)) != null ? ref2.join('_') : void 0) || "") : this.parse ? "CustomParser" : void 0);
return this._variantNodeClassName = baseName;
}
});
/*
OPTIONS:
node / nodeClass
TODO: pick one, I like 'node' today
extends / baseClass / nodeBaseClass
TODO: pick one, I like 'extends' today
*/
RuleVariant.prototype._initVariantNodeClass = function(options) {
var nodeBaseClass, nodeSubclassOptions, rule;
rule = options.rule;
nodeSubclassOptions = options.node || options.nodeClass || options;
nodeBaseClass = options["extends"] || options.baseClass || options.nodeBaseClass || Node;
return this.VariantNodeClass = (typeof nodeClass !== "undefined" && nodeClass !== null ? nodeClass.prototype : void 0) instanceof Node ? nodeClass : nodeBaseClass.createSubclass(merge({
name: this.variantNodeClassName,
ruleVarient: this.ruleVarient
}, nodeSubclassOptions));
};
return RuleVariant;
})(BaseClass);
/***/ }),
/* 16 */
/***/ (function(module, exports, __webpack_require__) {
var Tools, peek;
peek = __webpack_require__(0).peek;
module.exports = Tools = (function() {
var getLineColumn;
function Tools() {}
Tools.getLineColumn = getLineColumn = function(string, offset) {
var lines;
if (string.length === 0 || offset === 0) {
return {
line: 1,
column: 1
};
}
lines = (string.slice(0, offset)).split("\n");
return {
line: lines.length,
column: peek(lines).length + 1
};
};
Tools.getLineColumnString = function(string, offset) {
var column, line, ref;
ref = getLineColumn(string, offset), line = ref.line, column = ref.column;
return line + ":" + column;
};
return Tools;
})();
/***/ }),
/* 17 */
/***/ (function(module, exports, __webpack_require__) {
/* MIT license */
var cssKeywords = __webpack_require__(18);
// NOTE: conversions should only return primitive values (i.e. arrays, or
// values that give correct `typeof` results).
// do not use box values types (i.e. Number(), String(), etc.)
var reverseKeywords = {};
for (var key in cssKeywords) {
if (cssKeywords.hasOwnProperty(key)) {
reverseKeywords[cssKeywords[key]] = key;
}
}
var convert = module.exports = {
rgb: {channels: 3, labels: 'rgb'},
hsl: {channels: 3, labels: 'hsl'},
hsv: {channels: 3, labels: 'hsv'},
hwb: {channels: 3, labels: 'hwb'},
cmyk: {channels: 4, labels: 'cmyk'},
xyz: {channels: 3, labels: 'xyz'},
lab: {channels: 3, labels: 'lab'},
lch: {channels: 3, labels: 'lch'},
hex: {channels: 1, labels: ['hex']},
keyword: {channels: 1, labels: ['keyword']},
ansi16: {channels: 1, labels: ['ansi16']},
ansi256: {channels: 1, labels: ['ansi256']},
hcg: {channels: 3, labels: ['h', 'c', 'g']},
apple: {channels: 3, labels: ['r16', 'g16', 'b16']},
gray: {channels: 1, labels: ['gray']}
};
// hide .channels and .labels properties
for (var model in convert) {
if (convert.hasOwnProperty(model)) {
if (!('channels' in convert[model])) {
throw new Error('missing channels property: ' + model);
}
if (!('labels' in convert[model])) {
throw new Error('missing channel labels property: ' + model);
}
if (convert[model].labels.length !== convert[model].channels) {
throw new Error('channel and label counts mismatch: ' + model);
}
var channels = convert[model].channels;
var labels = convert[model].labels;
delete convert[model].channels;
delete convert[model].labels;
Object.defineProperty(convert[model], 'channels', {value: channels});
Object.defineProperty(convert[model], 'labels', {value: labels});
}
}
convert.rgb.hsl = function (rgb) {
var r = rgb[0] / 255;
var g = rgb[1] / 255;
var b = rgb[2] / 255;
var min = Math.min(r, g, b);
var max = Math.max(r, g, b);
var delta = max - min;
var h;
var s;
var l;
if (max === min) {
h = 0;
} else if (r === max) {
h = (g - b) / delta;
} else if (g === max) {
h = 2 + (b - r) / delta;
} else if (b === max) {
h = 4 + (r - g) / delta;
}
h = Math.min(h * 60, 360);
if (h < 0) {
h += 360;
}
l = (min + max) / 2;
if (max === min) {
s = 0;
} else if (l <= 0.5) {
s = delta / (max + min);
} else {
s = delta / (2 - max - min);
}
return [h, s * 100, l * 100];
};
convert.rgb.hsv = function (rgb) {
var r = rgb[0];
var g = rgb[1];
var b = rgb[2];
var min = Math.min(r, g, b);
var max = Math.max(r, g, b);
var delta = max - min;
var h;
var s;
var v;
if (max === 0) {
s = 0;
} else {
s = (delta / max * 1000) / 10;
}
if (max === min) {
h = 0;
} else if (r === max) {
h = (g - b) / delta;
} else if (g === max) {
h = 2 + (b - r) / delta;
} else if (b === max) {
h = 4 + (r - g) / delta;
}
h = Math.min(h * 60, 360);
if (h < 0) {
h += 360;
}
v = ((max / 255) * 1000) / 10;
return [h, s, v];
};
convert.rgb.hwb = function (rgb) {
var r = rgb[0];
var g = rgb[1];
var b = rgb[2];
var h = convert.rgb.hsl(rgb)[0];
var w = 1 / 255 * Math.min(r, Math.min(g, b));
b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
return [h, w * 100, b * 100];
};
convert.rgb.cmyk = function (rgb) {
var r = rgb[0] / 255;
var g = rgb[1] / 255;
var b = rgb[2] / 255;
var c;
var m;
var y;
var k;
k = Math.min(1 - r, 1 - g, 1 - b);
c = (1 - r - k) / (1 - k) || 0;
m = (1 - g - k) / (1 - k) || 0;
y = (1 - b - k) / (1 - k) || 0;
return [c * 100, m * 100, y * 100, k * 100];
};
/**
* See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
* */
function comparativeDistance(x, y) {
return (
Math.pow(x[0] - y[0], 2) +
Math.pow(x[1] - y[1], 2) +
Math.pow(x[2] - y[2], 2)
);
}
convert.rgb.keyword = function (rgb) {
var reversed = reverseKeywords[rgb];
if (reversed) {
return reversed;
}
var currentClosestDistance = Infinity;
var currentClosestKeyword;
for (var keyword in cssKeywords) {
if (cssKeywords.hasOwnProperty(keyword)) {
var value = cssKeywords[keyword];
// Compute comparative distance
var distance = comparativeDistance(rgb, value);
// Check if its less, if so set as closest
if (distance < currentClosestDistance) {
currentClosestDistance = distance;
currentClosestKeyword = keyword;
}
}
}
return currentClosestKeyword;
};
convert.keyword.rgb = function (keyword) {
return cssKeywords[keyword];
};
convert.rgb.xyz = function (rgb) {
var r = rgb[0] / 255;
var g = rgb[1] / 255;
var b = rgb[2] / 255;
// assume sRGB
r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92);
g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92);
b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92);
var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
return [x * 100, y * 100, z * 100];
};
convert.rgb.lab = function (rgb) {
var xyz = convert.rgb.xyz(rgb);
var x = xyz[0];
var y = xyz[1];
var z = xyz[2];
var l;
var a;
var b;
x /= 95.047;
y /= 100;
z /= 108.883;
x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + (16 / 116);
y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + (16 / 116);
z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + (16 / 116);
l = (116 * y) - 16;
a = 500 * (x - y);
b = 200 * (y - z);
return [l, a, b];
};
convert.hsl.rgb = function (hsl) {
var h = hsl[0] / 360;
var s = hsl[1] / 100;
var l = hsl[2] / 100;
var t1;
var t2;
var t3;
var rgb;
var val;
if (s === 0) {
val = l * 255;
return [val, val, val];
}
if (l < 0.5) {
t2 = l * (1 + s);
} else {
t2 = l + s - l * s;
}
t1 = 2 * l - t2;
rgb = [0, 0, 0];
for (var i = 0; i < 3; i++) {
t3 = h + 1 / 3 * -(i - 1);
if (t3 < 0) {
t3++;
}
if (t3 > 1) {
t3--;
}
if (6 * t3 < 1) {
v