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
Update tests and codegen
kitten.sh
5 years ago
1ab74a7d
de129283
+52
-1
2 changed files
expand all
collapse all
unified
split
src
codegen.js
core.test.js
+2
-1
src/codegen.js
···
26
26
`;
27
27
28
28
const astExpression = (ast, depth, opts) => {
29
29
+
const capture = !!opts.capture && !ast.capture;
29
30
const restoreLength =
30
31
(opts.length && opts.abort && js`${_node}.length = ln${opts.length};`) ||
31
32
'';
32
33
const expression = `${ast.expression.id}(${_state})`;
33
34
return js`
34
35
if ((${_match} = ${ast.expression.id}(${_state})) != null) {
35
35
-
${opts.capture ? js`${_node}.push(${_match})` : ''}
36
36
+
${capture ? js`${_node}.push(${_match})` : ''}
36
37
} else {
37
38
${opts.onAbort}
38
39
${restoreIndex(opts.index)}
+50
src/core.test.js
···
358
358
);
359
359
});
360
360
361
361
+
describe('non-capturing shorthand', () => {
362
362
+
const node = match('node')`${/1/} :${/2/}+`;
363
363
+
it.each`
364
364
+
input | result | lastIndex
365
365
+
${'12'} | ${['1']} | ${2}
366
366
+
${'122'} | ${['1']} | ${3}
367
367
+
${'13'} | ${undefined} | ${0}
368
368
+
${'1'} | ${undefined} | ${0}
369
369
+
${'_'} | ${undefined} | ${0}
370
370
+
`(
371
371
+
'should return $result when $input is passed',
372
372
+
({ input, result, lastIndex }) => {
373
373
+
expectToParse(node, input, result, lastIndex);
374
374
+
}
375
375
+
);
376
376
+
});
377
377
+
361
378
describe('non-capturing group with plus matcher, then required matcher', () => {
362
379
const node = match('node')`(?: ${/1/}+) ${/2/}`;
363
380
it.each`
···
445
462
);
446
463
});
447
464
465
465
+
describe('positive lookahead shorthand', () => {
466
466
+
const node = match('node')`=${/1/} ${/\d/}`;
467
467
+
it.each`
468
468
+
input | result | lastIndex
469
469
+
${'1'} | ${['1']} | ${1}
470
470
+
${'13'} | ${['1']} | ${1}
471
471
+
${'2'} | ${undefined} | ${0}
472
472
+
${'_'} | ${undefined} | ${0}
473
473
+
`(
474
474
+
'should return $result when $input is passed',
475
475
+
({ input, result, lastIndex }) => {
476
476
+
expectToParse(node, input, result, lastIndex);
477
477
+
}
478
478
+
);
479
479
+
});
480
480
+
448
481
describe('positive lookahead group with plus matcher', () => {
449
482
const node = match('node')`(?= ${/1/}+) ${/\d/}`;
450
483
it.each`
···
484
517
485
518
describe('negative lookahead group', () => {
486
519
const node = match('node')`(?! ${/1/}) ${/\d/}`;
520
520
+
it.each`
521
521
+
input | result | lastIndex
522
522
+
${'2'} | ${['2']} | ${1}
523
523
+
${'23'} | ${['2']} | ${1}
524
524
+
${'1'} | ${undefined} | ${0}
525
525
+
${'1'} | ${undefined} | ${0}
526
526
+
${'_'} | ${undefined} | ${0}
527
527
+
`(
528
528
+
'should return $result when $input is passed',
529
529
+
({ input, result, lastIndex }) => {
530
530
+
expectToParse(node, input, result, lastIndex);
531
531
+
}
532
532
+
);
533
533
+
});
534
534
+
535
535
+
describe('negative lookahead shorthand', () => {
536
536
+
const node = match('node')`!${/1/} ${/\d/}`;
487
537
it.each`
488
538
input | result | lastIndex
489
539
${'2'} | ${['2']} | ${1}