Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dfa

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dfa - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

1311

compile.js

@@ -5,18 +5,2 @@ 'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var _Array$from = _interopDefault(require('babel-runtime/core-js/array/from'));
var _getIterator = _interopDefault(require('babel-runtime/core-js/get-iterator'));
var _get = _interopDefault(require('babel-runtime/helpers/get'));
var _Object$getPrototypeOf = _interopDefault(require('babel-runtime/core-js/object/get-prototype-of'));
var _possibleConstructorReturn = _interopDefault(require('babel-runtime/helpers/possibleConstructorReturn'));
var _inherits = _interopDefault(require('babel-runtime/helpers/inherits'));
var _Set = _interopDefault(require('babel-runtime/core-js/set'));
var _classCallCheck = _interopDefault(require('babel-runtime/helpers/classCallCheck'));
var _createClass = _interopDefault(require('babel-runtime/helpers/createClass'));
var _slicedToArray = _interopDefault(require('babel-runtime/helpers/slicedToArray'));
var _defineProperty = _interopDefault(require('babel-runtime/helpers/defineProperty'));
var _regeneratorRuntime = _interopDefault(require('babel-runtime/regenerator'));
var _Symbol$iterator = _interopDefault(require('babel-runtime/core-js/symbol/iterator'));
/**

@@ -26,70 +10,27 @@ * Returns a new set representing the union of a and b.

function union(a, b) {
var s = new _Set(a);
var s = new Set(a);
addAll(s, b);
return s;
}
/**
* Adds all items from the set b to a.
*/
function addAll(a, b) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = _getIterator(b), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var x = _step.value;
a.add(x);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
for (var x of b) {
a.add(x);
}
}
/**
* Returns whether two sets are equal
*/
function equal(a, b) {
if (a === b) return true;
if (a.size !== b.size) return false;
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = _getIterator(a), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var x = _step2.value;
if (!b.has(x)) {
return false;
}
for (var x of a) {
if (!b.has(x)) {
return false;
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}

@@ -103,66 +44,45 @@

*/
var Node = function () {
function Node() {
_classCallCheck(this, Node);
Object.defineProperty(this, 'followpos', { value: new _Set() });
class Node {
constructor() {
Object.defineProperty(this, 'followpos', {
value: new Set()
});
}
_createClass(Node, [{
key: 'calcFollowpos',
value: function calcFollowpos() {
for (var key in this) {
if (this[key] instanceof Node) {
this[key].calcFollowpos();
}
calcFollowpos() {
for (var key in this) {
if (this[key] instanceof Node) {
this[key].calcFollowpos();
}
}
}]);
}
return Node;
}();
}
/**
* Represents a variable reference
*/
var Variable = function (_Node) {
_inherits(Variable, _Node);
function Variable(name) {
_classCallCheck(this, Variable);
class Variable extends Node {
constructor(name) {
super();
this.name = name;
}
var _this = _possibleConstructorReturn(this, (Variable.__proto__ || _Object$getPrototypeOf(Variable)).call(this));
_this.name = name;
return _this;
copy() {
return new Variable(this.name);
}
_createClass(Variable, [{
key: 'copy',
value: function copy() {
return new Variable(this.name);
}
}]);
return Variable;
}(Node);
}
/**
* Represents a comment
*/
var Comment = function (_Node2) {
_inherits(Comment, _Node2);
function Comment(value) {
_classCallCheck(this, Comment);
var _this2 = _possibleConstructorReturn(this, (Comment.__proto__ || _Object$getPrototypeOf(Comment)).call(this));
_this2.value = value;
return _this2;
class Comment extends Node {
constructor(value) {
super();
this.value = value;
}
return Comment;
}(Node);
}
/**

@@ -172,18 +92,11 @@ * Represents an assignment statement.

*/
var Assignment = function (_Node3) {
_inherits(Assignment, _Node3);
function Assignment(variable, expression) {
_classCallCheck(this, Assignment);
var _this3 = _possibleConstructorReturn(this, (Assignment.__proto__ || _Object$getPrototypeOf(Assignment)).call(this));
_this3.variable = variable;
_this3.expression = expression;
return _this3;
class Assignment extends Node {
constructor(variable, expression) {
super();
this.variable = variable;
this.expression = expression;
}
return Assignment;
}(Node);
}
/**

@@ -193,40 +106,27 @@ * Represents an alternation.

*/
var Alternation = function (_Node4) {
_inherits(Alternation, _Node4);
function Alternation(a, b) {
_classCallCheck(this, Alternation);
class Alternation extends Node {
constructor(a, b) {
super();
this.a = a;
this.b = b;
}
var _this4 = _possibleConstructorReturn(this, (Alternation.__proto__ || _Object$getPrototypeOf(Alternation)).call(this));
get nullable() {
return this.a.nullable || this.b.nullable;
}
_this4.a = a;
_this4.b = b;
return _this4;
get firstpos() {
return union(this.a.firstpos, this.b.firstpos);
}
_createClass(Alternation, [{
key: 'copy',
value: function copy() {
return new Alternation(this.a.copy(), this.b.copy());
}
}, {
key: 'nullable',
get: function get() {
return this.a.nullable || this.b.nullable;
}
}, {
key: 'firstpos',
get: function get() {
return union(this.a.firstpos, this.b.firstpos);
}
}, {
key: 'lastpos',
get: function get() {
return union(this.a.lastpos, this.b.lastpos);
}
}]);
get lastpos() {
return union(this.a.lastpos, this.b.lastpos);
}
return Alternation;
}(Node);
copy() {
return new Alternation(this.a.copy(), this.b.copy());
}
}
/**

@@ -236,79 +136,47 @@ * Represents a concatenation, or chain.

*/
var Concatenation = function (_Node5) {
_inherits(Concatenation, _Node5);
function Concatenation(a, b) {
_classCallCheck(this, Concatenation);
class Concatenation extends Node {
constructor(a, b) {
super();
this.a = a;
this.b = b;
}
var _this5 = _possibleConstructorReturn(this, (Concatenation.__proto__ || _Object$getPrototypeOf(Concatenation)).call(this));
_this5.a = a;
_this5.b = b;
return _this5;
get nullable() {
return this.a.nullable && this.b.nullable;
}
_createClass(Concatenation, [{
key: 'calcFollowpos',
value: function calcFollowpos() {
_get(Concatenation.prototype.__proto__ || _Object$getPrototypeOf(Concatenation.prototype), 'calcFollowpos', this).call(this);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
get firstpos() {
var s = this.a.firstpos;
try {
for (var _iterator = _getIterator(this.a.lastpos), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var n = _step.value;
addAll(n.followpos, this.b.firstpos);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
if (this.a.nullable) {
s = union(s, this.b.firstpos);
}
}, {
key: 'copy',
value: function copy() {
return new Concatenation(this.a.copy(), this.b.copy());
}
}, {
key: 'nullable',
get: function get() {
return this.a.nullable && this.b.nullable;
}
}, {
key: 'firstpos',
get: function get() {
var s = this.a.firstpos;
if (this.a.nullable) {
s = union(s, this.b.firstpos);
}
return s;
return s;
}
get lastpos() {
var s = this.b.lastpos;
if (this.b.nullable) {
s = union(s, this.a.lastpos);
}
}, {
key: 'lastpos',
get: function get() {
var s = this.b.lastpos;
if (this.b.nullable) {
s = union(s, this.a.lastpos);
}
return s;
return s;
}
calcFollowpos() {
super.calcFollowpos();
for (var n of this.a.lastpos) {
addAll(n.followpos, this.b.firstpos);
}
}]);
}
return Concatenation;
}(Node);
copy() {
return new Concatenation(this.a.copy(), this.b.copy());
}
}
/**

@@ -318,80 +186,44 @@ * Represents a repetition.

*/
var Repeat = function (_Node6) {
_inherits(Repeat, _Node6);
function Repeat(expression, op) {
_classCallCheck(this, Repeat);
class Repeat extends Node {
constructor(expression, op) {
super();
this.expression = expression;
this.op = op;
}
var _this6 = _possibleConstructorReturn(this, (Repeat.__proto__ || _Object$getPrototypeOf(Repeat)).call(this));
get nullable() {
return this.op === '*' || this.op === '?';
}
_this6.expression = expression;
_this6.op = op;
return _this6;
get firstpos() {
return this.expression.firstpos;
}
_createClass(Repeat, [{
key: 'calcFollowpos',
value: function calcFollowpos() {
_get(Repeat.prototype.__proto__ || _Object$getPrototypeOf(Repeat.prototype), 'calcFollowpos', this).call(this);
if (this.op === '*' || this.op === '+') {
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
get lastpos() {
return this.expression.lastpos;
}
try {
for (var _iterator2 = _getIterator(this.lastpos), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var n = _step2.value;
calcFollowpos() {
super.calcFollowpos();
addAll(n.followpos, this.firstpos);
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
if (this.op === '*' || this.op === '+') {
for (var n of this.lastpos) {
addAll(n.followpos, this.firstpos);
}
}
}, {
key: 'copy',
value: function copy() {
return new Repeat(this.expression.copy(), this.op);
}
}, {
key: 'nullable',
get: function get() {
return this.op === '*' || this.op === '?';
}
}, {
key: 'firstpos',
get: function get() {
return this.expression.firstpos;
}
}, {
key: 'lastpos',
get: function get() {
return this.expression.lastpos;
}
}]);
}
return Repeat;
}(Node);
copy() {
return new Repeat(this.expression.copy(), this.op);
}
function buildRepetition(expression) {
var min = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var max = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity;
}
function buildRepetition(expression, min = 0, max = Infinity) {
if (min < 0 || min > max) {
throw new Error('Invalid repetition range: ' + min + ' ' + max);
throw new Error("Invalid repetition range: ".concat(min, " ").concat(max));
}
var res = null;
for (var i = 0; i < min; i++) {

@@ -419,3 +251,2 @@ res = concat(res, expression.copy());

}
/**

@@ -425,31 +256,17 @@ * Base class for leaf nodes

var Leaf = function (_Node7) {
_inherits(Leaf, _Node7);
function Leaf() {
_classCallCheck(this, Leaf);
class Leaf extends Node {
get nullable() {
return false;
}
return _possibleConstructorReturn(this, (Leaf.__proto__ || _Object$getPrototypeOf(Leaf)).apply(this, arguments));
get firstpos() {
return new Set([this]);
}
_createClass(Leaf, [{
key: 'nullable',
get: function get() {
return false;
}
}, {
key: 'firstpos',
get: function get() {
return new _Set([this]);
}
}, {
key: 'lastpos',
get: function get() {
return new _Set([this]);
}
}]);
get lastpos() {
return new Set([this]);
}
return Leaf;
}(Node);
}
/**

@@ -460,39 +277,18 @@ * Represents a literal value, e.g. a number

var Literal = function (_Leaf) {
_inherits(Literal, _Leaf);
class Literal extends Leaf {
constructor(value) {
super();
this.value = value;
}
function Literal(value) {
_classCallCheck(this, Literal);
var _this8 = _possibleConstructorReturn(this, (Literal.__proto__ || _Object$getPrototypeOf(Literal)).call(this));
_this8.value = value;
return _this8;
copy() {
return new Literal(this.value);
}
_createClass(Literal, [{
key: 'copy',
value: function copy() {
return new Literal(this.value);
}
}]);
return Literal;
}(Leaf);
}
/**
* Marks the end of an expression
*/
var EndMarker = function (_Leaf2) {
_inherits(EndMarker, _Leaf2);
function EndMarker() {
_classCallCheck(this, EndMarker);
return _possibleConstructorReturn(this, (EndMarker.__proto__ || _Object$getPrototypeOf(EndMarker)).apply(this, arguments));
}
return EndMarker;
}(Leaf);
class EndMarker extends Leaf {}
/**

@@ -502,45 +298,33 @@ * Represents a tag

*/
var Tag = function (_Leaf3) {
_inherits(Tag, _Leaf3);
function Tag(name) {
_classCallCheck(this, Tag);
class Tag extends Leaf {
constructor(name) {
super();
this.name = name;
}
var _this10 = _possibleConstructorReturn(this, (Tag.__proto__ || _Object$getPrototypeOf(Tag)).call(this));
get nullable() {
return true;
}
_this10.name = name;
return _this10;
copy() {
return new Tag(this.name);
}
_createClass(Tag, [{
key: 'copy',
value: function copy() {
return new Tag(this.name);
}
}, {
key: 'nullable',
get: function get() {
return true;
}
}]);
}
return Tag;
}(Leaf);
var nodes = Object.freeze({
Node: Node,
Variable: Variable,
Comment: Comment,
Assignment: Assignment,
Alternation: Alternation,
Concatenation: Concatenation,
Repeat: Repeat,
buildRepetition: buildRepetition,
Literal: Literal,
EndMarker: EndMarker,
Tag: Tag
var nodes = /*#__PURE__*/Object.freeze({
Node: Node,
Variable: Variable,
Comment: Comment,
Assignment: Assignment,
Alternation: Alternation,
Concatenation: Concatenation,
Repeat: Repeat,
buildRepetition: buildRepetition,
Literal: Literal,
EndMarker: EndMarker,
Tag: Tag
});
var require$$0 = ( nodes && nodes['default'] ) || nodes;
function peg$subclass(child, parent) {

@@ -550,2 +334,3 @@ function ctor() {

}
ctor.prototype = parent.prototype;

@@ -571,7 +356,6 @@ child.prototype = new ctor();

var DESCRIBE_EXPECTATION_FNS = {
literal: function literal(expectation) {
literal: function (expectation) {
return "\"" + literalEscape(expectation.text) + "\"";
},
"class": function _class(expectation) {
"class": function (expectation) {
var escapedParts = "",

@@ -586,12 +370,9 @@ i;

},
any: function any(expectation) {
any: function (expectation) {
return "any character";
},
end: function end(expectation) {
end: function (expectation) {
return "end of input";
},
other: function other(expectation) {
other: function (expectation) {
return expectation.description;

@@ -643,2 +424,3 @@ }

}
descriptions.length = j;

@@ -670,5 +452,7 @@ }

var peg$FAILED = {},
peg$startRuleFunctions = { rules: peg$parserules },
peg$startRuleFunctions = {
rules: peg$parserules
},
peg$startRuleFunction = peg$parserules,
peg$c0 = function peg$c0(s) {
peg$c0 = function (s) {
return s;

@@ -682,3 +466,3 @@ },

peg$c6 = peg$classExpectation(["\r", "\n"], false, false),
peg$c7 = function peg$c7(v) {
peg$c7 = function (v) {
return new n.Comment(v.join(''));

@@ -690,6 +474,6 @@ },

peg$c11 = peg$literalExpectation(";", false),
peg$c12 = function peg$c12(v, e) {
peg$c12 = function (v, e) {
return new n.Assignment(v, e);
},
peg$c13 = function peg$c13(v) {
peg$c13 = function (v) {
return new n.Variable(v);

@@ -699,6 +483,6 @@ },

peg$c15 = peg$literalExpectation("|", false),
peg$c16 = function peg$c16(a, b) {
peg$c16 = function (a, b) {
return new n.Alternation(a, b);
},
peg$c17 = function peg$c17(a, b) {
peg$c17 = function (a, b) {
return new n.Concatenation(a, b);

@@ -708,3 +492,3 @@ },

peg$c19 = peg$literalExpectation(":", false),
peg$c20 = function peg$c20(t, e) {
peg$c20 = function (t, e) {
return new n.Concatenation(e, new n.Tag(t));

@@ -714,3 +498,3 @@ },

peg$c22 = peg$literalExpectation("*", false),
peg$c23 = function peg$c23(t) {
peg$c23 = function (t) {
return new n.Repeat(t, '*');

@@ -720,3 +504,3 @@ },

peg$c25 = peg$literalExpectation("?", false),
peg$c26 = function peg$c26(t) {
peg$c26 = function (t) {
return new n.Repeat(t, '?');

@@ -726,3 +510,3 @@ },

peg$c28 = peg$literalExpectation("+", false),
peg$c29 = function peg$c29(t) {
peg$c29 = function (t) {
return new n.Repeat(t, '+');

@@ -734,3 +518,3 @@ },

peg$c33 = peg$literalExpectation("}", false),
peg$c34 = function peg$c34(t, m) {
peg$c34 = function (t, m) {
return n.buildRepetition(t, m, m);

@@ -740,12 +524,12 @@ },

peg$c36 = peg$literalExpectation(",", false),
peg$c37 = function peg$c37(t, min) {
peg$c37 = function (t, min) {
return n.buildRepetition(t, min, Infinity);
},
peg$c38 = function peg$c38(t, max) {
peg$c38 = function (t, max) {
return n.buildRepetition(t, 0, max);
},
peg$c39 = function peg$c39(t, min, max) {
peg$c39 = function (t, min, max) {
return n.buildRepetition(t, min, max);
},
peg$c40 = function peg$c40(x) {
peg$c40 = function (x) {
return new n.Literal(x);

@@ -757,9 +541,6 @@ },

peg$c44 = peg$literalExpectation(")", false),
peg$c45 = function peg$c45(e) {
peg$c45 = function (e) {
return e;
},
peg$c46 = function peg$c46() {
return n.buildRepetition();
},
peg$c47 = function peg$c47(a, b) {
peg$c47 = function (a, b) {
return a + b.join('');

@@ -773,3 +554,3 @@ },

peg$c53 = peg$classExpectation([["0", "9"]], false, false),
peg$c54 = function peg$c54(num) {
peg$c54 = function (num) {
return parseInt(num.join(''));

@@ -780,7 +561,8 @@ },

peg$currPos = 0,
peg$savedPos = 0,
peg$posDetailsCache = [{ line: 1, column: 1 }],
peg$posDetailsCache = [{
line: 1,
column: 1
}],
peg$maxFailPos = 0,
peg$maxFailExpected = [],
peg$silentFails = 0,
peg$result;

@@ -796,42 +578,25 @@

function text() {
return input.substring(peg$savedPos, peg$currPos);
}
function location() {
return peg$computeLocation(peg$savedPos, peg$currPos);
}
function expected(description, location) {
location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos);
throw peg$buildStructuredError([peg$otherExpectation(description)], input.substring(peg$savedPos, peg$currPos), location);
}
function error(message, location) {
location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos);
throw peg$buildSimpleError(message, location);
}
function peg$literalExpectation(text, ignoreCase) {
return { type: "literal", text: text, ignoreCase: ignoreCase };
return {
type: "literal",
text: text,
ignoreCase: ignoreCase
};
}
function peg$classExpectation(parts, inverted, ignoreCase) {
return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase };
return {
type: "class",
parts: parts,
inverted: inverted,
ignoreCase: ignoreCase
};
}
function peg$anyExpectation() {
return { type: "any" };
}
function peg$endExpectation() {
return { type: "end" };
return {
type: "end"
};
}
function peg$otherExpectation(description) {
return { type: "other", description: description };
}
function peg$computePosDetails(pos) {

@@ -845,2 +610,3 @@ var details = peg$posDetailsCache[pos],

p = pos - 1;
while (!peg$posDetailsCache[p]) {

@@ -875,3 +641,2 @@ p--;

endPosDetails = peg$computePosDetails(endPos);
return {

@@ -904,6 +669,2 @@ start: {

function peg$buildSimpleError(message, location) {
return new peg$SyntaxError(message, null, null, location);
}
function peg$buildStructuredError(expected, found, location) {

@@ -915,5 +676,5 @@ return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);

var s0, s1;
s0 = [];
s1 = peg$parsestatement();
if (s1 !== peg$FAILED) {

@@ -933,9 +694,9 @@ while (s1 !== peg$FAILED) {

var s0, s1, s2;
s0 = peg$currPos;
s1 = peg$parsestatement_type();
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c0(s1);

@@ -957,4 +718,4 @@ s0 = s1;

var s0;
s0 = peg$parseassignment();
s0 = peg$parseassignment();
if (s0 === peg$FAILED) {

@@ -969,4 +730,4 @@ s0 = peg$parsecomment();

var s0, s1, s2, s3;
s0 = peg$currPos;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 35) {

@@ -977,8 +738,11 @@ s1 = peg$c1;

s1 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c2);
}
}
if (s1 !== peg$FAILED) {
s2 = [];
if (peg$c3.test(input.charAt(peg$currPos))) {

@@ -989,8 +753,11 @@ s3 = input.charAt(peg$currPos);

s3 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c4);
}
}
while (s3 !== peg$FAILED) {
s2.push(s3);
if (peg$c3.test(input.charAt(peg$currPos))) {

@@ -1001,3 +768,4 @@ s3 = input.charAt(peg$currPos);

s3 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c4);

@@ -1007,2 +775,3 @@ }

}
if (s2 !== peg$FAILED) {

@@ -1014,8 +783,9 @@ if (peg$c5.test(input.charAt(peg$currPos))) {

s3 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c6);
}
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c7(s2);

@@ -1041,7 +811,8 @@ s0 = s1;

var s0, s1, s2, s3, s4, s5, s6, s7;
s0 = peg$currPos;
s1 = peg$parsevariable();
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {

@@ -1053,12 +824,17 @@ if (input.charCodeAt(peg$currPos) === 61) {

s3 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c9);
}
}
if (s3 !== peg$FAILED) {
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
s5 = peg$parsealternation();
if (s5 !== peg$FAILED) {
s6 = peg$parse_();
if (s6 !== peg$FAILED) {

@@ -1070,8 +846,9 @@ if (input.charCodeAt(peg$currPos) === 59) {

s7 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c11);
}
}
if (s7 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c12(s1, s5);

@@ -1113,11 +890,10 @@ s0 = s1;

var s0, s1;
s0 = peg$currPos;
s1 = peg$parsename();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c13(s1);
}
s0 = s1;
return s0;

@@ -1128,7 +904,8 @@ }

var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
s1 = peg$parseconcatenation();
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {

@@ -1140,12 +917,15 @@ if (input.charCodeAt(peg$currPos) === 124) {

s3 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c15);
}
}
if (s3 !== peg$FAILED) {
s4 = peg$parse_();
if (s4 !== peg$FAILED) {
s5 = peg$parsealternation();
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c16(s1, s5);

@@ -1173,2 +953,3 @@ s0 = s1;

}
if (s0 === peg$FAILED) {

@@ -1183,11 +964,12 @@ s0 = peg$parseconcatenation();

var s0, s1, s2, s3;
s0 = peg$currPos;
s1 = peg$parserepeat();
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
if (s2 !== peg$FAILED) {
s3 = peg$parseconcatenation();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c17(s1, s3);

@@ -1207,2 +989,3 @@ s0 = s1;

}
if (s0 === peg$FAILED) {

@@ -1217,5 +1000,5 @@ s0 = peg$parserepeat();

var s0, s1, s2, s3, s4, s5, s6;
s0 = peg$currPos;
s1 = peg$parsename();
if (s1 !== peg$FAILED) {

@@ -1227,10 +1010,12 @@ if (input.charCodeAt(peg$currPos) === 58) {

s2 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c19);
}
}
if (s2 !== peg$FAILED) {
s3 = peg$parserepeat();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c20(s1, s3);

@@ -1250,5 +1035,7 @@ s0 = s1;

}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseterm();
if (s1 !== peg$FAILED) {

@@ -1260,8 +1047,9 @@ if (input.charCodeAt(peg$currPos) === 42) {

s2 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c22);
}
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c23(s1);

@@ -1277,5 +1065,7 @@ s0 = s1;

}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseterm();
if (s1 !== peg$FAILED) {

@@ -1287,8 +1077,9 @@ if (input.charCodeAt(peg$currPos) === 63) {

s2 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c25);
}
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c26(s1);

@@ -1304,5 +1095,7 @@ s0 = s1;

}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseterm();
if (s1 !== peg$FAILED) {

@@ -1314,8 +1107,9 @@ if (input.charCodeAt(peg$currPos) === 43) {

s2 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c28);
}
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c29(s1);

@@ -1331,5 +1125,7 @@ s0 = s1;

}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseterm();
if (s1 !== peg$FAILED) {

@@ -1341,8 +1137,11 @@ if (input.charCodeAt(peg$currPos) === 123) {

s2 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c31);
}
}
if (s2 !== peg$FAILED) {
s3 = peg$parsenumber();
if (s3 !== peg$FAILED) {

@@ -1354,8 +1153,9 @@ if (input.charCodeAt(peg$currPos) === 125) {

s4 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c33);
}
}
if (s4 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c34(s1, s3);

@@ -1379,5 +1179,7 @@ s0 = s1;

}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseterm();
if (s1 !== peg$FAILED) {

@@ -1389,8 +1191,11 @@ if (input.charCodeAt(peg$currPos) === 123) {

s2 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c31);
}
}
if (s2 !== peg$FAILED) {
s3 = peg$parsenumber();
if (s3 !== peg$FAILED) {

@@ -1402,6 +1207,8 @@ if (input.charCodeAt(peg$currPos) === 44) {

s4 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c36);
}
}
if (s4 !== peg$FAILED) {

@@ -1413,8 +1220,9 @@ if (input.charCodeAt(peg$currPos) === 125) {

s5 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c33);
}
}
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c37(s1, s3);

@@ -1442,5 +1250,7 @@ s0 = s1;

}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseterm();
if (s1 !== peg$FAILED) {

@@ -1452,6 +1262,8 @@ if (input.charCodeAt(peg$currPos) === 123) {

s2 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c31);
}
}
if (s2 !== peg$FAILED) {

@@ -1463,8 +1275,11 @@ if (input.charCodeAt(peg$currPos) === 44) {

s3 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c36);
}
}
if (s3 !== peg$FAILED) {
s4 = peg$parsenumber();
if (s4 !== peg$FAILED) {

@@ -1476,8 +1291,9 @@ if (input.charCodeAt(peg$currPos) === 125) {

s5 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c33);
}
}
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c38(s1, s4);

@@ -1505,5 +1321,7 @@ s0 = s1;

}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseterm();
if (s1 !== peg$FAILED) {

@@ -1515,8 +1333,11 @@ if (input.charCodeAt(peg$currPos) === 123) {

s2 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c31);
}
}
if (s2 !== peg$FAILED) {
s3 = peg$parsenumber();
if (s3 !== peg$FAILED) {

@@ -1528,8 +1349,11 @@ if (input.charCodeAt(peg$currPos) === 44) {

s4 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c36);
}
}
if (s4 !== peg$FAILED) {
s5 = peg$parsenumber();
if (s5 !== peg$FAILED) {

@@ -1541,8 +1365,9 @@ if (input.charCodeAt(peg$currPos) === 125) {

s6 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c33);
}
}
if (s6 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c39(s1, s3, s5);

@@ -1574,2 +1399,3 @@ s0 = s1;

}
if (s0 === peg$FAILED) {

@@ -1591,14 +1417,17 @@ s0 = peg$parseterm();

var s0, s1, s2, s3;
s0 = peg$parsevariable();
s0 = peg$parsevariable();
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parsenumber();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c40(s1);
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 40) {

@@ -1609,8 +1438,11 @@ s1 = peg$c41;

s1 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c42);
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parsealternation();
if (s2 !== peg$FAILED) {

@@ -1622,8 +1454,9 @@ if (input.charCodeAt(peg$currPos) === 41) {

s3 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c44);
}
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c45(s2);

@@ -1649,55 +1482,11 @@ s0 = s1;

function peg$parserepetition() {
var s0, s1, s2, s3;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 123) {
s1 = peg$c30;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c31);
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parsenumber();
if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 125) {
s3 = peg$c32;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c33);
}
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c46();
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parsename() {
var s0, s1, s2, s3;
s0 = peg$currPos;
s1 = peg$parsename_start_char();
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$parsename_char();
while (s3 !== peg$FAILED) {

@@ -1707,4 +1496,4 @@ s2.push(s3);

}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c47(s1, s2);

@@ -1732,6 +1521,8 @@ s0 = s1;

s0 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c49);
}
}
if (s0 === peg$FAILED) {

@@ -1743,3 +1534,4 @@ if (peg$c50.test(input.charAt(peg$currPos))) {

s0 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c51);

@@ -1755,4 +1547,4 @@ }

var s0;
s0 = peg$parsename_start_char();
s0 = peg$parsename_start_char();
if (s0 === peg$FAILED) {

@@ -1764,3 +1556,4 @@ if (peg$c52.test(input.charAt(peg$currPos))) {

s0 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c53);

@@ -1776,5 +1569,5 @@ }

var s0, s1, s2;
s0 = peg$currPos;
s1 = [];
if (peg$c52.test(input.charAt(peg$currPos))) {

@@ -1785,9 +1578,12 @@ s2 = input.charAt(peg$currPos);

s2 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c53);
}
}
if (s2 !== peg$FAILED) {
while (s2 !== peg$FAILED) {
s1.push(s2);
if (peg$c52.test(input.charAt(peg$currPos))) {

@@ -1798,3 +1594,4 @@ s2 = input.charAt(peg$currPos);

s2 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c53);

@@ -1807,8 +1604,8 @@ }

}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c54(s1);
}
s0 = s1;
return s0;

@@ -1819,4 +1616,4 @@ }

var s0, s1;
s0 = [];
s0 = [];
if (peg$c55.test(input.charAt(peg$currPos))) {

@@ -1827,8 +1624,11 @@ s1 = input.charAt(peg$currPos);

s1 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c56);
}
}
while (s1 !== peg$FAILED) {
s0.push(s1);
if (peg$c55.test(input.charAt(peg$currPos))) {

@@ -1839,3 +1639,4 @@ s1 = input.charAt(peg$currPos);

s1 = peg$FAILED;
if (peg$silentFails === 0) {
{
peg$fail(peg$c56);

@@ -1849,4 +1650,3 @@ }

var n = require$$0;
var n = nodes;
peg$result = peg$startRuleFunction();

@@ -1874,8 +1674,4 @@

var SymbolTable = function () {
function SymbolTable(statements) {
var externalSymbols = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_classCallCheck(this, SymbolTable);
class SymbolTable {
constructor(statements, externalSymbols = {}) {
this.variables = {};

@@ -1885,3 +1681,2 @@ this.symbols = {};

this.size = 0;
this.addExternalSymbols(externalSymbols);

@@ -1891,78 +1686,50 @@ this.process(statements);

_createClass(SymbolTable, [{
key: 'addExternalSymbols',
value: function addExternalSymbols(externalSymbols) {
for (var key in externalSymbols) {
this.variables[key] = new Literal(externalSymbols[key]);
this.symbols[key] = externalSymbols[key];
this.size++;
}
addExternalSymbols(externalSymbols) {
for (var key in externalSymbols) {
this.variables[key] = new Literal(externalSymbols[key]);
this.symbols[key] = externalSymbols[key];
this.size++;
}
}, {
key: 'process',
value: function process(statements) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
}
try {
for (var _iterator = _getIterator(statements), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var statement = _step.value;
process(statements) {
for (var statement of statements) {
if (statement instanceof Assignment) {
this.variables[statement.variable.name] = this.processExpression(statement.expression);
if (statement instanceof Assignment) {
this.variables[statement.variable.name] = this.processExpression(statement.expression);
if (statement.expression instanceof Literal) {
this.symbols[statement.variable.name] = statement.expression.value;
this.size++;
}
}
if (statement.expression instanceof Literal) {
this.symbols[statement.variable.name] = statement.expression.value;
this.size++;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
this.main = this.variables.main;
if (!this.main) {
throw new Error('No main variable declaration found');
}
this.main = this.variables.main;
if (!this.main) {
throw new Error('No main variable declaration found');
}
}, {
key: 'processExpression',
value: function processExpression(expr) {
// Process children
for (var key in expr) {
if (expr[key] instanceof Node) {
expr[key] = this.processExpression(expr[key]);
}
}
processExpression(expr) {
// Process children
for (var key in expr) {
if (expr[key] instanceof Node) {
expr[key] = this.processExpression(expr[key]);
}
} // Replace variable references with their values
// Replace variable references with their values
if (expr instanceof Variable) {
var value = this.variables[expr.name];
if (value == null) throw new Error('Undeclared indentifier ' + expr.name);
expr = this.processExpression(value.copy());
}
return expr;
if (expr instanceof Variable) {
var value = this.variables[expr.name];
if (value == null) throw new Error("Undeclared indentifier ".concat(expr.name));
expr = this.processExpression(value.copy());
}
}]);
return SymbolTable;
}();
return expr;
}
}
var END_MARKER = new EndMarker();
/**

@@ -1975,11 +1742,10 @@ * This is an implementation of the direct regular expression to DFA algorithm described

*/
function buildDFA(root, numSymbols) {
root = new Concatenation(root, END_MARKER);
root.calcFollowpos();
var failState = new State(new _Set(), numSymbols);
var failState = new State(new Set(), numSymbols);
var initialState = new State(root.firstpos, numSymbols);
var dstates = [failState, initialState];
var dstates = [failState, initialState]; // while there is an unmarked state S in dstates
// while there is an unmarked state S in dstates
while (1) {

@@ -1997,37 +1763,16 @@ var s = null;

break;
}
} // mark S
// mark S
s.marked = true;
// for each input symbol a
s.marked = true; // for each input symbol a
for (var a = 0; a < numSymbols; a++) {
// let U be the union of followpos(p) for all
// p in S that correspond to a
var u = new _Set();
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
var u = new Set();
try {
for (var _iterator = _getIterator(s.positions), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var p = _step.value;
if (p instanceof Literal && p.value === a) {
addAll(u, p.followpos);
}
for (var p of s.positions) {
if (p instanceof Literal && p.value === a) {
addAll(u, p.followpos);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}

@@ -2037,6 +1782,7 @@

continue;
}
} // if U is not in dstates
// if U is not in dstates
var ux = -1;
for (var i = 0; i < dstates.length; i++) {

@@ -2062,19 +1808,11 @@ if (equal(u, dstates[i].positions)) {

var State = function State(positions, len) {
_classCallCheck(this, State);
class State {
constructor(positions, len) {
this.positions = positions;
this.transitions = new Uint16Array(len);
this.accepting = positions.has(END_MARKER);
this.marked = false;
this.tags = new Set();
this.positions = positions;
this.transitions = new Uint16Array(len);
this.accepting = positions.has(END_MARKER);
this.marked = false;
this.tags = new _Set();
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = _getIterator(positions), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var pos = _step2.value;
for (var pos of positions) {
if (pos instanceof Tag) {

@@ -2084,21 +1822,8 @@ this.tags.add(pos.name);

}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
};
}
var INITIAL_STATE = 1;
var FAIL_STATE = 0;
/**

@@ -2109,6 +1834,4 @@ * A StateMachine represents a deterministic finite automaton.

var StateMachine = function () {
function StateMachine(dfa) {
_classCallCheck(this, StateMachine);
class StateMachine {
constructor(dfa) {
this.stateTable = dfa.stateTable;

@@ -2118,3 +1841,2 @@ this.accepting = dfa.accepting;

}
/**

@@ -2126,155 +1848,69 @@ * Returns an iterable object that yields pattern matches over the input sequence.

_createClass(StateMachine, [{
key: 'match',
value: function match(str) {
var self = this;
return _defineProperty({}, _Symbol$iterator, _regeneratorRuntime.mark(function _callee() {
var state, startRun, lastAccepting, lastState, p, c;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
state = INITIAL_STATE;
startRun = null;
lastAccepting = null;
lastState = null;
p = 0;
match(str) {
var self = this;
return {
*[Symbol.iterator]() {
var state = INITIAL_STATE;
var startRun = null;
var lastAccepting = null;
var lastState = null;
case 5:
if (!(p < str.length)) {
_context.next = 21;
break;
}
for (var p = 0; p < str.length; p++) {
var c = str[p];
lastState = state;
state = self.stateTable[state][c];
c = str[p];
if (state === FAIL_STATE) {
// yield the last match if any
if (startRun != null && lastAccepting != null && lastAccepting >= startRun) {
yield [startRun, lastAccepting, self.tags[lastState]];
} // reset the state as if we started over from the initial state
lastState = state;
state = self.stateTable[state][c];
state = self.stateTable[INITIAL_STATE][c];
startRun = null;
} // start a run if not in the failure state
if (!(state === FAIL_STATE)) {
_context.next = 15;
break;
}
if (!(startRun != null && lastAccepting != null && lastAccepting >= startRun)) {
_context.next = 13;
break;
}
if (state !== FAIL_STATE && startRun == null) {
startRun = p;
} // if accepting, mark the potential match end
_context.next = 13;
return [startRun, lastAccepting, self.tags[lastState]];
case 13:
if (self.accepting[state]) {
lastAccepting = p;
} // reset the state to the initial state if we get into the failure state
// reset the state as if we started over from the initial state
state = self.stateTable[INITIAL_STATE][c];
startRun = null;
case 15:
// start a run if not in the failure state
if (state !== FAIL_STATE && startRun == null) {
startRun = p;
}
// if accepting, mark the potential match end
if (self.accepting[state]) {
lastAccepting = p;
}
// reset the state to the initial state if we get into the failure state
if (state === FAIL_STATE) {
state = INITIAL_STATE;
}
case 18:
p++;
_context.next = 5;
break;
case 21:
if (!(startRun != null && lastAccepting != null && lastAccepting >= startRun)) {
_context.next = 24;
break;
}
_context.next = 24;
return [startRun, lastAccepting, self.tags[state]];
case 24:
case 'end':
return _context.stop();
}
if (state === FAIL_STATE) {
state = INITIAL_STATE;
}
}, _callee, this);
}));
}
} // yield the last match if any
/**
* For each match over the input sequence, action functions matching
* the tag definitions in the input pattern are called with the startIndex,
* endIndex, and sub-match sequence.
*/
}, {
key: 'apply',
value: function apply(str, actions) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
if (startRun != null && lastAccepting != null && lastAccepting >= startRun) {
yield [startRun, lastAccepting, self.tags[state]];
}
}
try {
for (var _iterator = _getIterator(this.match(str)), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _step$value = _slicedToArray(_step.value, 3);
};
}
/**
* For each match over the input sequence, action functions matching
* the tag definitions in the input pattern are called with the startIndex,
* endIndex, and sub-match sequence.
*/
var start = _step$value[0];
var end = _step$value[1];
var tags = _step$value[2];
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = _getIterator(tags), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var tag = _step2.value;
if (typeof actions[tag] === 'function') {
actions[tag](start, end, str.slice(start, end + 1));
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
apply(str, actions) {
for (var [start, end, tags] of this.match(str)) {
for (var tag of tags) {
if (typeof actions[tag] === 'function') {
actions[tag](start, end, str.slice(start, end + 1));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
}]);
}
return StateMachine;
}();
}

@@ -2285,19 +1921,10 @@ function parse(string, externalSymbols) {

}
function build(symbolTable) {
var states = buildDFA(symbolTable.main, symbolTable.size);
return new StateMachine({
stateTable: states.map(function (s) {
return _Array$from(s.transitions);
}),
accepting: states.map(function (s) {
return s.accepting;
}),
tags: states.map(function (s) {
return _Array$from(s.tags);
})
stateTable: states.map(s => Array.from(s.transitions)),
accepting: states.map(s => s.accepting),
tags: states.map(s => Array.from(s.tags))
});
}
function compile(string, externalSymbols) {

@@ -2307,5 +1934,5 @@ return build(parse(string, externalSymbols));

exports.build = build;
exports.default = compile;
exports.parse = parse;
exports.build = build;
exports['default'] = compile;
//# sourceMappingURL=compile.js.map
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var _slicedToArray = _interopDefault(require('babel-runtime/helpers/slicedToArray'));
var _getIterator = _interopDefault(require('babel-runtime/core-js/get-iterator'));
var _defineProperty = _interopDefault(require('babel-runtime/helpers/defineProperty'));
var _regeneratorRuntime = _interopDefault(require('babel-runtime/regenerator'));
var _Symbol$iterator = _interopDefault(require('babel-runtime/core-js/symbol/iterator'));
var _classCallCheck = _interopDefault(require('babel-runtime/helpers/classCallCheck'));
var _createClass = _interopDefault(require('babel-runtime/helpers/createClass'));
var INITIAL_STATE = 1;
var FAIL_STATE = 0;
/**

@@ -21,6 +10,4 @@ * A StateMachine represents a deterministic finite automaton.

var StateMachine = function () {
function StateMachine(dfa) {
_classCallCheck(this, StateMachine);
class StateMachine {
constructor(dfa) {
this.stateTable = dfa.stateTable;

@@ -30,3 +17,2 @@ this.accepting = dfa.accepting;

}
/**

@@ -38,157 +24,71 @@ * Returns an iterable object that yields pattern matches over the input sequence.

_createClass(StateMachine, [{
key: 'match',
value: function match(str) {
var self = this;
return _defineProperty({}, _Symbol$iterator, _regeneratorRuntime.mark(function _callee() {
var state, startRun, lastAccepting, lastState, p, c;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
state = INITIAL_STATE;
startRun = null;
lastAccepting = null;
lastState = null;
p = 0;
match(str) {
var self = this;
return {
*[Symbol.iterator]() {
var state = INITIAL_STATE;
var startRun = null;
var lastAccepting = null;
var lastState = null;
case 5:
if (!(p < str.length)) {
_context.next = 21;
break;
}
for (var p = 0; p < str.length; p++) {
var c = str[p];
lastState = state;
state = self.stateTable[state][c];
c = str[p];
if (state === FAIL_STATE) {
// yield the last match if any
if (startRun != null && lastAccepting != null && lastAccepting >= startRun) {
yield [startRun, lastAccepting, self.tags[lastState]];
} // reset the state as if we started over from the initial state
lastState = state;
state = self.stateTable[state][c];
state = self.stateTable[INITIAL_STATE][c];
startRun = null;
} // start a run if not in the failure state
if (!(state === FAIL_STATE)) {
_context.next = 15;
break;
}
if (!(startRun != null && lastAccepting != null && lastAccepting >= startRun)) {
_context.next = 13;
break;
}
if (state !== FAIL_STATE && startRun == null) {
startRun = p;
} // if accepting, mark the potential match end
_context.next = 13;
return [startRun, lastAccepting, self.tags[lastState]];
case 13:
if (self.accepting[state]) {
lastAccepting = p;
} // reset the state to the initial state if we get into the failure state
// reset the state as if we started over from the initial state
state = self.stateTable[INITIAL_STATE][c];
startRun = null;
case 15:
// start a run if not in the failure state
if (state !== FAIL_STATE && startRun == null) {
startRun = p;
}
// if accepting, mark the potential match end
if (self.accepting[state]) {
lastAccepting = p;
}
// reset the state to the initial state if we get into the failure state
if (state === FAIL_STATE) {
state = INITIAL_STATE;
}
case 18:
p++;
_context.next = 5;
break;
case 21:
if (!(startRun != null && lastAccepting != null && lastAccepting >= startRun)) {
_context.next = 24;
break;
}
_context.next = 24;
return [startRun, lastAccepting, self.tags[state]];
case 24:
case 'end':
return _context.stop();
}
if (state === FAIL_STATE) {
state = INITIAL_STATE;
}
}, _callee, this);
}));
}
} // yield the last match if any
/**
* For each match over the input sequence, action functions matching
* the tag definitions in the input pattern are called with the startIndex,
* endIndex, and sub-match sequence.
*/
}, {
key: 'apply',
value: function apply(str, actions) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
if (startRun != null && lastAccepting != null && lastAccepting >= startRun) {
yield [startRun, lastAccepting, self.tags[state]];
}
}
try {
for (var _iterator = _getIterator(this.match(str)), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _step$value = _slicedToArray(_step.value, 3);
};
}
/**
* For each match over the input sequence, action functions matching
* the tag definitions in the input pattern are called with the startIndex,
* endIndex, and sub-match sequence.
*/
var start = _step$value[0];
var end = _step$value[1];
var tags = _step$value[2];
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = _getIterator(tags), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var tag = _step2.value;
if (typeof actions[tag] === 'function') {
actions[tag](start, end, str.slice(start, end + 1));
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
apply(str, actions) {
for (var [start, end, tags] of this.match(str)) {
for (var tag of tags) {
if (typeof actions[tag] === 'function') {
actions[tag](start, end, str.slice(start, end + 1));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
}]);
}
return StateMachine;
}();
}
module.exports = StateMachine;
//# sourceMappingURL=index.js.map
{
"name": "dfa",
"version": "1.1.0",
"version": "1.2.0",
"description": "A state machine compiler",
"main": "index.js",
"dependencies": {
"babel-runtime": "^6.11.6"
},
"devDependencies": {
"babel-core": "^6.17.0",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-polyfill": "^6.16.0",
"babel-preset-es2015": "^6.16.0",
"babel-register": "^6.16.3",
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/register": "^7.0.0",
"mocha": "^3.1.0",
"pegjs": "^0.10.0",
"rollup": "^0.36.1",
"rollup-plugin-babel": "^2.6.1",
"rollup-plugin-commonjs": "^5.0.4",
"rollup": "^1.5.0",
"rollup-plugin-babel": "^4.0.1",
"rollup-plugin-commonjs": "^9.2.1",
"rollup-plugin-local-resolve": "^1.0.7"
},
"scripts": {
"test": "mocha --require babel-register --require babel-polyfill",
"test": "mocha --require @babel/register",
"prepublish": "make"

@@ -25,0 +20,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc