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) (#65)

* Allow numbers to be written in queries in scientific (exponential) notation (#52 
* Support hex and octal numbers
  • Loading branch information
albertoventurini authored Jan 28, 2023
1 parent f5c039a commit fdc3602
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -635,4 +635,4 @@ Dash ::= "-" // todo: migrate all variants
LeftArrowHead ::= "<" // todo: migrate all variants
RightArrowHead ::= ">" // todo: migrate all variants
UnsignedDouble ::= l_decimal
UnsignedInteger ::= l_integer
UnsignedInteger ::= l_integer | l_hex_integer | l_octal_integer
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,22 @@ 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_HEX_INTEGER=0[xX][0-9a-fA-F]*
L_OCTAL_INTEGER=0"o"[0-7]*
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 Expand Up @@ -289,6 +299,8 @@ BLOCK_COMMENT = "/*" ( ([^"*"]|[\r\n])* ("*"+ [^"*""/"] )? )* ("*" | "*"+"/")?
{L_DECIMAL} { return L_DECIMAL; }
{L_INTEGER} { return L_INTEGER; }
{L_STRING} { return L_STRING; }
{L_HEX_INTEGER} { return L_HEX_INTEGER; }
{L_OCTAL_INTEGER} { return L_OCTAL_INTEGER; }

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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);
}

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

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RETURN 0x10
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Cypher file: FILE(0,11)
CypherStatementItemImpl(STATEMENT_ITEM)(0,11)
CypherStatementImpl(STATEMENT)(0,11)
CypherQueryOptionsImpl(QUERY_OPTIONS)(0,0)
<empty list>
CypherQueryImpl(QUERY)(0,11)
CypherRegularQueryImpl(REGULAR_QUERY)(0,11)
CypherSingleQueryImpl(SINGLE_QUERY)(0,11)
CypherSinglePartQueryImpl(SINGLE_PART_QUERY)(0,11)
CypherReadingWithReturnImpl(READING_WITH_RETURN)(0,11)
CypherReturnImpl(RETURN)(0,11)
PsiElement(RETURN)('RETURN')(0,6)
CypherReturnBodyImpl(RETURN_BODY)(7,11)
CypherReturnItemsImpl(RETURN_ITEMS)(7,11)
CypherReturnItemImpl(RETURN_ITEM)(7,11)
CypherExpressionImpl(EXPRESSION)(7,11)
CypherNumberLiteralImpl(NUMBER_LITERAL)(7,11)
CypherIntegerLiteralImpl(INTEGER_LITERAL)(7,11)
CypherUnsignedIntegerImpl(UNSIGNED_INTEGER)(7,11)
PsiElement(hex_integer)('0x10')(7,11)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RETURN 0o01234567
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Cypher file: FILE(0,17)
CypherStatementItemImpl(STATEMENT_ITEM)(0,17)
CypherStatementImpl(STATEMENT)(0,17)
CypherQueryOptionsImpl(QUERY_OPTIONS)(0,0)
<empty list>
CypherQueryImpl(QUERY)(0,17)
CypherRegularQueryImpl(REGULAR_QUERY)(0,17)
CypherSingleQueryImpl(SINGLE_QUERY)(0,17)
CypherSinglePartQueryImpl(SINGLE_PART_QUERY)(0,17)
CypherReadingWithReturnImpl(READING_WITH_RETURN)(0,17)
CypherReturnImpl(RETURN)(0,17)
PsiElement(RETURN)('RETURN')(0,6)
CypherReturnBodyImpl(RETURN_BODY)(7,17)
CypherReturnItemsImpl(RETURN_ITEMS)(7,17)
CypherReturnItemImpl(RETURN_ITEM)(7,17)
CypherExpressionImpl(EXPRESSION)(7,17)
CypherNumberLiteralImpl(NUMBER_LITERAL)(7,17)
CypherIntegerLiteralImpl(INTEGER_LITERAL)(7,17)
CypherUnsignedIntegerImpl(UNSIGNED_INTEGER)(7,17)
PsiElement(octal_integer)('0o01234567')(7,17)
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 fdc3602

Please sign in to comment.