Skip to content

Commit

Permalink
Remove caseInsensitive function argument where it's not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
KvanTTT committed Dec 25, 2021
1 parent d0c14f4 commit 8bf1039
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions tool/src/org/antlr/v4/automata/LexerATNFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public class LexerATNFactory extends ParserATNFactory {
COMMON_CONSTANTS.put("MIN_CHAR_VALUE", Lexer.MIN_CHAR_VALUE);
}

private List<String> ruleCommands = new ArrayList<String>();
private final List<String> ruleCommands = new ArrayList<String>();

private boolean caseInsensitive;
private final boolean caseInsensitive;

/**
* Maps from an action index to a {@link LexerAction} object.
Expand Down Expand Up @@ -286,7 +286,7 @@ else if ( t.getType()==ANTLRParser.LEXER_CHAR_SET ) {
else if ( t.getType()==ANTLRParser.STRING_LITERAL ) {
int c = CharSupport.getCharValueFromGrammarCharLiteral(t.getText());
if ( c != -1 ) {
checkCharAndAddToSet(associatedAST, set, c, caseInsensitive);
checkCharAndAddToSet(associatedAST, set, c);
}
else {
g.tool.errMgr.grammarError(ErrorType.INVALID_LITERAL_IN_LEXER_SET,
Expand Down Expand Up @@ -470,10 +470,10 @@ public IntervalSet getSetFromCharSetLiteral(GrammarAST charSetAST) {
state = CharSetParseState.ERROR;
break;
case CODE_POINT:
state = applyPrevStateAndMoveToCodePoint(charSetAST, set, state, escapeParseResult.codePoint, caseInsensitive);
state = applyPrevStateAndMoveToCodePoint(charSetAST, set, state, escapeParseResult.codePoint);
break;
case PROPERTY:
state = applyPrevStateAndMoveToProperty(charSetAST, set, state, escapeParseResult.propertyIntervalSet, caseInsensitive);
state = applyPrevStateAndMoveToProperty(charSetAST, set, state, escapeParseResult.propertyIntervalSet);
break;
}
offset = escapeParseResult.parseLength;
Expand All @@ -489,24 +489,23 @@ else if (c == '-' && !state.inRange && i != 0 && i != n - 1 && state.mode != Cha
}
}
else {
state = applyPrevStateAndMoveToCodePoint(charSetAST, set, state, c, caseInsensitive);
state = applyPrevStateAndMoveToCodePoint(charSetAST, set, state, c);
}
i += offset;
}
if (state.mode == CharSetParseState.Mode.ERROR) {
return new IntervalSet();
}
// Whether or not we were in a range, we'll add the last code point found to the set.
applyPrevState(charSetAST, set, state, caseInsensitive);
applyPrevState(charSetAST, set, state);
return set;
}

private CharSetParseState applyPrevStateAndMoveToCodePoint(
GrammarAST charSetAST,
IntervalSet set,
CharSetParseState state,
int codePoint,
boolean caseInsensitive) {
int codePoint) {
if (state.inRange) {
if (state.prevCodePoint > codePoint) {
g.tool.errMgr.grammarError(
Expand All @@ -519,7 +518,7 @@ private CharSetParseState applyPrevStateAndMoveToCodePoint(
state = CharSetParseState.NONE;
}
else {
applyPrevState(charSetAST, set, state, caseInsensitive);
applyPrevState(charSetAST, set, state);
state = new CharSetParseState(
CharSetParseState.Mode.PREV_CODE_POINT,
false,
Expand All @@ -533,15 +532,14 @@ private CharSetParseState applyPrevStateAndMoveToProperty(
GrammarAST charSetAST,
IntervalSet set,
CharSetParseState state,
IntervalSet property,
boolean caseInsensitive) {
IntervalSet property) {
if (state.inRange) {
g.tool.errMgr.grammarError(ErrorType.UNICODE_PROPERTY_NOT_ALLOWED_IN_RANGE,
g.fileName, charSetAST.getToken(), charSetAST.getText());
return CharSetParseState.ERROR;
}
else {
applyPrevState(charSetAST, set, state, caseInsensitive);
applyPrevState(charSetAST, set, state);
state = new CharSetParseState(
CharSetParseState.Mode.PREV_PROPERTY,
false,
Expand All @@ -551,21 +549,21 @@ private CharSetParseState applyPrevStateAndMoveToProperty(
return state;
}

private void applyPrevState(GrammarAST charSetAST, IntervalSet set, CharSetParseState state, boolean caseInsensitive) {
private void applyPrevState(GrammarAST charSetAST, IntervalSet set, CharSetParseState state) {
switch (state.mode) {
case NONE:
case ERROR:
break;
case PREV_CODE_POINT:
checkCharAndAddToSet(charSetAST, set, state.prevCodePoint, caseInsensitive);
checkCharAndAddToSet(charSetAST, set, state.prevCodePoint);
break;
case PREV_PROPERTY:
set.addAll(state.prevProperty);
break;
}
}

private void checkCharAndAddToSet(GrammarAST ast, IntervalSet set, int c, boolean caseInsensitive) {
private void checkCharAndAddToSet(GrammarAST ast, IntervalSet set, int c) {
checkRangeAndAddToSet(ast, set, c, c, caseInsensitive);
}

Expand Down

0 comments on commit 8bf1039

Please sign in to comment.