dressipi usecase hardcoded

This commit is contained in:
Marko Budiselic
2016-09-14 12:19:56 +01:00
parent 266d8ed055
commit c67742e3fa
23 changed files with 311 additions and 10 deletions

View File

@@ -674,6 +674,12 @@ void RecordStream<Stream>::write_meta(const std::string &type)
HALF_CALL(write_meta(type));
}
template <class Stream>
void RecordStream<Stream>::write_failure(const std::map<std::string, std::string> &data)
{
HALF_CALL(write_failure(data));
}
template <class Stream>
void RecordStream<Stream>::send()
{

View File

@@ -19,3 +19,4 @@
#include "set.hpp"
#include "expr.hpp"
#include "with.hpp"
#include "functions.hpp"

View File

@@ -36,6 +36,9 @@ struct Star;
struct Slash;
struct Rem;
// functions
struct CountFunction;
struct RelationshipSpecs;
struct RelationshipTypeList;
struct Relationship;
@@ -83,6 +86,7 @@ struct AstVisitor
PatternList, Match, ReadQuery, Start, Where, WriteQuery, Create,
Return, Distinct, Delete, DeleteQuery, UpdateQuery, Set, SetKey,
ReadWriteQuery, IdentifierList, WithList, WithClause, WithQuery, Long,
CountFunction,
InternalIdExpr, SetValue, SetElement, SetList>
{
};

View File

@@ -24,6 +24,16 @@ struct LeafExpr : public ValueExpr<Derived>
T value;
};
// T is argument type
template <class T, class Derived>
struct FunctionExpr : public ValueExpr<Derived>
{
FunctionExpr(const std::string& name, T argument) : name(name), argument(argument) {}
std::string name;
T argument;
};
template <class Derived>
struct BinaryExpr : public ValueExpr<Derived>
{
@@ -43,4 +53,5 @@ struct PatternExpr : public Expr
Pattern *pattern;
};
}

View File

@@ -0,0 +1,14 @@
#pragma once
#include "expr.hpp"
namespace ast
{
struct CountFunction : public FunctionExpr<std::string, CountFunction>
{
CountFunction(const std::string &argument) : FunctionExpr("count", argument)
{
}
};
}

View File

@@ -495,6 +495,12 @@ pattern_expr(E) ::= pattern(P). {
E = ast->create<ast::PatternExpr>(P);
}
%type function_expr {ast::Expr*}
function_expr(E) ::= COUNT LP IDN(A) RP. {
E = ast->create<ast::CountFunction>(A->value);
}
%type expr {ast::Expr*}
expr(E) ::= value_expr(V). {
@@ -505,6 +511,10 @@ expr(E) ::= pattern_expr(P). {
E = P;
}
expr(E) ::= function_expr(F). {
E = F;
}
//%type alias {ast::Alias*}
//
//alias(A) ::= IDN(X) AS IDN(Y). {

View File

@@ -294,6 +294,12 @@ public:
Traverser::visit(rem);
}
void visit(ast::CountFunction& count) override
{
auto entry = printer.advance("Count ");
entry << count.name << "(" << count.argument << ")";
}
void visit(ast::PropertyList& prop_list) override
{
auto entry = printer.advance("Property List");

View File

@@ -58,6 +58,9 @@ public:
rule("(?i:AND)", TK_AND);
rule("(?i:OR)", TK_OR);
// functions
rule("(?i:COUNT)", TK_COUNT);
// string literal TODO single quote escape
rule("'(.*?)'", TK_STR);

View File

@@ -154,6 +154,10 @@ public:
accept(rem.right);
}
void visit(ast::CountFunction& count) override
{
}
void visit(ast::PropertyList& prop_list) override
{
accept(prop_list.value);