2015-08-30 07:12:46 +08:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <vector>
|
|
|
|
#include <vector>
|
|
|
|
|
2015-10-19 01:44:00 +08:00
|
|
|
#include "compiler.hpp"
|
2015-10-30 08:24:01 +08:00
|
|
|
#include "debug/tree_print.hpp"
|
|
|
|
#include "codegen/cppgen.hpp"
|
2015-11-02 01:03:15 +08:00
|
|
|
#include "utils/command_line/arguments.hpp"
|
2016-01-17 01:24:35 +08:00
|
|
|
#include "utils/string/filereader.hpp"
|
2015-08-30 07:12:46 +08:00
|
|
|
|
2016-01-18 07:41:54 +08:00
|
|
|
#include "utils/terminate_handler.hpp"
|
|
|
|
|
2015-10-30 08:24:01 +08:00
|
|
|
using std::cout;
|
|
|
|
using std::endl;
|
2015-08-30 07:12:46 +08:00
|
|
|
|
2015-10-30 08:24:01 +08:00
|
|
|
// * INPUT ARGUMENTS *
|
|
|
|
// -q -> query
|
|
|
|
// -v -> visitor
|
2016-01-17 01:24:35 +08:00
|
|
|
// -f -> file
|
|
|
|
|
|
|
|
std::string extract_query(const vector_str& arguments)
|
|
|
|
{
|
|
|
|
if (contain_argument(arguments, "-q"))
|
|
|
|
return get_argument(arguments, "-q", "CREATE (n {a:1, b:2}) RETURN n");
|
|
|
|
auto default_file = "query/read/match/match-where.cypher";
|
|
|
|
auto file = get_argument(arguments, "-f", default_file);
|
|
|
|
// TODO: error handling
|
|
|
|
return read_file(file.c_str());
|
|
|
|
}
|
2015-08-30 07:12:46 +08:00
|
|
|
|
2015-10-30 08:24:01 +08:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2016-01-18 07:41:54 +08:00
|
|
|
std::set_terminate(&terminate_handler);
|
|
|
|
|
2015-10-30 08:24:01 +08:00
|
|
|
// arguments parsing
|
|
|
|
auto arguments = all_arguments(argc, argv);
|
2016-01-17 01:24:35 +08:00
|
|
|
|
|
|
|
// query extraction
|
|
|
|
auto cypher_query = extract_query(arguments);
|
2016-01-18 07:41:54 +08:00
|
|
|
cout << "QUERY: " << cypher_query << endl;
|
2015-10-30 08:24:01 +08:00
|
|
|
|
|
|
|
// traversers
|
2016-01-17 01:24:35 +08:00
|
|
|
auto traverser = get_argument(arguments, "-t", "code");
|
2015-10-30 08:24:01 +08:00
|
|
|
auto print_traverser = Traverser::sptr(new PrintVisitor(cout));
|
|
|
|
auto cppgen_traverser = Traverser::sptr(new CppGen());
|
|
|
|
std::map<std::string, Traverser::sptr> traversers = {
|
|
|
|
{"print", print_traverser},
|
|
|
|
{"code", cppgen_traverser}
|
|
|
|
};
|
2015-08-30 07:12:46 +08:00
|
|
|
|
2015-10-30 08:24:01 +08:00
|
|
|
cypher::Compiler compiler;
|
|
|
|
auto tree = compiler.syntax_tree(cypher_query);
|
2015-10-19 01:44:00 +08:00
|
|
|
|
2015-10-30 08:24:01 +08:00
|
|
|
auto t = traversers[traverser];
|
|
|
|
tree.root->accept(*t);
|
2015-08-30 07:12:46 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|