cypher parser is extended again (find by internal_id ID(n)=internal_id)
This commit is contained in:
parent
c8440b4671
commit
8a3aee1ba6
@ -71,6 +71,8 @@ struct WithList;
|
||||
struct WithClause;
|
||||
struct WithQuery;
|
||||
|
||||
struct InternalIdExpr;
|
||||
|
||||
struct AstVisitor
|
||||
: public Visitor<Accessor, Boolean, Float, Identifier, Alias, Integer,
|
||||
String, Property, And, Or, Lt, Gt, Ge, Le, Eq, Ne, Plus,
|
||||
@ -81,6 +83,7 @@ struct AstVisitor
|
||||
Distinct, Delete, DeleteQuery, UpdateQuery, Set, SetKey,
|
||||
ReadWriteQuery, IdentifierList,
|
||||
WithList, WithClause, WithQuery,
|
||||
InternalIdExpr,
|
||||
SetValue, SetElement, SetList>
|
||||
{
|
||||
};
|
||||
|
@ -14,10 +14,7 @@ struct ValueExpr : public Crtp<Derived>, public Expr
|
||||
{
|
||||
using uptr = std::unique_ptr<Derived>;
|
||||
|
||||
virtual void accept(AstVisitor& visitor)
|
||||
{
|
||||
visitor.visit(this->derived());
|
||||
}
|
||||
virtual void accept(AstVisitor &visitor) { visitor.visit(this->derived()); }
|
||||
};
|
||||
|
||||
template <class T, class Derived>
|
||||
@ -30,24 +27,20 @@ struct LeafExpr : public ValueExpr<Derived>
|
||||
template <class Derived>
|
||||
struct BinaryExpr : public ValueExpr<Derived>
|
||||
{
|
||||
BinaryExpr(Expr* left, Expr* right) : left(left), right(right) {}
|
||||
BinaryExpr(Expr *left, Expr *right) : left(left), right(right) {}
|
||||
|
||||
Expr* left;
|
||||
Expr* right;
|
||||
Expr *left;
|
||||
Expr *right;
|
||||
};
|
||||
|
||||
struct PatternExpr : public Expr
|
||||
{
|
||||
using uptr = std::unique_ptr<PatternExpr>;
|
||||
|
||||
PatternExpr(Pattern* pattern) : pattern(pattern) {}
|
||||
PatternExpr(Pattern *pattern) : pattern(pattern) {}
|
||||
|
||||
virtual void accept(AstVisitor& visitor)
|
||||
{
|
||||
visitor.visit(*this);
|
||||
}
|
||||
virtual void accept(AstVisitor &visitor) { visitor.visit(*this); }
|
||||
|
||||
Pattern* pattern;
|
||||
Pattern *pattern;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,16 @@ struct Integer : public LeafExpr<int, Integer>
|
||||
using LeafExpr::LeafExpr;
|
||||
};
|
||||
|
||||
struct Long : public LeafExpr<int64_t, Long>
|
||||
{
|
||||
using LeafExpr::LeafExpr;
|
||||
};
|
||||
|
||||
struct ULong : public LeafExpr<uint64_t, ULong>
|
||||
{
|
||||
using LeafExpr::LeafExpr;
|
||||
};
|
||||
|
||||
struct Boolean : public LeafExpr<bool, Boolean>
|
||||
{
|
||||
using LeafExpr::LeafExpr;
|
||||
@ -27,4 +37,17 @@ struct String : public LeafExpr<std::string, String>
|
||||
using LeafExpr::LeafExpr;
|
||||
};
|
||||
|
||||
struct InternalIdExpr : public Expr
|
||||
{
|
||||
InternalIdExpr(Identifier *identifier, Integer *value)
|
||||
: identifier(identifier), value(value)
|
||||
{
|
||||
}
|
||||
|
||||
Identifier *identifier;
|
||||
Integer *value;
|
||||
|
||||
virtual void accept(AstVisitor &visitor) { visitor.visit(*this); }
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -444,6 +444,11 @@ value_expr(E) ::= idn(I) DOT idn(P). {
|
||||
E = ast->create<ast::Accessor>(I, P);
|
||||
}
|
||||
|
||||
value_expr(E) ::= ID LP idn(I) RP EQ INT(V). {
|
||||
auto value = std::stoi(V->value);
|
||||
E = ast->create<ast::InternalIdExpr>(I, ast->create<ast::Integer>(value));
|
||||
}
|
||||
|
||||
%type idn {ast::Identifier*}
|
||||
|
||||
idn(I) ::= IDN(X). {
|
||||
|
@ -184,12 +184,24 @@ public:
|
||||
entry << "Integer " << integer.value;
|
||||
}
|
||||
|
||||
// void visit(ast::ULong& ulong) override
|
||||
// {
|
||||
// auto entry = printer.advance();
|
||||
// entry << "ULong " << ulong.value;
|
||||
// }
|
||||
|
||||
void visit(ast::String& string) override
|
||||
{
|
||||
auto entry = printer.advance();
|
||||
entry << "String " << string.value;
|
||||
}
|
||||
|
||||
void visit(ast::InternalIdExpr& internal_id) override
|
||||
{
|
||||
auto entry = printer.advance("InternalId");
|
||||
Traverser::visit(internal_id);
|
||||
}
|
||||
|
||||
void visit(ast::Property& property) override
|
||||
{
|
||||
auto entry = printer.advance("Property");
|
||||
|
@ -50,6 +50,10 @@ public:
|
||||
rule("(?i:DISTINCT)", TK_DISTINCT);
|
||||
rule("(?i:DELETE)", TK_DELETE);
|
||||
rule("(?i:WITH)", TK_WITH);
|
||||
// TODO: here should be better regex
|
||||
// problem is that id in property list isn't ID from where
|
||||
// part
|
||||
rule("(?-i:ID)", TK_ID);
|
||||
|
||||
rule("(?i:AND)", TK_AND);
|
||||
rule("(?i:OR)", TK_OR);
|
||||
|
@ -30,11 +30,8 @@ public:
|
||||
void visit(ast::ReadWriteQuery& query) override
|
||||
{
|
||||
accept(query.match_clause);
|
||||
|
||||
accept(query.create_clause);
|
||||
|
||||
if (query.return_clause != nullptr)
|
||||
accept(query.return_clause);
|
||||
accept(query.return_clause);
|
||||
}
|
||||
|
||||
void visit(ast::Match& match) override
|
||||
@ -279,6 +276,12 @@ public:
|
||||
accept(with_query.return_clause);
|
||||
}
|
||||
|
||||
void visit(ast::InternalIdExpr& internal_id) override
|
||||
{
|
||||
accept(internal_id.identifier);
|
||||
accept(internal_id.value);
|
||||
}
|
||||
|
||||
protected:
|
||||
template<class T>
|
||||
void accept(T* node)
|
||||
|
@ -27,6 +27,10 @@ public:
|
||||
++index;
|
||||
}
|
||||
|
||||
void visit(ast::InternalIdExpr& internal_id) override
|
||||
{
|
||||
}
|
||||
|
||||
void visit(ast::Return& ret) override
|
||||
{
|
||||
#ifdef DEBUG
|
||||
|
@ -45,6 +45,7 @@ foreach(test ${concurrency_test_names})
|
||||
set(test_name concurrent_${test})
|
||||
add_executable(${test_name} concurrent/${test}.cpp)
|
||||
target_link_libraries(${test_name} Threads::Threads)
|
||||
target_link_libraries(${test_name} ${fmt_static_lib})
|
||||
add_test(NAME ${test_name} COMMAND ${test_name})
|
||||
set_property(TARGET ${test_name} PROPERTY CXX_STANDARD 14)
|
||||
endforeach()
|
||||
@ -60,8 +61,16 @@ set_property(TARGET integration_queries PROPERTY CXX_STANDARD 14)
|
||||
|
||||
## MANUAL TESTS
|
||||
|
||||
# query engine
|
||||
add_executable(manual_query_engine manual/query_engine.cpp ${memgraph_src_files})
|
||||
target_link_libraries(manual_query_engine ${fmt_static_lib})
|
||||
target_link_libraries(manual_query_engine dl)
|
||||
target_link_libraries(manual_query_engine cypher_lib)
|
||||
set_property(TARGET manual_query_engine PROPERTY CXX_STANDARD 14)
|
||||
|
||||
# ast traversal
|
||||
add_executable(cypher_ast_traverser manual/cypher_ast.cpp ${mamgraph_src_files})
|
||||
target_link_libraries(cypher_ast_traverser ${fmt_static_lib})
|
||||
target_link_libraries(cypher_ast_traverser cypher_lib)
|
||||
set_property(TARGET cypher_ast_traverser PROPERTY CXX_STANDARD 14)
|
||||
|
||||
|
@ -1 +1 @@
|
||||
MATCH (p:Personnel)-[:CREATED]->(o:Opportunity)-[:HAS_MATCH]->(c:Company {id: "321"}) RETURN (a:Account {id: "123"})-[:IS]->(p)
|
||||
MATCH (p:Personnel)-[:CREATED]->(o:Opportunity)-[:HAS_MATCH]->(c:Company {identifier: "321"}) RETURN (a:Account {prop: "123"})-[:IS]->(p)
|
||||
|
1
tests/data/cypher_queries/sprint_0/query_04.cypher
Normal file
1
tests/data/cypher_queries/sprint_0/query_04.cypher
Normal file
@ -0,0 +1 @@
|
||||
MATCH (n {id:0}) SET n.name = "TEST100" RETURN n
|
1
tests/data/cypher_queries/sprint_0/query_07.cypher
Normal file
1
tests/data/cypher_queries/sprint_0/query_07.cypher
Normal file
@ -0,0 +1 @@
|
||||
MATCH ()-[r]-() WHERE ID(r)=0 RETURN r
|
1
tests/data/cypher_queries/sprint_0/query_08.cypher
Normal file
1
tests/data/cypher_queries/sprint_0/query_08.cypher
Normal file
@ -0,0 +1 @@
|
||||
MATCH (a),(b) WHERE ID(a)=0 AND ID(b)=1 RETURN a,b
|
1
tests/data/cypher_queries/sprint_0/query_09.cypher
Normal file
1
tests/data/cypher_queries/sprint_0/query_09.cypher
Normal file
@ -0,0 +1 @@
|
||||
MATCH (n) WHERE ID(n)=0 SET n.name = "bla" RETURN n
|
1
tests/data/cypher_queries/sprint_0/query_10.cypher
Normal file
1
tests/data/cypher_queries/sprint_0/query_10.cypher
Normal file
@ -0,0 +1 @@
|
||||
MATCH ()-[r]-() WHERE ID(r)=0 SET r.test = "bla" RETURN r
|
@ -1 +0,0 @@
|
||||
MATCH (n {id: 0}) SET n.name = "TEST100" RETURN n
|
44
tests/manual/cypher_ast.cpp
Normal file
44
tests/manual/cypher_ast.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
#include <vector>
|
||||
|
||||
#include "cypher/compiler.hpp"
|
||||
#include "cypher/debug/tree_print.hpp"
|
||||
#include "utils/command_line/arguments.hpp"
|
||||
#include "cypher/common.hpp"
|
||||
#include "utils/terminate_handler.hpp"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
// * INPUT ARGUMENTS *
|
||||
// -q -> query
|
||||
// -v -> visitor
|
||||
// -f -> file
|
||||
//
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::set_terminate(&terminate_handler);
|
||||
|
||||
// arguments parsing
|
||||
auto arguments = all_arguments(argc, argv);
|
||||
|
||||
// query extraction
|
||||
auto cypher_query = extract_query(arguments);
|
||||
cout << "QUERY: " << cypher_query << endl;
|
||||
|
||||
// traversers
|
||||
auto traverser = get_argument(arguments, "-t", "code");
|
||||
auto print_traverser = Traverser::sptr(new PrintVisitor(cout));
|
||||
std::map<std::string, Traverser::sptr> traversers = {
|
||||
{"print", print_traverser}
|
||||
};
|
||||
|
||||
cypher::Compiler compiler;
|
||||
auto tree = compiler.syntax_tree(cypher_query);
|
||||
|
||||
auto t = traversers[traverser];
|
||||
tree.root->accept(*t);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user