tangled
alpha
login
or
join now
kitten.sh
/
reghex
0
fork
atom
Mirror: The magical sticky regex-based parser generator 🧙
0
fork
atom
overview
issues
pulls
pipelines
Fix empty matches being impossible at end of input
kitten.sh
5 years ago
0d9458b4
050ed1f2
+11
-7
2 changed files
expand all
collapse all
unified
split
src
core.js
core.test.js
+6
-7
src/core.js
···
10
10
11
11
const execString = (pattern) => {
12
12
return (state) => {
13
13
-
const input = state.quasis[state.x];
14
14
-
if (input && state.y < input.length) {
13
13
+
if (state.x < state.quasis.length) {
14
14
+
const input = state.quasis[state.x];
15
15
for (let i = 0, l = pattern.length; i < l; i++)
16
16
if (input.charCodeAt(state.y + i) !== pattern.charCodeAt(i))
17
17
return null;
···
26
26
? new RegExp(pattern.source, 'y')
27
27
: new RegExp(pattern.source + '|()', 'g');
28
28
return (state) => {
29
29
-
const input = state.quasis[state.x];
30
30
-
if (input && state.y < input.length) {
29
29
+
if (state.x < state.quasis.length) {
30
30
+
const input = state.quasis[state.x];
31
31
pattern.lastIndex = state.y;
32
32
-
33
32
let match;
34
33
if (isStickySupported) {
35
34
if (pattern.test(input))
···
59
58
let match;
60
59
61
60
if (
62
62
-
state.y >= state.quasis[state.x].length &&
63
63
-
state.x < state.expressions.length
61
61
+
state.x < state.expressions.length &&
62
62
+
state.y >= state.quasis[state.x].length
64
63
) {
65
64
state.y = 0;
66
65
match = state.expressions[state.x++];
+5
src/core.test.js
···
24
24
`('should return $result when $input is passed', ({ input, result }) => {
25
25
expectToParse(node, input, result);
26
26
});
27
27
+
28
28
+
it('matches empty regex patterns', () => {
29
29
+
const node = match('node')`${/[ ]*/}`;
30
30
+
expectToParse(node, '', ['']);
31
31
+
});
27
32
});
28
33
29
34
describe('optional matcher', () => {