Skip to content

Commit

Permalink
Fix broken g anchor asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
duckdoom4 committed Aug 15, 2024
1 parent bbf05a3 commit ff6f5e2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/tokenizer/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class Tokenizer {
stack.push(RenpyPatterns.basePatterns as ExTokenRepoPattern);

const mFlagRe = /(?<!\[)[\^$]/g;
const gAnchorRe = /\(\\G\)|\(\?!\\G\)/g;
const gAnchorRe = /(?:\(\?!\\G\))|(?:\\G)/g;
while (!stack.isEmpty()) {
const p = stack.pop()!;
assert(p !== undefined, "This pattern is undefined! Please make sure that circular includes are added after both patterns are defined.");
Expand All @@ -162,7 +162,7 @@ export class Tokenizer {
}

if (gAnchorRe.test(reBeginSource)) {
assert("Can't use the \\G anchor, please update the regex!");
assert(false, "Can't use the \\G anchor, please update the regex!");
reBeginSource = reBeginSource.replace(gAnchorRe, "");
}

Expand Down Expand Up @@ -206,7 +206,7 @@ export class Tokenizer {
if (reEndSource.startsWith("(?!\\G)")) {
p._endNotG = true;
} else {
assert("The end patterns only supports (?!\\G) at the start of the regex. Please update the regex!");
assert(false, "The end patterns only supports (?!\\G) at the start of the regex. Please update the regex!");
reEndSource = reEndSource.replace(gAnchorRe, "");
}
}
Expand All @@ -225,6 +225,11 @@ export class Tokenizer {
assert(p.match.multiline, "To match this pattern the 'm' flag is required!");
}

if (gAnchorRe.test(p.match.source)) {
assert(false, "The \\G anchors are not yet supported on match patterns!");
p.match = new RegExp(p.match.source.replace(gAnchorRe, ""), p.match.flags);
}

assert(p.match.global, "To match this pattern the 'g' flag is required!");
if (p.captures) {
assert(p.match.hasIndices, "To match this pattern the 'd' flag is required!");
Expand Down

0 comments on commit ff6f5e2

Please sign in to comment.