Skip to content

Commit

Permalink
Support implicit 0 quantifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
slevithan committed Nov 6, 2024
1 parent 0050311 commit d4317b5
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 79 deletions.
25 changes: 12 additions & 13 deletions spec/match-capturing-group.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ beforeEach(() => {
});

// TODO: Add me
// describe('CapturingGroup', () => {
// describe('named', () => {
// it('should', () => {
// expect('').toExactlyMatch(r``);
// });
// });

describe('CapturingGroup', () => {
describe('named', () => {
it('should', () => {
expect('').toExactlyMatch(r``);
});
});

describe('numbered', () => {
it('should', () => {
expect('').toExactlyMatch(r``);
});
});
});
// describe('numbered', () => {
// it('should', () => {
// expect('').toExactlyMatch(r``);
// });
// });
// });
12 changes: 5 additions & 7 deletions spec/match-char-class-intersection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ beforeEach(() => {
});

// TODO: Add me
// TODO: Test that it throws for target ES2018

describe('CharacterClassIntersection', () => {
it('should', () => {
expect('').toExactlyMatch(r``);
});
});
// describe('CharacterClassIntersection', () => {
// it('should', () => {
// expect('').toExactlyMatch(r``);
// });
// });
2 changes: 1 addition & 1 deletion spec/match-char-class.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ beforeEach(() => {
});

describe('CharacterClass', () => {
// TODO: Move to `match-char.spec.js`?
// TODO: Move and mix into `match-char.spec.js`?
describe('Character', () => {
describe('escape', () => {
it('should match supported letter escapes', () => {
Expand Down
25 changes: 12 additions & 13 deletions spec/match-directive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ beforeEach(() => {
});

// TODO: Add me
// describe('Directive', () => {
// describe('flags', () => {
// it('should', () => {
// expect('').toExactlyMatch(r``);
// });
// });

describe('Directive', () => {
describe('flags', () => {
it('should', () => {
expect('').toExactlyMatch(r``);
});
});

describe('keep', () => {
it('should', () => {
expect('').toExactlyMatch(r``);
});
});
});
// describe('keep', () => {
// it('should', () => {
// expect('').toExactlyMatch(r``);
// });
// });
// });
11 changes: 5 additions & 6 deletions spec/match-flags.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ beforeEach(() => {
});

// TODO: Add me

describe('Flags', () => {
it('should', () => {
expect('').toExactlyMatch(r``);
});
});
// describe('Flags', () => {
// it('should', () => {
// expect('').toExactlyMatch(r``);
// });
// });
35 changes: 17 additions & 18 deletions spec/match-group.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@ beforeEach(() => {
});

// TODO: Add me
// describe('Group', () => {
// describe('atomic', () => {
// it('should', () => {
// expect('').toExactlyMatch(r``);
// });
// });

describe('Group', () => {
describe('atomic', () => {
it('should', () => {
expect('').toExactlyMatch(r``);
});
});
// describe('flags', () => {
// it('should', () => {
// expect('').toExactlyMatch(r``);
// });
// });

describe('flags', () => {
it('should', () => {
expect('').toExactlyMatch(r``);
});
});

describe('noncapturing', () => {
it('should', () => {
expect('').toExactlyMatch(r``);
});
});
});
// describe('noncapturing', () => {
// it('should', () => {
// expect('').toExactlyMatch(r``);
// });
// });
// });
37 changes: 19 additions & 18 deletions spec/match-quantifier.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ beforeEach(() => {
});

describe('Quantifier', () => {
describe('greedy', () => {
// TODO: Add me
it('should', () => {
expect('').toExactlyMatch(r``);
});
});
// TODO: Add me
// describe('greedy', () => {
// it('should', () => {
// expect('').toExactlyMatch(r``);
// });
// });

describe('lazy', () => {
// TODO: Add me
it('should', () => {
expect('').toExactlyMatch(r``);
});
});
// TODO: Add me
// describe('lazy', () => {
// it('should', () => {
// expect('').toExactlyMatch(r``);
// });
// });

describe('possessive', () => {
// TODO: Add me
it('should', () => {
expect('').toExactlyMatch(r``);
});
});
// TODO: Add me
// describe('possessive', () => {
// it('should', () => {
// expect('').toExactlyMatch(r``);
// });
// });

describe('quantifiability', () => {
it('should throw at start of pattern, group, or alternative', () => {
Expand Down Expand Up @@ -56,6 +56,7 @@ describe('Quantifier', () => {
expect(() => toDetails(r`\K+`)).toThrow();
expect(() => toDetails(r`(?i)+`)).toThrow();
expect(() => toDetails(r`(?-i)+`)).toThrow();
expect(() => toDetails(r`(?i-m)+`)).toThrow();
});
});
});
6 changes: 3 additions & 3 deletions src/tokenize.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ const hexCharPattern = r`u(?:\p{AHex}{4})? | x\{[^\}]*\}? | x\p{AHex}{0,2}`;
const escapedNumPattern = r`\d{1,3}`;
const charClassOpenPattern = r`\[\^?\]?`;
// Even with flag x, Onig doesn't allow whitespace to separate a quantifier from the `?` or `+`
// that makes it lazy or possessive
const quantifierRe = /[?*+][?+]?|\{\d+(?:,\d*)?\}\??/;
// that makes it lazy or possessive. Possessive suffixes don't apply to interval quantifiers
const quantifierRe = /[?*+][?+]?|\{(?:\d+(?:,\d*)?|,\d+)\}\??/;
const tokenRe = new RegExp(r`
\\ (?:
${controlCharPattern}
Expand Down Expand Up @@ -596,7 +596,7 @@ function createTokenForFlagMod(raw, context) {
function createTokenForQuantifier(raw) {
const data = {};
if (raw[0] === '{') {
const {min, max} = /^\{(?<min>\d+)(?:,(?<max>\d*))?/.exec(raw).groups;
const {min, max} = /^\{(?<min>\d*)(?:,(?<max>\d*))?/.exec(raw).groups;
const limit = 100_000;
if (+min > limit || +max > limit) {
throw new Error('Quantifier value unsupported in Oniguruma');
Expand Down

0 comments on commit d4317b5

Please sign in to comment.