From 1a6676e240d4c4ec6b8ba3a182b51cb8f1b2cddd Mon Sep 17 00:00:00 2001
From: Marko Budiselic <mbudiselicbuda@gmail.com>
Date: Tue, 19 Jan 2016 23:36:00 +0100
Subject: [PATCH] some query examples are modified and try to add AS in grammar
 (not successfully one)

---
 cypher/ast/identifier.hpp                     | 5 ++++-
 cypher/cypher.y                               | 9 ++++++++-
 cypher/debug/tree_print.hpp                   | 1 +
 cypher/query/read/match/match-custom1.cypher  | 2 +-
 cypher/query/read/match/match-n-m.cypher      | 2 +-
 cypher/query/read/match/match-optional.cypher | 2 +-
 cypher/query/read/match/match-path.cypher     | 2 +-
 cypher/query/read/match/match-property.cypher | 2 +-
 cypher/query/read/match/match-where.cypher    | 2 +-
 9 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/cypher/ast/identifier.hpp b/cypher/ast/identifier.hpp
index c8dde72e3..69ba41b09 100644
--- a/cypher/ast/identifier.hpp
+++ b/cypher/ast/identifier.hpp
@@ -9,8 +9,11 @@ namespace ast
 
 struct Identifier : public AstNode<Identifier>
 {
-    Identifier(std::string name) : name(name) {}
+    Identifier(std::string name, std::string alias)
+        : name(name), alias(alias) {}
+
     std::string name;
+    std::string alias;
 };
 
 }
diff --git a/cypher/cypher.y b/cypher/cypher.y
index 4034adc1e..bbcf034ea 100644
--- a/cypher/cypher.y
+++ b/cypher/cypher.y
@@ -316,7 +316,14 @@ expr(E) ::= idn(I) DOT idn(P). {
 %type idn {ast::Identifier*}
 
 idn(I) ::= IDN(X). {
-    I = ast->create<ast::Identifier>(X->value);
+    I = ast->create<ast::Identifier>(X->value, "");
+}
+
+/*
+not the best idea TODO: how to put AS into the grammar
+*/
+idn(I) ::= IDN(X) AS IDN(A). {
+    I = ast->create<ast::Identifier>(X->value, A->value);
 }
 
 expr(E) ::= INT(V). {
diff --git a/cypher/debug/tree_print.hpp b/cypher/debug/tree_print.hpp
index 9e9620a18..ca27e4eef 100644
--- a/cypher/debug/tree_print.hpp
+++ b/cypher/debug/tree_print.hpp
@@ -116,6 +116,7 @@ public:
     {
         auto entry = printer.advance();
         entry << "Identifier '" << idn.name << "'";
+        entry << " Alias '" << idn.alias << "'";
     }
 
     void visit(ast::Return& return_clause) override
diff --git a/cypher/query/read/match/match-custom1.cypher b/cypher/query/read/match/match-custom1.cypher
index 90275b84b..3c3b95423 100644
--- a/cypher/query/read/match/match-custom1.cypher
+++ b/cypher/query/read/match/match-custom1.cypher
@@ -1 +1 @@
-MATCH (user:User { name: 'Dominik', age: 8 + 4})-[has:HAS|IS|CAN { duration: 'PERMANENT'}]->(item:Item)--(shop)
+MATCH (user:User { name: 'Dominik', age: 8 + 4})-[has:HAS|IS|CAN { duration: 'PERMANENT'}]->(item:Item)--(shop) RETURN shop
diff --git a/cypher/query/read/match/match-n-m.cypher b/cypher/query/read/match/match-n-m.cypher
index b789f4b13..c6e4c04a1 100644
--- a/cypher/query/read/match/match-n-m.cypher
+++ b/cypher/query/read/match/match-n-m.cypher
@@ -1 +1 @@
-MATCH (n)-->(m)
+MATCH (n)-->(m) RETURN n
diff --git a/cypher/query/read/match/match-optional.cypher b/cypher/query/read/match/match-optional.cypher
index acf18260a..ff234d7c1 100644
--- a/cypher/query/read/match/match-optional.cypher
+++ b/cypher/query/read/match/match-optional.cypher
@@ -1 +1 @@
-OPTIONAL MATCH (n)-[r]->(m)
+OPTIONAL MATCH (n)-[r]->(m) RETURN n
diff --git a/cypher/query/read/match/match-path.cypher b/cypher/query/read/match/match-path.cypher
index f7daa6166..927100aa0 100644
--- a/cypher/query/read/match/match-path.cypher
+++ b/cypher/query/read/match/match-path.cypher
@@ -1 +1 @@
-MATCH p = (n)-->(m)
+MATCH p = (n:Person)-->(m:Dog {name: 'Bos'}) RETURN p
diff --git a/cypher/query/read/match/match-property.cypher b/cypher/query/read/match/match-property.cypher
index 72a617c34..bd81b2cdc 100644
--- a/cypher/query/read/match/match-property.cypher
+++ b/cypher/query/read/match/match-property.cypher
@@ -1 +1 @@
-MATCH (n {name:'Alice'})-->(m)
+MATCH (n {name:'Alice'})-->(m) RETURN m
diff --git a/cypher/query/read/match/match-where.cypher b/cypher/query/read/match/match-where.cypher
index 5014ff2c1..c3450d221 100644
--- a/cypher/query/read/match/match-where.cypher
+++ b/cypher/query/read/match/match-where.cypher
@@ -1 +1 @@
-MATCH (n:Person)-[:KNOWS]->(m:Person) WHERE n.name="Alice"
+MATCH (n:Person)-[:KNOWS]->(m:Person) WHERE n.name="Alice" RETURN m