Skip to content

Commit

Permalink
Add e-notation double (#4616)
Browse files Browse the repository at this point in the history
* Add e-notation double

* Run clang-format

---------

Co-authored-by: CI Bot <[email protected]>
  • Loading branch information
andyfengHKU and andyfengHKU authored Dec 10, 2024
1 parent 0a68e24 commit 6a4685b
Show file tree
Hide file tree
Showing 9 changed files with 1,000 additions and 944 deletions.
7 changes: 6 additions & 1 deletion scripts/antlr4/Cypher.g4
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,12 @@ ZeroDigit
: '0' ;

oC_DoubleLiteral
: RegularDecimalReal ;
: ExponentDecimalReal
| RegularDecimalReal
;

ExponentDecimalReal
: ( ( Digit )+ | ( ( Digit )+ '.' ( Digit )+ ) | ( '.' ( Digit )+ ) ) ( 'E' | 'e' ) '-'? ( Digit )+ ;

RegularDecimalReal
: ( Digit )* '.' ( Digit )+ ;
Expand Down
2 changes: 1 addition & 1 deletion scripts/antlr4/hash.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d9c5285da41449cec8a219dc7d558e11
81546847023f2a4c8d1fec8ef8ff0d88
7 changes: 6 additions & 1 deletion src/antlr4/Cypher.g4
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,12 @@ ZeroDigit
: '0' ;

oC_DoubleLiteral
: RegularDecimalReal ;
: ExponentDecimalReal
| RegularDecimalReal
;

ExponentDecimalReal
: ( ( Digit )+ | ( ( Digit )+ '.' ( Digit )+ ) | ( '.' ( Digit )+ ) ) ( 'E' | 'e' ) '-'? ( Digit )+ ;

RegularDecimalReal
: ( Digit )* '.' ( Digit )+ ;
Expand Down
3 changes: 2 additions & 1 deletion src/parser/transform/transform_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,8 @@ std::unique_ptr<ParsedExpression> Transformer::transformIntegerLiteral(

std::unique_ptr<ParsedExpression> Transformer::transformDoubleLiteral(
CypherParser::OC_DoubleLiteralContext& ctx) {
auto text = ctx.RegularDecimalReal()->getText();
auto text = ctx.ExponentDecimalReal() ? ctx.ExponentDecimalReal()->getText() :
ctx.RegularDecimalReal()->getText();
ku_string_t literal{text.c_str(), text.length()};
double result = 0;
function::CastString::operation(literal, result);
Expand Down
8 changes: 8 additions & 0 deletions test/test_files/projection/single_label.test
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ abc|1
2|person
2|person

-LOG ReturnEDecimal
-STATEMENT RETURN -9.13e-02
---- 1
-0.091300
-STATEMENT RETURN -9.13e-02 + 1
---- 1
0.908700

-LOG ReturnNullLiteral
-STATEMENT RETURN (NULL = NULL) IS NOT NULL, NULL, NULL = NULL
---- 1
Expand Down
828 changes: 422 additions & 406 deletions third_party/antlr4_cypher/cypher_lexer.cpp

Large diffs are not rendered by default.

1,074 changes: 546 additions & 528 deletions third_party/antlr4_cypher/cypher_parser.cpp

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions third_party/antlr4_cypher/include/cypher_lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ class CypherLexer : public antlr4::Lexer {
L_SKIP = 153, INVALID_NOT_EQUAL = 154, MINUS = 155, FACTORIAL = 156,
COLON = 157, StringLiteral = 158, EscapedChar = 159, DecimalInteger = 160,
HexLetter = 161, HexDigit = 162, Digit = 163, NonZeroDigit = 164, NonZeroOctDigit = 165,
ZeroDigit = 166, RegularDecimalReal = 167, UnescapedSymbolicName = 168,
IdentifierStart = 169, IdentifierPart = 170, EscapedSymbolicName = 171,
SP = 172, WHITESPACE = 173, CypherComment = 174, Unknown = 175
ZeroDigit = 166, ExponentDecimalReal = 167, RegularDecimalReal = 168,
UnescapedSymbolicName = 169, IdentifierStart = 170, IdentifierPart = 171,
EscapedSymbolicName = 172, SP = 173, WHITESPACE = 174, CypherComment = 175,
Unknown = 176
};

explicit CypherLexer(antlr4::CharStream *input);
Expand Down
8 changes: 5 additions & 3 deletions third_party/antlr4_cypher/include/cypher_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ class CypherParser : public antlr4::Parser {
L_SKIP = 153, INVALID_NOT_EQUAL = 154, MINUS = 155, FACTORIAL = 156,
COLON = 157, StringLiteral = 158, EscapedChar = 159, DecimalInteger = 160,
HexLetter = 161, HexDigit = 162, Digit = 163, NonZeroDigit = 164, NonZeroOctDigit = 165,
ZeroDigit = 166, RegularDecimalReal = 167, UnescapedSymbolicName = 168,
IdentifierStart = 169, IdentifierPart = 170, EscapedSymbolicName = 171,
SP = 172, WHITESPACE = 173, CypherComment = 174, Unknown = 175
ZeroDigit = 166, ExponentDecimalReal = 167, RegularDecimalReal = 168,
UnescapedSymbolicName = 169, IdentifierStart = 170, IdentifierPart = 171,
EscapedSymbolicName = 172, SP = 173, WHITESPACE = 174, CypherComment = 175,
Unknown = 176
};

enum {
Expand Down Expand Up @@ -2790,6 +2791,7 @@ class CypherParser : public antlr4::Parser {
public:
OC_DoubleLiteralContext(antlr4::ParserRuleContext *parent, size_t invokingState);
virtual size_t getRuleIndex() const override;
antlr4::tree::TerminalNode *ExponentDecimalReal();
antlr4::tree::TerminalNode *RegularDecimalReal();


Expand Down

0 comments on commit 6a4685b

Please sign in to comment.