Comparing version 1.0.0 to 1.1.0
474
compile.js
@@ -137,2 +137,9 @@ 'use strict'; | ||
_createClass(Variable, [{ | ||
key: 'copy', | ||
value: function copy() { | ||
return new Variable(this.name); | ||
} | ||
}]); | ||
return Variable; | ||
@@ -375,2 +382,34 @@ }(Node); | ||
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; | ||
if (min < 0 || min > max) { | ||
throw new Error('Invalid repetition range: ' + min + ' ' + max); | ||
} | ||
var res = null; | ||
for (var i = 0; i < min; i++) { | ||
res = concat(res, expression.copy()); | ||
} | ||
if (max === Infinity) { | ||
res = concat(res, new Repeat(expression.copy(), '*')); | ||
} else { | ||
for (var _i = min; _i < max; _i++) { | ||
res = concat(res, new Repeat(expression.copy(), '?')); | ||
} | ||
} | ||
return res; | ||
} | ||
function concat(a, b) { | ||
if (!a) { | ||
return b; | ||
} | ||
return new Concatenation(a, b); | ||
} | ||
/** | ||
@@ -490,2 +529,3 @@ * Base class for leaf nodes | ||
Repeat: Repeat, | ||
buildRepetition: buildRepetition, | ||
Literal: Literal, | ||
@@ -670,26 +710,47 @@ EndMarker: EndMarker, | ||
}, | ||
peg$c30 = function peg$c30(x) { | ||
peg$c30 = "{", | ||
peg$c31 = peg$literalExpectation("{", false), | ||
peg$c32 = "}", | ||
peg$c33 = peg$literalExpectation("}", false), | ||
peg$c34 = function peg$c34(t, m) { | ||
return n.buildRepetition(t, m, m); | ||
}, | ||
peg$c35 = ",", | ||
peg$c36 = peg$literalExpectation(",", false), | ||
peg$c37 = function peg$c37(t, min) { | ||
return n.buildRepetition(t, min, Infinity); | ||
}, | ||
peg$c38 = function peg$c38(t, max) { | ||
return n.buildRepetition(t, 0, max); | ||
}, | ||
peg$c39 = function peg$c39(t, min, max) { | ||
return n.buildRepetition(t, min, max); | ||
}, | ||
peg$c40 = function peg$c40(x) { | ||
return new n.Literal(x); | ||
}, | ||
peg$c31 = "(", | ||
peg$c32 = peg$literalExpectation("(", false), | ||
peg$c33 = ")", | ||
peg$c34 = peg$literalExpectation(")", false), | ||
peg$c35 = function peg$c35(e) { | ||
peg$c41 = "(", | ||
peg$c42 = peg$literalExpectation("(", false), | ||
peg$c43 = ")", | ||
peg$c44 = peg$literalExpectation(")", false), | ||
peg$c45 = function peg$c45(e) { | ||
return e; | ||
}, | ||
peg$c36 = function peg$c36(a, b) { | ||
peg$c46 = function peg$c46() { | ||
return n.buildRepetition(); | ||
}, | ||
peg$c47 = function peg$c47(a, b) { | ||
return a + b.join(''); | ||
}, | ||
peg$c37 = "_", | ||
peg$c38 = peg$literalExpectation("_", false), | ||
peg$c39 = /^[a-zA-Z]/, | ||
peg$c40 = peg$classExpectation([["a", "z"], ["A", "Z"]], false, false), | ||
peg$c41 = /^[0-9]/, | ||
peg$c42 = peg$classExpectation([["0", "9"]], false, false), | ||
peg$c43 = function peg$c43(num) { | ||
peg$c48 = "_", | ||
peg$c49 = peg$literalExpectation("_", false), | ||
peg$c50 = /^[a-zA-Z]/, | ||
peg$c51 = peg$classExpectation([["a", "z"], ["A", "Z"]], false, false), | ||
peg$c52 = /^[0-9]/, | ||
peg$c53 = peg$classExpectation([["0", "9"]], false, false), | ||
peg$c54 = function peg$c54(num) { | ||
return parseInt(num.join('')); | ||
}, | ||
peg$c44 = /^[ \t\r\n]/, | ||
peg$c45 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false), | ||
peg$c55 = /^[ \t\r\n]/, | ||
peg$c56 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false), | ||
peg$currPos = 0, | ||
@@ -961,3 +1022,3 @@ peg$savedPos = 0, | ||
if (s4 !== peg$FAILED) { | ||
s5 = peg$parseexpr(); | ||
s5 = peg$parsealternation(); | ||
if (s5 !== peg$FAILED) { | ||
@@ -1025,7 +1086,7 @@ s6 = peg$parse_(); | ||
function peg$parseexpr() { | ||
function peg$parsealternation() { | ||
var s0, s1, s2, s3, s4, s5; | ||
s0 = peg$currPos; | ||
s1 = peg$parseexpr_q(); | ||
s1 = peg$parseconcatenation(); | ||
if (s1 !== peg$FAILED) { | ||
@@ -1046,3 +1107,3 @@ s2 = peg$parse_(); | ||
if (s4 !== peg$FAILED) { | ||
s5 = peg$parseexpr(); | ||
s5 = peg$parsealternation(); | ||
if (s5 !== peg$FAILED) { | ||
@@ -1073,16 +1134,21 @@ peg$savedPos = s0; | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$currPos; | ||
s1 = peg$parseexpr_q(); | ||
if (s1 !== peg$FAILED) { | ||
s2 = peg$parse_(); | ||
if (s2 !== peg$FAILED) { | ||
s3 = peg$parseexpr(); | ||
if (s3 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c17(s1, s3); | ||
s0 = s1; | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
s0 = peg$parseconcatenation(); | ||
} | ||
return s0; | ||
} | ||
function 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); | ||
s0 = s1; | ||
} else { | ||
@@ -1096,6 +1162,9 @@ peg$currPos = s0; | ||
} | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$parseexpr_q(); | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$parserepeat(); | ||
} | ||
@@ -1105,4 +1174,4 @@ return s0; | ||
function peg$parseexpr_q() { | ||
var s0, s1, s2, s3; | ||
function peg$parserepeat() { | ||
var s0, s1, s2, s3, s4, s5, s6; | ||
@@ -1122,3 +1191,3 @@ s0 = peg$currPos; | ||
if (s2 !== peg$FAILED) { | ||
s3 = peg$parseexpr_q(); | ||
s3 = peg$parserepeat(); | ||
if (s3 !== peg$FAILED) { | ||
@@ -1216,3 +1285,235 @@ peg$savedPos = s0; | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$parseterm(); | ||
s0 = peg$currPos; | ||
s1 = peg$parseterm(); | ||
if (s1 !== peg$FAILED) { | ||
if (input.charCodeAt(peg$currPos) === 123) { | ||
s2 = peg$c30; | ||
peg$currPos++; | ||
} else { | ||
s2 = peg$FAILED; | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c31); | ||
} | ||
} | ||
if (s2 !== peg$FAILED) { | ||
s3 = peg$parsenumber(); | ||
if (s3 !== peg$FAILED) { | ||
if (input.charCodeAt(peg$currPos) === 125) { | ||
s4 = peg$c32; | ||
peg$currPos++; | ||
} else { | ||
s4 = peg$FAILED; | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c33); | ||
} | ||
} | ||
if (s4 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c34(s1, s3); | ||
s0 = s1; | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$currPos; | ||
s1 = peg$parseterm(); | ||
if (s1 !== peg$FAILED) { | ||
if (input.charCodeAt(peg$currPos) === 123) { | ||
s2 = peg$c30; | ||
peg$currPos++; | ||
} else { | ||
s2 = peg$FAILED; | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c31); | ||
} | ||
} | ||
if (s2 !== peg$FAILED) { | ||
s3 = peg$parsenumber(); | ||
if (s3 !== peg$FAILED) { | ||
if (input.charCodeAt(peg$currPos) === 44) { | ||
s4 = peg$c35; | ||
peg$currPos++; | ||
} else { | ||
s4 = peg$FAILED; | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c36); | ||
} | ||
} | ||
if (s4 !== peg$FAILED) { | ||
if (input.charCodeAt(peg$currPos) === 125) { | ||
s5 = peg$c32; | ||
peg$currPos++; | ||
} else { | ||
s5 = peg$FAILED; | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c33); | ||
} | ||
} | ||
if (s5 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c37(s1, s3); | ||
s0 = s1; | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$currPos; | ||
s1 = peg$parseterm(); | ||
if (s1 !== peg$FAILED) { | ||
if (input.charCodeAt(peg$currPos) === 123) { | ||
s2 = peg$c30; | ||
peg$currPos++; | ||
} else { | ||
s2 = peg$FAILED; | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c31); | ||
} | ||
} | ||
if (s2 !== peg$FAILED) { | ||
if (input.charCodeAt(peg$currPos) === 44) { | ||
s3 = peg$c35; | ||
peg$currPos++; | ||
} else { | ||
s3 = peg$FAILED; | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c36); | ||
} | ||
} | ||
if (s3 !== peg$FAILED) { | ||
s4 = peg$parsenumber(); | ||
if (s4 !== peg$FAILED) { | ||
if (input.charCodeAt(peg$currPos) === 125) { | ||
s5 = peg$c32; | ||
peg$currPos++; | ||
} else { | ||
s5 = peg$FAILED; | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c33); | ||
} | ||
} | ||
if (s5 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c38(s1, s4); | ||
s0 = s1; | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$currPos; | ||
s1 = peg$parseterm(); | ||
if (s1 !== peg$FAILED) { | ||
if (input.charCodeAt(peg$currPos) === 123) { | ||
s2 = peg$c30; | ||
peg$currPos++; | ||
} else { | ||
s2 = peg$FAILED; | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c31); | ||
} | ||
} | ||
if (s2 !== peg$FAILED) { | ||
s3 = peg$parsenumber(); | ||
if (s3 !== peg$FAILED) { | ||
if (input.charCodeAt(peg$currPos) === 44) { | ||
s4 = peg$c35; | ||
peg$currPos++; | ||
} else { | ||
s4 = peg$FAILED; | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c36); | ||
} | ||
} | ||
if (s4 !== peg$FAILED) { | ||
s5 = peg$parsenumber(); | ||
if (s5 !== peg$FAILED) { | ||
if (input.charCodeAt(peg$currPos) === 125) { | ||
s6 = peg$c32; | ||
peg$currPos++; | ||
} else { | ||
s6 = peg$FAILED; | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c33); | ||
} | ||
} | ||
if (s6 !== peg$FAILED) { | ||
peg$savedPos = s0; | ||
s1 = peg$c39(s1, s3, s5); | ||
s0 = s1; | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
} else { | ||
peg$currPos = s0; | ||
s0 = peg$FAILED; | ||
} | ||
if (s0 === peg$FAILED) { | ||
s0 = peg$parseterm(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
@@ -1235,3 +1536,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c30(s1); | ||
s1 = peg$c40(s1); | ||
} | ||
@@ -1242,3 +1543,3 @@ s0 = s1; | ||
if (input.charCodeAt(peg$currPos) === 40) { | ||
s1 = peg$c31; | ||
s1 = peg$c41; | ||
peg$currPos++; | ||
@@ -1248,10 +1549,10 @@ } else { | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c32); | ||
peg$fail(peg$c42); | ||
} | ||
} | ||
if (s1 !== peg$FAILED) { | ||
s2 = peg$parseexpr(); | ||
s2 = peg$parsealternation(); | ||
if (s2 !== peg$FAILED) { | ||
if (input.charCodeAt(peg$currPos) === 41) { | ||
s3 = peg$c33; | ||
s3 = peg$c43; | ||
peg$currPos++; | ||
@@ -1261,3 +1562,3 @@ } else { | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c34); | ||
peg$fail(peg$c44); | ||
} | ||
@@ -1267,3 +1568,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c35(s2); | ||
s1 = peg$c45(s2); | ||
s0 = s1; | ||
@@ -1288,2 +1589,47 @@ } else { | ||
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() { | ||
@@ -1303,3 +1649,3 @@ var s0, s1, s2, s3; | ||
peg$savedPos = s0; | ||
s1 = peg$c36(s1, s2); | ||
s1 = peg$c47(s1, s2); | ||
s0 = s1; | ||
@@ -1322,3 +1668,3 @@ } else { | ||
if (input.charCodeAt(peg$currPos) === 95) { | ||
s0 = peg$c37; | ||
s0 = peg$c48; | ||
peg$currPos++; | ||
@@ -1328,7 +1674,7 @@ } else { | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c38); | ||
peg$fail(peg$c49); | ||
} | ||
} | ||
if (s0 === peg$FAILED) { | ||
if (peg$c39.test(input.charAt(peg$currPos))) { | ||
if (peg$c50.test(input.charAt(peg$currPos))) { | ||
s0 = input.charAt(peg$currPos); | ||
@@ -1339,3 +1685,3 @@ peg$currPos++; | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c40); | ||
peg$fail(peg$c51); | ||
} | ||
@@ -1353,3 +1699,3 @@ } | ||
if (s0 === peg$FAILED) { | ||
if (peg$c41.test(input.charAt(peg$currPos))) { | ||
if (peg$c52.test(input.charAt(peg$currPos))) { | ||
s0 = input.charAt(peg$currPos); | ||
@@ -1360,3 +1706,3 @@ peg$currPos++; | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c42); | ||
peg$fail(peg$c53); | ||
} | ||
@@ -1374,3 +1720,3 @@ } | ||
s1 = []; | ||
if (peg$c41.test(input.charAt(peg$currPos))) { | ||
if (peg$c52.test(input.charAt(peg$currPos))) { | ||
s2 = input.charAt(peg$currPos); | ||
@@ -1381,3 +1727,3 @@ peg$currPos++; | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c42); | ||
peg$fail(peg$c53); | ||
} | ||
@@ -1388,3 +1734,3 @@ } | ||
s1.push(s2); | ||
if (peg$c41.test(input.charAt(peg$currPos))) { | ||
if (peg$c52.test(input.charAt(peg$currPos))) { | ||
s2 = input.charAt(peg$currPos); | ||
@@ -1395,3 +1741,3 @@ peg$currPos++; | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c42); | ||
peg$fail(peg$c53); | ||
} | ||
@@ -1405,3 +1751,3 @@ } | ||
peg$savedPos = s0; | ||
s1 = peg$c43(s1); | ||
s1 = peg$c54(s1); | ||
} | ||
@@ -1417,3 +1763,3 @@ s0 = s1; | ||
s0 = []; | ||
if (peg$c44.test(input.charAt(peg$currPos))) { | ||
if (peg$c55.test(input.charAt(peg$currPos))) { | ||
s1 = input.charAt(peg$currPos); | ||
@@ -1424,3 +1770,3 @@ peg$currPos++; | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c45); | ||
peg$fail(peg$c56); | ||
} | ||
@@ -1430,3 +1776,3 @@ } | ||
s0.push(s1); | ||
if (peg$c44.test(input.charAt(peg$currPos))) { | ||
if (peg$c55.test(input.charAt(peg$currPos))) { | ||
s1 = input.charAt(peg$currPos); | ||
@@ -1437,3 +1783,3 @@ peg$currPos++; | ||
if (peg$silentFails === 0) { | ||
peg$fail(peg$c45); | ||
peg$fail(peg$c56); | ||
} | ||
@@ -1440,0 +1786,0 @@ } |
{ | ||
"name": "dfa", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A state machine compiler", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
151579
6
2099
0
84
0