Skip to content

Commit

Permalink
Allow numbers to be written in queries in scientific (exponential) no…
Browse files Browse the repository at this point in the history
…tation (#52)
  • Loading branch information
albertoventurini committed Jan 28, 2023
1 parent 77338b7 commit da8c8cf
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,20 @@ K_ON_EACH_TYPE={K_ON}{WHITE_SPACE}{_EACH}{WHITE_SPACE}{_TYPE}
K_ON_TYPE={K_ON}{WHITE_SPACE}{_TYPE}
K_IN_TRANSACTIONS={_IN}{WHITE_SPACE}{_TRANSACTIONS}

L_IDENTIFIER=[a-zA-Z_][a-zA-Z_$0-9]*
_DECIMAL_EXPONENT=[eE] [+-]? {_INTEGER_PART}+ {_PART_LETTER}*
_INTEGER_PART= "_"? [0-9]

L_IDENTIFIER={_LETTER}{_PART_LETTER}*
L_IDENTIFIER_TEXT=\`[^`]+\`
L_DECIMAL=(0|[1-9][0-9]*)\.[0-9]+
L_DECIMAL=[0-9] {_INTEGER_PART}* "_"? "." {_INTEGER_PART}+ {_DECIMAL_EXPONENT}? {L_IDENTIFIER}?
| "." {_INTEGER_PART}+ {_DECIMAL_EXPONENT}? {L_IDENTIFIER}?
| [0-9] {_INTEGER_PART}* {_DECIMAL_EXPONENT} {L_IDENTIFIER}?
L_INTEGER=0|[1-9][0-9]*
L_STRING=('([^'\\]|\\.)*'|\"([^\"\\]|\\.)*\")

_LETTER=[a-zA-Z]
_PART_LETTER=[a-zA-Z_$0-9]

LINE_COMMENT = "//" [^\r\n]*
BLOCK_COMMENT = "/*" ( ([^"*"]|[\r\n])* ("*"+ [^"*""/"] )? )* ("*" | "*"+"/")?

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.albertoventurini.graphdbplugin.test.integration.neo4j.tests.cypher.parsing;

import com.albertoventurini.graphdbplugin.test.integration.neo4j.tests.cypher.util.BaseParsingTest;

public class LexerTest extends BaseParsingTest {

public LexerTest() {
super("lexer");
}

public void testScientificNotation() {
doTest(true);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RETURN 1e6;
RETURN 1.7976931348623157e+308;
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Cypher file: FILE(0,43)
CypherStatementItemImpl(STATEMENT_ITEM)(0,11)
CypherStatementImpl(STATEMENT)(0,10)
CypherQueryOptionsImpl(QUERY_OPTIONS)(0,0)
<empty list>
CypherQueryImpl(QUERY)(0,10)
CypherRegularQueryImpl(REGULAR_QUERY)(0,10)
CypherSingleQueryImpl(SINGLE_QUERY)(0,10)
CypherSinglePartQueryImpl(SINGLE_PART_QUERY)(0,10)
CypherReadingWithReturnImpl(READING_WITH_RETURN)(0,10)
CypherReturnImpl(RETURN)(0,10)
PsiElement(RETURN)('RETURN')(0,6)
CypherReturnBodyImpl(RETURN_BODY)(7,10)
CypherReturnItemsImpl(RETURN_ITEMS)(7,10)
CypherReturnItemImpl(RETURN_ITEM)(7,10)
CypherExpressionImpl(EXPRESSION)(7,10)
CypherNumberLiteralImpl(NUMBER_LITERAL)(7,10)
CypherDoubleLiteralImpl(DOUBLE_LITERAL)(7,10)
CypherUnsignedDoubleImpl(UNSIGNED_DOUBLE)(7,10)
PsiElement(decimal)('1e6')(7,10)
PsiElement(;)(';')(10,11)
CypherStatementItemImpl(STATEMENT_ITEM)(12,43)
CypherStatementImpl(STATEMENT)(12,42)
CypherQueryOptionsImpl(QUERY_OPTIONS)(12,12)
<empty list>
CypherQueryImpl(QUERY)(12,42)
CypherRegularQueryImpl(REGULAR_QUERY)(12,42)
CypherSingleQueryImpl(SINGLE_QUERY)(12,42)
CypherSinglePartQueryImpl(SINGLE_PART_QUERY)(12,42)
CypherReadingWithReturnImpl(READING_WITH_RETURN)(12,42)
CypherReturnImpl(RETURN)(12,42)
PsiElement(RETURN)('RETURN')(12,18)
CypherReturnBodyImpl(RETURN_BODY)(19,42)
CypherReturnItemsImpl(RETURN_ITEMS)(19,42)
CypherReturnItemImpl(RETURN_ITEM)(19,42)
CypherExpressionImpl(EXPRESSION)(19,42)
CypherNumberLiteralImpl(NUMBER_LITERAL)(19,42)
CypherDoubleLiteralImpl(DOUBLE_LITERAL)(19,42)
CypherUnsignedDoubleImpl(UNSIGNED_DOUBLE)(19,42)
PsiElement(decimal)('1.7976931348623157e+308')(19,42)
PsiElement(;)(';')(42,43)

0 comments on commit da8c8cf

Please sign in to comment.