Skip to content
This repository was archived by the owner on Oct 11, 2021. It is now read-only.

Commit 35122fa

Browse files
Updated refa version
1 parent 0a1372e commit 35122fa

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

lib/rules/disjoint-alternatives.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default {
2323
function toNfa(alt: Alternative): ReadonlyNFA {
2424
const result = parser.parseElement(alt, { lookarounds: "disable" });
2525
const nfa = NFA.fromRegex(result.expression, { maxCharacter: result.maxCharacter });
26-
nfa.removeEmptyWord();
26+
nfa.withoutEmptyWord();
2727
return nfa;
2828
}
2929

@@ -74,7 +74,7 @@ export default {
7474
const altIndex = alternatives.indexOf(alt);
7575
const beforeAlternatives = alternatives.slice(0, altIndex);
7676

77-
const intersection = NFA.intersect(total, nfa);
77+
const intersection = NFA.fromIntersection(total, nfa);
7878
const isSubset = nfaEquals(nfa, intersection);
7979

8080
// try to find the alternatives that are not disjoint with this one
@@ -98,10 +98,17 @@ export default {
9898
message += " This alternative contains a capturing group so be careful when removing.";
9999
}
100100
} else {
101+
let sharedLanguageMsg;
102+
try {
103+
sharedLanguageMsg = ` The shared language is ${toRegExpString(intersection)}.`;
104+
} catch (e) {
105+
// the regex of the intersection might be too big in which case the implementation will
106+
// throw an error
107+
sharedLanguageMsg = "";
108+
}
101109
message = isSuperset
102110
? `This alternative is a superset of ${causeMsg}.`
103-
: `This alternative is not disjoint with ${causeMsg}.` +
104-
` The shared language is ${toRegExpString(intersection)}.`;
111+
: `This alternative is not disjoint with ${causeMsg}.${sharedLanguageMsg}`;
105112
}
106113

107114
// whether this ambiguity might cause exponential backtracking

lib/util.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
RegExpLiteral,
2323
AnyCharacterSet,
2424
} from "regexpp/ast";
25-
import { JS, DFA, CharSet, NFA, ReadonlyNFA, NFAOptions } from "refa";
25+
import { JS, DFA, CharSet, NFA, ReadonlyNFA } from "refa";
2626

2727
export interface FirstChar {
2828
/**
@@ -1505,9 +1505,9 @@ export function nfaEquals(a: ReadonlyNFA, b: ReadonlyNFA): boolean {
15051505
return false;
15061506
}
15071507

1508-
const aDfa = DFA.fromNFA(a);
1508+
const aDfa = DFA.fromFA(a);
15091509
aDfa.minimize();
1510-
const bDfa = DFA.fromNFA(b);
1510+
const bDfa = DFA.fromFA(b);
15111511
bDfa.minimize();
15121512

15131513
return aDfa.structurallyEqual(bDfa);
@@ -1520,7 +1520,7 @@ export function nfaIsSupersetOf(superset: ReadonlyNFA, subset: ReadonlyNFA): boo
15201520
export function nfaIsSubsetOf(subset: ReadonlyNFA, superset: ReadonlyNFA): boolean {
15211521
return nfaIsSupersetOf(superset, subset);
15221522
}
1523-
export function nfaUnionAll(nfas: Iterable<ReadonlyNFA>, options: Readonly<NFAOptions>): NFA {
1523+
export function nfaUnionAll(nfas: Iterable<ReadonlyNFA>, options: Readonly<NFA.Options>): NFA {
15241524
const total = NFA.empty(options);
15251525
for (const nfa of nfas) {
15261526
total.union(nfa);

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"test": "mocha -r ts-node/register 'tests/**/*.ts'"
2626
},
2727
"dependencies": {
28-
"refa": "0.4.1",
28+
"refa": "^0.5.0",
2929
"regexpp": "^3.1.0"
3030
},
3131
"devDependencies": {

0 commit comments

Comments
 (0)