Skip to content
Snippets Groups Projects
Commit 00cac469 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

FIX: parsing of decimal numbers

parent 3c26a245
No related branches found
No related tags found
2 merge requests!105Release 0.11.0,!104FIX: parsing of decimal numbers
Pipeline #42251 passed
......@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Wrong url returned by FileSystem resource behind proxy.
* `NullPointerException` in GRPC API converters when executing SELECT query on
NULL values.
* Fix parsing of decimal numbers. Fixes https://gitlab.com/linkahead/linkahead-server/-/issues/239
### Security ###
......
......@@ -163,6 +163,9 @@ sources (if you called `make run` previously).
`$ make test`
You can run single unit test with
`mvn test -X -Dtest=TestCQL#testDecimalNumber`
## Setup Eclipse
......
......@@ -433,7 +433,7 @@ WHITE_SPACE_f:
/** */
WHITE_SPACE:
[ \t\n\r]+
WHITE_SPACE_f
;
/** */
......@@ -529,9 +529,9 @@ COLON:
/** Matches signed and unsigned numbers with decimal points, also numbers in scientific notation. */
DECIMAL_NUMBER:
((HYPHEN_f | PLUS ) WHITE_SPACE_f?)?
( NUM_f? DOT NUM_f WHITE_SPACE_f? E_NOTATION_f?
| NUM_f WHITE_SPACE_f? E_NOTATION_f
((HYPHEN_f | PLUS ) WHITE_SPACE_f?)?
( NUM_f? DOT NUM_f (WHITE_SPACE_f? E_NOTATION_f)?
| NUM_f (WHITE_SPACE_f? E_NOTATION_f)?
)
;
......
......@@ -36,6 +36,7 @@ import java.util.regex.Matcher;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.Vocabulary;
import org.antlr.v4.runtime.tree.ParseTree;
import org.caosdb.server.CaosDBServer;
import org.caosdb.server.database.access.Access;
......@@ -7103,4 +7104,32 @@ public class TestCQL {
assertTrue(conj.getFilters().get(0) instanceof POV);
assertTrue(conj.getFilters().get(1) instanceof POV);
}
@Test
public void testDecimalNumber() {
// This should always be DEC, WHITESPACE, AND repeat
final String text =
"1.2123e+3 AND 1.21234E+3 AND 1.21234E-3 AND 1.21234E3 AND 16.0 AND 1.2 AND -1.2 AND +1.2 AND 1.2 AND - 1.2 AND + 1.2 AND 2e-323 AND 2E-323 AND 2E- 323 AND 2 e -323 AND + 1.2123e+323";
CQLLexer lexer = new CQLLexer(CharStreams.fromString(text));
final CommonTokenStream tokens = new CommonTokenStream(lexer);
Vocabulary vocab = lexer.getVocabulary();
final CQLParser parser = new CQLParser(tokens);
final CqContext sfq = parser.cq();
int no = 0;
for (final Token t : tokens.getTokens()) {
if (no % 3 == 0) {
assertEquals(vocab.getSymbolicName(t.getType()), "DECIMAL_NUMBER");
}
if (no % 3 == 1) {
if (vocab.getSymbolicName(t.getType()) != "EOF") {
assertEquals(vocab.getSymbolicName(t.getType()), "WHITE_SPACE");
}
}
if (no % 3 == 2) {
assertEquals(vocab.getSymbolicName(t.getType()), "AND");
}
no = no + 1;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment