From 343fe54f2cb79c99e1932889dd50053e1b803ec0 Mon Sep 17 00:00:00 2001 From: Marin Tomic Date: Thu, 4 Oct 2018 16:31:41 +0200 Subject: [PATCH] Move 'explain' to Cypher.g4 and add it to keyword list Summary: Move explain to Cypher.g4 so MemgraphCypher contains only enterprise features. Also added `EXPLAIN` to keyword list because query `MATCH (explain) RETURN explain` wasn't working. Reviewers: teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1632 --- .../frontend/opencypher/grammar/Cypher.g4 | 7 +++++- .../opencypher/grammar/CypherLexer.g4 | 1 + .../opencypher/grammar/MemgraphCypher.g4 | 4 +--- .../opencypher/grammar/MemgraphCypherLexer.g4 | 3 +-- .../frontend/stripped_lexer_constants.hpp | 24 +++++++++---------- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/query/frontend/opencypher/grammar/Cypher.g4 b/src/query/frontend/opencypher/grammar/Cypher.g4 index ac7899e14..bb1d3eef9 100644 --- a/src/query/frontend/opencypher/grammar/Cypher.g4 +++ b/src/query/frontend/opencypher/grammar/Cypher.g4 @@ -23,7 +23,11 @@ cypher : statement ';'? EOF ; statement : query ; -query : regularQuery ; +query : regularQuery + | explainQuery + ; + +explainQuery : EXPLAIN regularQuery ; regularQuery : singleQuery ( cypherUnion )* ; @@ -291,6 +295,7 @@ cypherKeyword : ALL | ELSE | END | ENDS + | EXPLAIN | EXTRACT | FALSE | FILTER diff --git a/src/query/frontend/opencypher/grammar/CypherLexer.g4 b/src/query/frontend/opencypher/grammar/CypherLexer.g4 index aad481a36..ce4b06dc6 100644 --- a/src/query/frontend/opencypher/grammar/CypherLexer.g4 +++ b/src/query/frontend/opencypher/grammar/CypherLexer.g4 @@ -89,6 +89,7 @@ DISTINCT : D I S T I N C T ; ELSE : E L S E ; END : E N D ; ENDS : E N D S ; +EXPLAIN : E X P L A I N ; EXTRACT : E X T R A C T ; FALSE : F A L S E ; FILTER : F I L T E R ; diff --git a/src/query/frontend/opencypher/grammar/MemgraphCypher.g4 b/src/query/frontend/opencypher/grammar/MemgraphCypher.g4 index c11908966..a2935e1e8 100644 --- a/src/query/frontend/opencypher/grammar/MemgraphCypher.g4 +++ b/src/query/frontend/opencypher/grammar/MemgraphCypher.g4 @@ -1,4 +1,4 @@ -/* Memgraph specific part of Cypher grammar. */ +/* Memgraph specific part of Cypher grammar with enterprise features. */ parser grammar MemgraphCypher ; @@ -51,8 +51,6 @@ query : regularQuery | explainQuery ; -explainQuery : EXPLAIN regularQuery ; - authQuery : createRole | dropRole | showRoles diff --git a/src/query/frontend/opencypher/grammar/MemgraphCypherLexer.g4 b/src/query/frontend/opencypher/grammar/MemgraphCypherLexer.g4 index 9accae45f..cbb97da34 100644 --- a/src/query/frontend/opencypher/grammar/MemgraphCypherLexer.g4 +++ b/src/query/frontend/opencypher/grammar/MemgraphCypherLexer.g4 @@ -1,4 +1,4 @@ -/* Memgraph specific Cypher reserved words. */ +/* Memgraph specific Cypher reserved words used for enterprise features. */ /* * When changing this grammar make sure to update constants in @@ -18,7 +18,6 @@ CLEAR : C L E A R ; DATA : D A T A ; DENY : D E N Y ; DROP : D R O P ; -EXPLAIN : E X P L A I N ; FOR : F O R ; FROM : F R O M ; GRANT : G R A N T ; diff --git a/src/query/frontend/stripped_lexer_constants.hpp b/src/query/frontend/stripped_lexer_constants.hpp index ec22dc77a..07e6cd546 100644 --- a/src/query/frontend/stripped_lexer_constants.hpp +++ b/src/query/frontend/stripped_lexer_constants.hpp @@ -79,18 +79,18 @@ class Trie { const int kBitsetSize = 65536; const trie::Trie kKeywords = { - "union", "all", "optional", "match", "unwind", "as", - "merge", "on", "create", "set", "detach", "delete", - "remove", "with", "distinct", "return", "order", "by", - "skip", "limit", "ascending", "asc", "descending", "desc", - "where", "or", "xor", "and", "not", "in", - "starts", "ends", "contains", "is", "null", "case", - "when", "then", "else", "end", "count", "filter", - "extract", "any", "none", "single", "true", "false", - "reduce", "user", "password", "alter", "drop", "stream", - "streams", "load", "data", "kafka", "transform", "batch", - "interval", "show", "start", "stop", "size", "topic", - "test"}; + "union", "all", "optional", "match", "unwind", "as", + "merge", "on", "create", "set", "detach", "delete", + "remove", "with", "distinct", "return", "order", "by", + "skip", "limit", "ascending", "asc", "descending", "desc", + "where", "or", "xor", "and", "not", "in", + "starts", "ends", "contains", "is", "null", "case", + "when", "then", "else", "end", "count", "filter", + "extract", "any", "none", "single", "true", "false", + "reduce", "user", "password", "alter", "drop", "stream", + "streams", "load", "data", "kafka", "transform", "batch", + "interval", "show", "start", "stop", "size", "topic", + "test", "explain"}; // Unicode codepoints that are allowed at the start of the unescaped name. const std::bitset kUnescapedNameAllowedStarts(std::string(