Skip to content

Commit fdc3602

Browse files
Allow numbers to be written in queries in scientific (exponential) notation (#52) (#65)
* Allow numbers to be written in queries in scientific (exponential) notation (#52 * Support hex and octal numbers
1 parent f5c039a commit fdc3602

File tree

9 files changed

+123
-3
lines changed

9 files changed

+123
-3
lines changed

language/cypher/src/main/java/com/albertoventurini/graphdbplugin/language/cypher/lexer/Cypher.bnf

+1-1
Original file line numberDiff line numberDiff line change
@@ -635,4 +635,4 @@ Dash ::= "-" // todo: migrate all variants
635635
LeftArrowHead ::= "<" // todo: migrate all variants
636636
RightArrowHead ::= ">" // todo: migrate all variants
637637
UnsignedDouble ::= l_decimal
638-
UnsignedInteger ::= l_integer
638+
UnsignedInteger ::= l_integer | l_hex_integer | l_octal_integer

language/cypher/src/main/java/com/albertoventurini/graphdbplugin/language/cypher/lexer/CypherLexer.flex

+14-2
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,22 @@ K_ON_EACH_TYPE={K_ON}{WHITE_SPACE}{_EACH}{WHITE_SPACE}{_TYPE}
137137
K_ON_TYPE={K_ON}{WHITE_SPACE}{_TYPE}
138138
K_IN_TRANSACTIONS={_IN}{WHITE_SPACE}{_TRANSACTIONS}
139139

140-
L_IDENTIFIER=[a-zA-Z_][a-zA-Z_$0-9]*
140+
_DECIMAL_EXPONENT=[eE] [+-]? {_INTEGER_PART}+ {_PART_LETTER}*
141+
_INTEGER_PART= "_"? [0-9]
142+
143+
L_IDENTIFIER={_LETTER}{_PART_LETTER}*
141144
L_IDENTIFIER_TEXT=\`[^`]+\`
142-
L_DECIMAL=(0|[1-9][0-9]*)\.[0-9]+
145+
L_DECIMAL=[0-9] {_INTEGER_PART}* "_"? "." {_INTEGER_PART}+ {_DECIMAL_EXPONENT}? {L_IDENTIFIER}?
146+
| "." {_INTEGER_PART}+ {_DECIMAL_EXPONENT}? {L_IDENTIFIER}?
147+
| [0-9] {_INTEGER_PART}* {_DECIMAL_EXPONENT} {L_IDENTIFIER}?
148+
L_HEX_INTEGER=0[xX][0-9a-fA-F]*
149+
L_OCTAL_INTEGER=0"o"[0-7]*
143150
L_INTEGER=0|[1-9][0-9]*
144151
L_STRING=('([^'\\]|\\.)*'|\"([^\"\\]|\\.)*\")
145152

153+
_LETTER=[a-zA-Z]
154+
_PART_LETTER=[a-zA-Z_$0-9]
155+
146156
LINE_COMMENT = "//" [^\r\n]*
147157
BLOCK_COMMENT = "/*" ( ([^"*"]|[\r\n])* ("*"+ [^"*""/"] )? )* ("*" | "*"+"/")?
148158

@@ -289,6 +299,8 @@ BLOCK_COMMENT = "/*" ( ([^"*"]|[\r\n])* ("*"+ [^"*""/"] )? )* ("*" | "*"+"/")?
289299
{L_DECIMAL} { return L_DECIMAL; }
290300
{L_INTEGER} { return L_INTEGER; }
291301
{L_STRING} { return L_STRING; }
302+
{L_HEX_INTEGER} { return L_HEX_INTEGER; }
303+
{L_OCTAL_INTEGER} { return L_OCTAL_INTEGER; }
292304

293305
}
294306

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.albertoventurini.graphdbplugin.test.integration.neo4j.tests.cypher.parsing;
2+
3+
import com.albertoventurini.graphdbplugin.test.integration.neo4j.tests.cypher.util.BaseParsingTest;
4+
5+
public class LexerTest extends BaseParsingTest {
6+
7+
public LexerTest() {
8+
super("lexer");
9+
}
10+
11+
public void testScientificNotation() {
12+
doTest(true);
13+
}
14+
15+
public void testHexNumbers() {
16+
doTest(true);
17+
}
18+
19+
public void testOctalNumbers() {
20+
doTest(true);
21+
}
22+
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RETURN 0x10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Cypher file: FILE(0,11)
2+
CypherStatementItemImpl(STATEMENT_ITEM)(0,11)
3+
CypherStatementImpl(STATEMENT)(0,11)
4+
CypherQueryOptionsImpl(QUERY_OPTIONS)(0,0)
5+
<empty list>
6+
CypherQueryImpl(QUERY)(0,11)
7+
CypherRegularQueryImpl(REGULAR_QUERY)(0,11)
8+
CypherSingleQueryImpl(SINGLE_QUERY)(0,11)
9+
CypherSinglePartQueryImpl(SINGLE_PART_QUERY)(0,11)
10+
CypherReadingWithReturnImpl(READING_WITH_RETURN)(0,11)
11+
CypherReturnImpl(RETURN)(0,11)
12+
PsiElement(RETURN)('RETURN')(0,6)
13+
CypherReturnBodyImpl(RETURN_BODY)(7,11)
14+
CypherReturnItemsImpl(RETURN_ITEMS)(7,11)
15+
CypherReturnItemImpl(RETURN_ITEM)(7,11)
16+
CypherExpressionImpl(EXPRESSION)(7,11)
17+
CypherNumberLiteralImpl(NUMBER_LITERAL)(7,11)
18+
CypherIntegerLiteralImpl(INTEGER_LITERAL)(7,11)
19+
CypherUnsignedIntegerImpl(UNSIGNED_INTEGER)(7,11)
20+
PsiElement(hex_integer)('0x10')(7,11)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RETURN 0o01234567
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Cypher file: FILE(0,17)
2+
CypherStatementItemImpl(STATEMENT_ITEM)(0,17)
3+
CypherStatementImpl(STATEMENT)(0,17)
4+
CypherQueryOptionsImpl(QUERY_OPTIONS)(0,0)
5+
<empty list>
6+
CypherQueryImpl(QUERY)(0,17)
7+
CypherRegularQueryImpl(REGULAR_QUERY)(0,17)
8+
CypherSingleQueryImpl(SINGLE_QUERY)(0,17)
9+
CypherSinglePartQueryImpl(SINGLE_PART_QUERY)(0,17)
10+
CypherReadingWithReturnImpl(READING_WITH_RETURN)(0,17)
11+
CypherReturnImpl(RETURN)(0,17)
12+
PsiElement(RETURN)('RETURN')(0,6)
13+
CypherReturnBodyImpl(RETURN_BODY)(7,17)
14+
CypherReturnItemsImpl(RETURN_ITEMS)(7,17)
15+
CypherReturnItemImpl(RETURN_ITEM)(7,17)
16+
CypherExpressionImpl(EXPRESSION)(7,17)
17+
CypherNumberLiteralImpl(NUMBER_LITERAL)(7,17)
18+
CypherIntegerLiteralImpl(INTEGER_LITERAL)(7,17)
19+
CypherUnsignedIntegerImpl(UNSIGNED_INTEGER)(7,17)
20+
PsiElement(octal_integer)('0o01234567')(7,17)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
RETURN 1e6;
2+
RETURN 1.7976931348623157e+308;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Cypher file: FILE(0,43)
2+
CypherStatementItemImpl(STATEMENT_ITEM)(0,11)
3+
CypherStatementImpl(STATEMENT)(0,10)
4+
CypherQueryOptionsImpl(QUERY_OPTIONS)(0,0)
5+
<empty list>
6+
CypherQueryImpl(QUERY)(0,10)
7+
CypherRegularQueryImpl(REGULAR_QUERY)(0,10)
8+
CypherSingleQueryImpl(SINGLE_QUERY)(0,10)
9+
CypherSinglePartQueryImpl(SINGLE_PART_QUERY)(0,10)
10+
CypherReadingWithReturnImpl(READING_WITH_RETURN)(0,10)
11+
CypherReturnImpl(RETURN)(0,10)
12+
PsiElement(RETURN)('RETURN')(0,6)
13+
CypherReturnBodyImpl(RETURN_BODY)(7,10)
14+
CypherReturnItemsImpl(RETURN_ITEMS)(7,10)
15+
CypherReturnItemImpl(RETURN_ITEM)(7,10)
16+
CypherExpressionImpl(EXPRESSION)(7,10)
17+
CypherNumberLiteralImpl(NUMBER_LITERAL)(7,10)
18+
CypherDoubleLiteralImpl(DOUBLE_LITERAL)(7,10)
19+
CypherUnsignedDoubleImpl(UNSIGNED_DOUBLE)(7,10)
20+
PsiElement(decimal)('1e6')(7,10)
21+
PsiElement(;)(';')(10,11)
22+
CypherStatementItemImpl(STATEMENT_ITEM)(12,43)
23+
CypherStatementImpl(STATEMENT)(12,42)
24+
CypherQueryOptionsImpl(QUERY_OPTIONS)(12,12)
25+
<empty list>
26+
CypherQueryImpl(QUERY)(12,42)
27+
CypherRegularQueryImpl(REGULAR_QUERY)(12,42)
28+
CypherSingleQueryImpl(SINGLE_QUERY)(12,42)
29+
CypherSinglePartQueryImpl(SINGLE_PART_QUERY)(12,42)
30+
CypherReadingWithReturnImpl(READING_WITH_RETURN)(12,42)
31+
CypherReturnImpl(RETURN)(12,42)
32+
PsiElement(RETURN)('RETURN')(12,18)
33+
CypherReturnBodyImpl(RETURN_BODY)(19,42)
34+
CypherReturnItemsImpl(RETURN_ITEMS)(19,42)
35+
CypherReturnItemImpl(RETURN_ITEM)(19,42)
36+
CypherExpressionImpl(EXPRESSION)(19,42)
37+
CypherNumberLiteralImpl(NUMBER_LITERAL)(19,42)
38+
CypherDoubleLiteralImpl(DOUBLE_LITERAL)(19,42)
39+
CypherUnsignedDoubleImpl(UNSIGNED_DOUBLE)(19,42)
40+
PsiElement(decimal)('1.7976931348623157e+308')(19,42)
41+
PsiElement(;)(';')(42,43)

0 commit comments

Comments
 (0)