-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RANGE_PROBABLY_CONTAINS_NOT_IMPLIED_CHARACTERS warning, refactor …
…code related to caseInsensitive option fixes #3433
- Loading branch information
Showing
7 changed files
with
152 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
tool/src/org/antlr/v4/automata/RangeBorderCharactersData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.antlr.v4.automata; | ||
|
||
import org.antlr.runtime.tree.CommonTree; | ||
import org.antlr.v4.tool.ErrorType; | ||
import org.antlr.v4.tool.Grammar; | ||
|
||
public class RangeBorderCharactersData { | ||
public int lowerFrom; | ||
public int upperFrom; | ||
public int lowerTo; | ||
public int upperTo; | ||
public boolean mixOfLowerAndUpperCharCase; | ||
|
||
public RangeBorderCharactersData(int lowerFrom, int upperFrom, int lowerTo, int upperTo, boolean mixOfLowerAndUpperCharCase) { | ||
this.lowerFrom = lowerFrom; | ||
this.upperFrom = upperFrom; | ||
this.lowerTo = lowerTo; | ||
this.upperTo = upperTo; | ||
this.mixOfLowerAndUpperCharCase = mixOfLowerAndUpperCharCase; | ||
} | ||
|
||
public static RangeBorderCharactersData getAndCheckCharactersData(int from, int to, Grammar grammar, CommonTree tree) { | ||
int lowerFrom = Character.toLowerCase(from); | ||
int upperFrom = Character.toUpperCase(from); | ||
int lowerTo = Character.toLowerCase(to); | ||
int upperTo = Character.toUpperCase(to); | ||
boolean isLowerFrom = lowerFrom == from; | ||
boolean isLowerTo = lowerTo == to; | ||
boolean mixOfLowerAndUpperCharCase = isLowerFrom && !isLowerTo || !isLowerFrom && isLowerTo; | ||
if (mixOfLowerAndUpperCharCase) { | ||
StringBuilder notImpliedCharacters = new StringBuilder(); | ||
for (int i = from; i < to; i++) { | ||
if (Character.toLowerCase(i) == Character.toUpperCase(i)) { | ||
notImpliedCharacters.append((char)i); | ||
} | ||
} | ||
if (notImpliedCharacters.length() > 0) { | ||
grammar.tool.errMgr.grammarError(ErrorType.RANGE_PROBABLY_CONTAINS_NOT_IMPLIED_CHARACTERS, grammar.fileName, tree.getToken(), | ||
(char) from, (char) to, notImpliedCharacters.toString()); | ||
} | ||
} | ||
return new RangeBorderCharactersData(lowerFrom, upperFrom, lowerTo, upperTo, mixOfLowerAndUpperCharCase); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters