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"
|
2015-11-02 01:03:15 +08:00
|
|
|
#include "utils/command_line/arguments.hpp"
|
2016-01-27 06:40:11 +08:00
|
|
|
#include "cypher/common.hpp"
|
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
|
2016-01-27 06:40:11 +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));
|
|
|
|
std::map<std::string, Traverser::sptr> traversers = {
|
2016-03-12 19:26:56 +08:00
|
|
|
{"print", print_traverser}
|
2015-10-30 08:24:01 +08:00
|
|
|
};
|
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;
|
|
|
|
}
|
|
|
|
|