Skip to content

Commit e1893d4

Browse files
committed
Case insensitive operators (Operators Not, And, Or are case insensitive)
1 parent 3abc905 commit e1893d4

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/main/java/com/scriptbasic/syntax/expression/AbstractExpressionAnalyzer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ private void consumeTheOperatorLexeme() throws AnalysisException {
3939
private boolean isOperatorWithPriority(final LexicalElement le,
4040
final Integer priority) {
4141
return le != null && le.isSymbol()
42-
&& getOperatorMap(priority).containsKey(le.getLexeme());
42+
&& getOperatorMap(priority).containsKey(le.getLexeme().toLowerCase());
4343
}
4444

4545
private Class<? extends AbstractBinaryOperator> getOperatorClass(
4646
final LexicalElement le, final Integer priority) {
47-
return getOperatorMap(priority).get(le.getLexeme());
47+
return getOperatorMap(priority).get(le.getLexeme().toLowerCase());
4848
}
4949

5050
private AbstractBinaryOperator getOperator(final LexicalElement le, final Integer priority)

src/main/java/com/scriptbasic/syntax/expression/BasicTagAnalyzer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private static boolean isOpeningParenthese(
104104

105105
private static boolean isUnaryOperator(final LexicalElement lexicalElement) {
106106
return lexicalElement.isSymbol()
107-
&& unaryOperatorMap.containsKey(lexicalElement.getLexeme());
107+
&& unaryOperatorMap.containsKey(lexicalElement.getLexeme().toLowerCase());
108108
}
109109

110110
@Override
@@ -192,7 +192,7 @@ private AbstractUnaryOperator newUnaryOperator(
192192
final var lexicalElement = LexUtility.get(lexicalAnalyzer);
193193
final AbstractUnaryOperator operator;
194194
try {
195-
operator = unaryOperatorMap.get(lexicalElement.getLexeme())
195+
operator = unaryOperatorMap.get(lexicalElement.getLexeme().toLowerCase())
196196
.getDeclaredConstructor().newInstance();
197197
} catch (final Exception e) {
198198
throw new BasicSyntaxException(e);

src/test/java/com/scriptbasic/executors/operators/TestOperators.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ public void testOperators() throws AnalysisException,
7070
a("a=+3-3", 0);
7171
a("a=+3.2+-2", 1.2);
7272
a("a=-3.4", -3.4);
73+
a("a= False", false);
74+
a("a= True", true);
7375
a("a= not a", true);
76+
a("a= Not a", true);
7477
a("a= not false", true);
7578
a("a= not true", false);
7679
a("a= 3 < 2", false);
@@ -142,7 +145,9 @@ public void testOperators() throws AnalysisException,
142145
a("a= \"apple\" > \"apale\"", true);
143146

144147
a("a= \"x\" and \"\"", false);
148+
a("a= \"x\" And \"\"", false);
145149
a("a= \"x\" or \"\"", true);
150+
a("a= \"x\" Or \"\"", true);
146151
a("a= \"x\" and \"z\"", true);
147152
a("a= \"x\" or \"z\"", true);
148153
a("a= 13.2 or false", true);

0 commit comments

Comments
 (0)