Detect alternations which are prefix of another
RunDevelopment opened this issue · 1 comments
RunDevelopment commented
Top-level alternations like int|integer are problematic because the word integer integer will never be matched.
In general: Let A and B be a pair of distinct alternatives of the same alternation where A comes before B.
If there ex. a word w in L(A) and x in L(B) \ L(A) such that w is prefix of x, then x can never be matched by B.
In other words: Report if [ L(B) \ L(A) ] ∩ L(/A[\s\S]*/) != ∅.
Examples:
/a|b/ //ok
/a|aa/ // report that `aa` cannot be matched
/a\b|aa/ // ok
/a|[ab]a/ // report that `aa` cannot be matched
/(?:a|[ab]a)\b/ // ok
/a(a|aa)a/ // report that `aaaa` cannot be matchedRunDevelopment commented
Done by regexp/no-dupe-disjunction.