Skip to content

Commit

Permalink
Parser2 (#4478)
Browse files Browse the repository at this point in the history
* 5

* 6

* 5
  • Loading branch information
peter-rich authored Aug 2, 2022
1 parent ef6d6a0 commit 1e58ada
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 69 deletions.
1 change: 1 addition & 0 deletions .linters/cpp/checkKeyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

reserved_key_words = [
'KW_GO',
'KW_ISOMOR',
'KW_AS',
'KW_TO',
'KW_OR',
Expand Down
21 changes: 21 additions & 0 deletions src/parser/TraverseSentences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,29 @@

#include "common/base/Base.h"

#include <stdio.h>

namespace nebula {


IsomorSentence::~IsomorSentence() {
printf("Deconstuct. \n");
}

std::string IsomorSentence::toString() const {
std::string buf;
buf.reserve(256);
buf += "ISOMOR";
buf += " ";
if (tags_->empty()) {
buf += "*";
} else {
buf += tags_->toString();
}
printf("Here is the string: %s \n", buf.c_str());
return buf;
}

std::string GoSentence::toString() const {
std::string buf;
buf.reserve(256);
Expand Down
16 changes: 15 additions & 1 deletion src/parser/TraverseSentences.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,23 @@
#include "parser/EdgeKey.h"
#include "parser/MutateSentences.h"
#include "parser/Sentence.h"

namespace nebula {

class IsomorSentence final : public Sentence {
public:
explicit IsomorSentence(NameLabelList* tags) {
tags_.reset(tags);
}
const NameLabelList* tags() const {
return tags_->empty() ? nullptr : tags_.get();
}
std::string toString() const override;
~IsomorSentence();

private:
std::unique_ptr<NameLabelList> tags_;
};

class GoSentence final : public Sentence {
public:
GoSentence(StepClause* step,
Expand Down
63 changes: 39 additions & 24 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
%parse-param { std::string &errmsg }
%parse-param { nebula::Sentence** sentences }
%parse-param { nebula::graph::QueryContext* qctx }

%code requires {
#include <iostream>
#include <sstream>
Expand Down Expand Up @@ -173,7 +173,8 @@ using namespace nebula;
%token KW_BOOL KW_INT8 KW_INT16 KW_INT32 KW_INT64 KW_INT KW_FLOAT KW_DOUBLE
%token KW_STRING KW_FIXED_STRING KW_TIMESTAMP KW_DATE KW_TIME KW_DATETIME KW_DURATION
%token KW_GO KW_AS KW_TO KW_USE KW_SET KW_FROM KW_WHERE KW_ALTER
%token KW_MATCH KW_INSERT KW_VALUE KW_VALUES KW_YIELD KW_RETURN KW_CREATE KW_VERTEX KW_VERTICES KW_IGNORE_EXISTED_INDEX
%token KW_MATCH KW_INSERT KW_VALUE KW_VALUES KW_YIELD KW_RETURN KW_CREATE KW_VERTEX KW_VERTICES KW_IGNORE_EXISTED_INDEX
%token KW_ISOMOR
%token KW_EDGE KW_EDGES KW_STEPS KW_OVER KW_UPTO KW_REVERSELY KW_SPACE KW_DELETE KW_FIND
%token KW_TAG KW_TAGS KW_UNION KW_INTERSECT KW_MINUS
%token KW_NO KW_OVERWRITE KW_IN KW_DESCRIBE KW_DESC KW_SHOW KW_HOST KW_HOSTS KW_PART KW_PARTS KW_ADD
Expand Down Expand Up @@ -391,6 +392,7 @@ using namespace nebula;
%type <sentence> download_sentence ingest_sentence

%type <sentence> traverse_sentence
%type <sentence> isomor_sentence
%type <sentence> go_sentence match_sentence lookup_sentence find_path_sentence get_subgraph_sentence
%type <sentence> group_by_sentence order_by_sentence limit_sentence
%type <sentence> fetch_sentence fetch_vertices_sentence fetch_edges_sentence
Expand Down Expand Up @@ -1390,11 +1392,20 @@ truncate_clause

go_sentence
: KW_GO step_clause from_clause over_clause where_clause yield_clause truncate_clause {
auto go = new GoSentence($2, $3, $4, $5, $7);
go->setYieldClause($6);
$$ = go;
auto go = new GoSentence($2, $3, $4, $5, $7);
go->setYieldClause($6);
$$ = go;
}
;


isomor_sentence
: KW_ISOMOR name_label_list {
auto isomor = new IsomorSentence($2);
$$ = isomor;
}
;


step_clause
: %empty { $$ = new StepClause(); }
Expand All @@ -1406,19 +1417,19 @@ step_clause
}
;

from_clause
: KW_FROM vid_list {
$$ = new FromClause($2);
}
| KW_FROM vid_ref_expression {
if(graph::ExpressionUtils::findAny($2,{Expression::Kind::kVar})) {
throw nebula::GraphParser::syntax_error(@2, "Parameter is not supported in from clause");
}
$$ = new FromClause($2);
}
;
from_clause
: KW_FROM vid_list {
$$ = new FromClause($2);
}
| KW_FROM vid_ref_expression {
if(graph::ExpressionUtils::findAny($2,{Expression::Kind::kVar})) {
throw nebula::GraphParser::syntax_error(@2, "Parameter is not supported in from clause");
}
$$ = new FromClause($2);
}
;

vid_list
vid_list
: vid {
$$ = new VertexIDList();
$$->add($1);
Expand Down Expand Up @@ -1455,9 +1466,9 @@ vid
throw nebula::GraphParser::syntax_error(@1, "Variable is not supported in vid");
}
}
;

unary_integer
;
unary_integer
: PLUS legal_integer {
$$ = $2;
}
Expand All @@ -1468,7 +1479,7 @@ unary_integer
$$ = $1;
}
;

vid_ref_expression
: input_prop_expression {
$$ = $1;
Expand All @@ -1480,7 +1491,7 @@ vid_ref_expression
$$ = $1;
}
;

over_edge
: name_label {
$$ = new OverEdge($1);
Expand Down Expand Up @@ -1691,6 +1702,9 @@ match_clause
}
;




reading_clause
: unwind_clause {
$$ = $1;
Expand Down Expand Up @@ -1782,13 +1796,13 @@ match_path
$$ = $3;
$$->setAlias($1);
}
;
;

match_path_list
: match_path {
$$ = new MatchPathList($1);
}
| match_path_list COMMA match_path {
| match_path_list COMMA match_path {
$$ = $1;
$$->add($3);
}
Expand Down Expand Up @@ -2922,6 +2936,7 @@ desc_zone_sentence
traverse_sentence
: L_PAREN set_sentence R_PAREN { $$ = $2; }
| go_sentence { $$ = $1; }
| isomor_sentence { $$ = $1; }
| lookup_sentence { $$ = $1; }
| group_by_sentence { $$ = $1; }
| order_by_sentence { $$ = $1; }
Expand Down
89 changes: 45 additions & 44 deletions src/parser/scanner.lex
Original file line number Diff line number Diff line change
Expand Up @@ -94,50 +94,51 @@ LABEL_FULL_WIDTH {CN_EN_FULL_WIDTH}{CN_EN_NUM_FULL_WIDTH}*
"FROM" { return TokenType::KW_FROM; }
"WHERE" { return TokenType::KW_WHERE; }
"MATCH" { return TokenType::KW_MATCH; }
"INSERT" { return TokenType::KW_INSERT; }
"YIELD" { return TokenType::KW_YIELD; }
"RETURN" { return TokenType::KW_RETURN; }
"DESCRIBE" { return TokenType::KW_DESCRIBE; }
"DESC" { return TokenType::KW_DESC; }
"VERTEX" { return TokenType::KW_VERTEX; }
"VERTICES" { return TokenType::KW_VERTICES; }
"EDGE" { return TokenType::KW_EDGE; }
"EDGES" { return TokenType::KW_EDGES; }
"UPDATE" { return TokenType::KW_UPDATE; }
"UPSERT" { return TokenType::KW_UPSERT; }
"WHEN" { return TokenType::KW_WHEN; }
"DELETE" { return TokenType::KW_DELETE; }
"FIND" { return TokenType::KW_FIND; }
"PATH" { return TokenType::KW_PATH; }
"LOOKUP" { return TokenType::KW_LOOKUP; }
"ALTER" { return TokenType::KW_ALTER; }
"STEPS" { return TokenType::KW_STEPS; }
"STEP" { return TokenType::KW_STEPS; }
"OVER" { return TokenType::KW_OVER; }
"UPTO" { return TokenType::KW_UPTO; }
"REVERSELY" { return TokenType::KW_REVERSELY; }
"INDEX" { return TokenType::KW_INDEX; }
"INDEXES" { return TokenType::KW_INDEXES; }
"REBUILD" { return TokenType::KW_REBUILD; }
"BOOL" { return TokenType::KW_BOOL; }
"INT8" { return TokenType::KW_INT8; }
"INT16" { return TokenType::KW_INT16; }
"INT32" { return TokenType::KW_INT32; }
"INT64" { return TokenType::KW_INT64; }
"INT" { return TokenType::KW_INT; }
"FLOAT" { return TokenType::KW_FLOAT; }
"DOUBLE" { return TokenType::KW_DOUBLE; }
"STRING" { return TokenType::KW_STRING; }
"FIXED_STRING" { return TokenType::KW_FIXED_STRING; }
"TIMESTAMP" { return TokenType::KW_TIMESTAMP; }
"DATE" { return TokenType::KW_DATE; }
"TIME" { return TokenType::KW_TIME; }
"DATETIME" { return TokenType::KW_DATETIME; }
"TAG" { return TokenType::KW_TAG; }
"TAGS" { return TokenType::KW_TAGS; }
"UNION" { return TokenType::KW_UNION; }
"INTERSECT" { return TokenType::KW_INTERSECT; }
"MINUS" { return TokenType::KW_MINUS; }
"ISOMOR" { return TokenType::KW_ISOMOR; }
"INSERT" { return TokenType::KW_INSERT; }
"YIELD" { return TokenType::KW_YIELD; }
"RETURN" { return TokenType::KW_RETURN; }
"DESCRIBE" { return TokenType::KW_DESCRIBE; }
"DESC" { return TokenType::KW_DESC; }
"VERTEX" { return TokenType::KW_VERTEX; }
"VERTICES" { return TokenType::KW_VERTICES; }
"EDGE" { return TokenType::KW_EDGE; }
"EDGES" { return TokenType::KW_EDGES; }
"UPDATE" { return TokenType::KW_UPDATE; }
"UPSERT" { return TokenType::KW_UPSERT; }
"WHEN" { return TokenType::KW_WHEN; }
"DELETE" { return TokenType::KW_DELETE; }
"FIND" { return TokenType::KW_FIND; }
"PATH" { return TokenType::KW_PATH; }
"LOOKUP" { return TokenType::KW_LOOKUP; }
"ALTER" { return TokenType::KW_ALTER; }
"STEPS" { return TokenType::KW_STEPS; }
"STEP" { return TokenType::KW_STEPS; }
"OVER" { return TokenType::KW_OVER; }
"UPTO" { return TokenType::KW_UPTO; }
"REVERSELY" { return TokenType::KW_REVERSELY; }
"INDEX" { return TokenType::KW_INDEX; }
"INDEXES" { return TokenType::KW_INDEXES; }
"REBUILD" { return TokenType::KW_REBUILD; }
"BOOL" { return TokenType::KW_BOOL; }
"INT8" { return TokenType::KW_INT8; }
"INT16" { return TokenType::KW_INT16; }
"INT32" { return TokenType::KW_INT32; }
"INT64" { return TokenType::KW_INT64; }
"INT" { return TokenType::KW_INT; }
"FLOAT" { return TokenType::KW_FLOAT; }
"DOUBLE" { return TokenType::KW_DOUBLE; }
"STRING" { return TokenType::KW_STRING; }
"FIXED_STRING" { return TokenType::KW_FIXED_STRING; }
"TIMESTAMP" { return TokenType::KW_TIMESTAMP; }
"DATE" { return TokenType::KW_DATE; }
"TIME" { return TokenType::KW_TIME; }
"DATETIME" { return TokenType::KW_DATETIME; }
"TAG" { return TokenType::KW_TAG; }
"TAGS" { return TokenType::KW_TAGS; }
"UNION" { return TokenType::KW_UNION; }
"INTERSECT" { return TokenType::KW_INTERSECT; }
"MINUS" { return TokenType::KW_MINUS; }
"NO" { return TokenType::KW_NO; }
"OVERWRITE" { return TokenType::KW_OVERWRITE; }
"SHOW" { return TokenType::KW_SHOW; }
Expand Down
13 changes: 13 additions & 0 deletions src/parser/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ nebula_add_test(
LIBRARIES gtest gtest_main ${THRIFT_LIBRARIES} ${PROXYGEN_LIBRARIES}
)

nebula_add_test(
NAME parser_iso
SOURCES ParserIso.cpp
OBJECTS
${PARSER_TEST_LIBS}
LIBRARIES
gtest gtest_main
${THRIFT_LIBRARIES}
${PROXYGEN_LIBRARIES}
${Ldap_LIBRARIES}
${ROCKSDB_LIBRARIES}
)

nebula_add_test(
NAME scanner_test
SOURCES ScannerTest.cpp
Expand Down
Loading

0 comments on commit 1e58ada

Please sign in to comment.