Skip to content
Browse files

Consolidated all the usages of strings into a single file, which make…

…s it much easier to see what the current keywords are
  • Loading branch information...
1 parent 07f0f47 commit 2481c7dd4afa772edf9426defc672797239407a8 @systay committed
Showing with 193 additions and 123 deletions.
  1. +1 −0 cypher/CHANGES.txt
  2. +3 −13 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/Base.scala
  3. +1 −1 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/CreateUnique.scala
  4. +1 −1 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/CypherParserImpl.scala
  5. +10 −10 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/Expressions.scala
  6. +93 −0 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/Keywords.scala
  7. +1 −1 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/MatchClause.scala
  8. +3 −6 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/OrderByClause.scala
  9. +1 −1 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/ParserPattern.scala
  10. +14 −14 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/Predicates.scala
  11. +6 −6 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/ReturnClause.scala
  12. +2 −2 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/SkipLimitClause.scala
  13. +17 −21 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/StartClause.scala
  14. +3 −3 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/Updates.scala
  15. +1 −1 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/WhereClause.scala
  16. +2 −2 cypher/src/test/java/org/neo4j/cypher/javacompat/JavaExecutionEngineTests.java
  17. +23 −23 cypher/src/test/scala/org/neo4j/cypher/CypherParserTest.scala
  18. +0 −7 cypher/src/test/scala/org/neo4j/cypher/ErrorMessagesTest.scala
  19. +4 −4 cypher/src/test/scala/org/neo4j/cypher/ExecutionEngineTest.scala
  20. +4 −4 cypher/src/test/scala/org/neo4j/cypher/MutatingIntegrationTests.scala
  21. +2 −2 cypher/src/test/scala/org/neo4j/cypher/SemanticErrorTest.scala
  22. +1 −1 cypher/src/test/scala/org/neo4j/cypher/docgen/CreateTest.scala
View
1 cypher/CHANGES.txt
@@ -3,6 +3,7 @@
o Predicates can now be returned and used to set properties
o Fixes #797: CREATE UNIQUE now makes sure used identifiers have the same properties even if
they are re-used without the properties
+o Extracted keywords into a single code file, to keep the list of keywords always up to date
1.8
--------------------
View
16 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/Base.scala
@@ -23,12 +23,9 @@ import scala.util.parsing.combinator._
import org.neo4j.helpers.ThisShouldNotHappenError
import org.neo4j.cypher.internal.commands.expressions.{ParameterExpression, Expression, Literal}
-abstract class Base extends JavaTokenParsers {
+abstract class Base extends JavaTokenParsers with Keywords {
var namer = new NodeNamer
- val keywords = List("start", "create", "set", "delete", "foreach", "match", "where",
- "with", "return", "skip", "limit", "order", "by", "asc", "ascending", "desc", "descending")
- def ignoreCase(str: String): Parser[String] = ("""(?i)\b""" + str + """\b""").r ^^ (x => x.toLowerCase)
def onlyOne[T](msg: String, inner: Parser[List[T]]): Parser[T] = Parser {
in => inner.apply(in) match {
@@ -42,13 +39,6 @@ abstract class Base extends JavaTokenParsers {
def reduce[A,B](in:Seq[(Seq[A], Seq[B])]):(Seq[A], Seq[B]) = if (in.isEmpty) (Seq(),Seq()) else in.reduce((a, b) => (a._1 ++ b._1, a._2 ++ b._2))
- def ignoreCases(strings: String*): Parser[String] = ignoreCases(strings.toList)
-
- def ignoreCases(strings: List[String]): Parser[String] = strings match {
- case List(x) => ignoreCase(x)
- case first :: rest => ignoreCase(first) | ignoreCases(rest)
- case _ => throw new ThisShouldNotHappenError("Andres", "Something went wrong if we get here.")
- }
def commaList[T](inner: Parser[T]): Parser[List[T]] =
rep1sep(inner, ",") |
@@ -67,8 +57,8 @@ abstract class Base extends JavaTokenParsers {
}
def nonKeywordIdentifier: Parser[String] =
- not(ignoreCases(keywords: _*)) ~> ident |
- ignoreCases(keywords: _*) ~> failure("reserved keyword")
+ not(keywords) ~> ident |
+ keywords ~> failure("reserved keyword")
def lowerCaseIdent = ident ^^ (c => c.toLowerCase)
View
2 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/CreateUnique.scala
@@ -31,7 +31,7 @@ import org.neo4j.cypher.internal.commands.True
trait CreateUnique extends Base with ParserPattern {
case class PathAndRelateLink(path:Option[NamedPath], links:Seq[UniqueLink])
- def relate: Parser[(Seq[StartItem], Seq[NamedPath])] = ignoreCase("create unique") ~> usePattern(translate) ^^ (patterns => {
+ def relate: Parser[(Seq[StartItem], Seq[NamedPath])] = CREATE ~> UNIQUE ~> usePattern(translate) ^^ (patterns => {
val (links, path)= reduce(patterns.map {
case PathAndRelateLink(p, l) => (l, p.toSeq)
})
View
2 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/CypherParserImpl.scala
@@ -79,7 +79,7 @@ Thank you, the Neo4j Team.
}
}
- def bodyWith: Parser[Body] = opt(matching) ~ opt(where) ~ WITH ~ opt(start) ~ updates ~ body ^^ {
+ def bodyWith: Parser[Body] = opt(matching) ~ opt(where) ~ with_clause ~ opt(start) ~ updates ~ body ^^ {
case matching ~ where ~ returns ~ start ~ updates ~ nextQ => {
val (pattern, matchPaths) = extractMatches(matching)
val startItems = start.toSeq.flatMap(_._1)
View
20 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/Expressions.scala
@@ -48,9 +48,9 @@ trait Expressions extends Base with ParserPattern with Predicates with StringLit
}
def factor: Parser[Expression] =
- (ignoreCase("true") ^^^ Literal(true)
- | ignoreCase("false") ^^^ Literal(false)
- | ignoreCase("null") ^^^ Literal(null)
+ (TRUE ^^^ Literal(true)
+ | FALSE ^^^ Literal(false)
+ | NULL ^^^ Literal(null)
| pathExpression
| extract
| function
@@ -92,21 +92,21 @@ trait Expressions extends Base with ParserPattern with Predicates with StringLit
property <~ "?" ^^ (p => new Nullable(p) with DefaultTrue) |
property <~ "!" ^^ (p => new Nullable(p) with DefaultFalse))
- def extract: Parser[Expression] = ignoreCase("extract") ~> parens(identity ~ ignoreCase("in") ~ expression ~ ":" ~ expression) ^^ {
+ def extract: Parser[Expression] = EXTRACT ~> parens(identity ~ IN ~ expression ~ ":" ~ expression) ^^ {
case (id ~ in ~ iter ~ ":" ~ expression) => ExtractFunction(iter, id, expression)
}
- def coalesceFunc: Parser[Expression] = ignoreCase("coalesce") ~> parens(commaList(expression)) ^^ {
+ def coalesceFunc: Parser[Expression] = COALESCE ~> parens(commaList(expression)) ^^ {
case expressions => CoalesceFunction(expressions: _*)
}
- def filterFunc: Parser[Expression] = ignoreCase("filter") ~> parens(identity ~ ignoreCase("in") ~ expression ~ (ignoreCase("where") | ":") ~ predicate) ^^ {
+ def filterFunc: Parser[Expression] = FILTER ~> parens(identity ~ IN ~ expression ~ (WHERE | ":") ~ predicate) ^^ {
case symbol ~ in ~ collection ~ where ~ pred => FilterFunction(collection, symbol, pred)
}
def function: Parser[Expression] = Parser {
case in => {
- val inner = identity ~ parens(commaList(expression | entity))
+ val inner = identity ~ parens(commaList(expression))
inner(in) match {
@@ -150,9 +150,9 @@ trait Expressions extends Base with ParserPattern with Predicates with StringLit
def aggregateExpression: Parser[Expression] = countStar | aggregationFunction
- def aggregateFunctionNames: Parser[String] = ignoreCases("count", "sum", "min", "max", "avg", "collect")
+ def aggregateFunctionNames: Parser[String] = COUNT | SUM | MIN | MAX | AVG | COLLECT
- def aggregationFunction: Parser[Expression] = aggregateFunctionNames ~ parens(opt(ignoreCase("distinct")) ~ expression) ^^ {
+ def aggregationFunction: Parser[Expression] = aggregateFunctionNames ~ parens(opt(DISTINCT) ~ expression) ^^ {
case function ~ (distinct ~ inner) => {
val aggregateExpression = function match {
@@ -173,7 +173,7 @@ trait Expressions extends Base with ParserPattern with Predicates with StringLit
}
}
- def countStar: Parser[Expression] = ignoreCase("count") ~> parens("*") ^^^ CountStar()
+ def countStar: Parser[Expression] = COUNT ~> parens("*") ^^^ CountStar()
def pathExpression: Parser[Expression] = usePath(translate) ^^ {//(pathPattern => PathExpression(pathPattern))
case Seq(x:ShortestPath) => ShortestPathExpression(x)
View
93 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/Keywords.scala
@@ -0,0 +1,93 @@
+/**
+ * Copyright (c) 2002-2012 "Neo Technology,"
+ * Network Engine for Objects in Lund AB [http://neotechnology.com]
+ *
+ * This file is part of Neo4j.
+ *
+ * Neo4j is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.neo4j.cypher.internal.parser.v1_9
+
+import util.parsing.combinator.JavaTokenParsers
+import org.neo4j.helpers.ThisShouldNotHappenError
+
+trait Keywords extends JavaTokenParsers {
+ private def internal_keywords = List("create", "start", "node", "relationship", "rel", "and", "or", "unique", "match",
+ "descending", "desc", "ascending", "asc", "order", "by", "foreach", "in", "delete", "set", "skip", "limit", "true",
+ "false", "null", "where", "distinct", "is", "not", "return", "as", "with")
+
+ def CREATE = keyword(0)
+ def START = keyword(1)
+ def NODE = keyword(2)
+ def REL = (keyword(3) | keyword(4)) ^^^ "rel"
+ def AND = keyword(5)
+ def OR = keyword(6)
+ def UNIQUE = keyword(7)
+ def MATCH = keyword(8)
+ def DESC = keyword(9) | keyword(10)
+ def ASC = keyword(11) | keyword(12)
+ def ORDER = keyword(13)
+ def BY = keyword(14)
+ def FOREACH = keyword(15)
+ def IN = keyword(16)
+ def DELETE = keyword(17)
+ def SET = keyword(18)
+ def SKIP = keyword(19)
+ def LIMIT = keyword(20)
+ def TRUE = keyword(21)
+ def FALSE = keyword(22)
+ def NULL = keyword(23)
+ def WHERE = keyword(24)
+ def DISTINCT = keyword(25)
+ def IS = keyword(26)
+ def NOT = keyword(27)
+ def RETURN = keyword(28)
+ def AS = keyword(29)
+ def WITH = keyword(30)
+
+ private def functions = List("shortestpath", "allshortestpaths", "extract", "coalesce", "filter", "count", "all",
+ "any", "none", "single", "sum", "min", "max", "avg", "collect", "has")
+
+ def SHORTESTPATH = function(0)
+ def ALLSHORTESTPATHS = function(1)
+ def EXTRACT = function(2)
+ def COALESCE= function(3)
+ def FILTER = function(4)
+ def COUNT= function(5)
+ def ALL = function(6)
+ def ANY = function(7)
+ def NONE = function(8)
+ def SINGLE = function(9)
+ def SUM = function(10)
+ def MIN = function(11)
+ def MAX = function(12)
+ def AVG = function(13)
+ def COLLECT = function(14)
+ def HAS = function(15)
+
+
+ private def keyword(idx: Int): Parser[String] = ignoreCase(internal_keywords(idx))
+ private def function(idx: Int): Parser[String] = ignoreCase(functions(idx))
+
+ def keywords:Parser[String] = ignoreCases(internal_keywords)
+
+ private def ignoreCases(strings: List[String]): Parser[String] = strings match {
+ case List(x) => ignoreCase(x)
+ case first :: rest => ignoreCase(first) | ignoreCases(rest)
+ case _ => throw new ThisShouldNotHappenError("Andres", "Something went wrong if we get here.")
+ }
+
+ private def ignoreCase(str: String): Parser[String] = ("""(?i)\b""" + str + """\b""").r ^^ (x => x.toLowerCase)
+
+}
View
2 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/MatchClause.scala
@@ -23,7 +23,7 @@ import org.neo4j.cypher.internal.commands._
import expressions.{Identifier, Expression}
trait MatchClause extends Base with ParserPattern {
- def matching: Parser[(Seq[Pattern], Seq[NamedPath])] = ignoreCase("match") ~> usePattern(matchTranslator) ^^ {
+ def matching: Parser[(Seq[Pattern], Seq[NamedPath])] = MATCH ~> usePattern(matchTranslator) ^^ {
case matching =>
val namedPaths = matching.filter(_.isInstanceOf[NamedPath]).map(_.asInstanceOf[NamedPath])
val unnamedPaths = matching.filter(_.isInstanceOf[List[Pattern]]).map(_.asInstanceOf[List[Pattern]]).flatten ++ matching.filter(_.isInstanceOf[Pattern]).map(_.asInstanceOf[Pattern])
View
9 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/OrderByClause.scala
@@ -23,11 +23,8 @@ import org.neo4j.cypher.internal.commands.SortItem
trait OrderByClause extends Base with Expressions {
- def desc:Parser[String] = ignoreCases("descending", "desc")
- def asc:Parser[String] = ignoreCases("ascending", "asc")
-
- def ascOrDesc:Parser[Boolean] = opt(asc | desc) ^^ {
+ def ascOrDesc:Parser[Boolean] = opt(ASC | DESC) ^^ {
case None => true
case Some(txt) => txt.toLowerCase.startsWith("a")
}
@@ -35,8 +32,8 @@ trait OrderByClause extends Base with Expressions {
def sortItem :Parser[SortItem] = expression ~ ascOrDesc ^^ { case expression ~ reverse => SortItem(expression, reverse) }
def order: Parser[Seq[SortItem]] =
- (ignoreCase("order by") ~> commaList(sortItem)
- | ignoreCase("order") ~> failure("expected by"))
+ (ORDER ~> BY ~> commaList(sortItem)
+ | ORDER ~> failure("expected by"))
}
View
2 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/ParserPattern.scala
@@ -133,7 +133,7 @@ trait ParserPattern extends Base {
private def patternForShortestPath: Parser[AbstractPattern] = onlyOne("expected single path segment", relationship)
- private def shortestPath: Parser[List[AbstractPattern]] = (ignoreCase("shortestPath") | ignoreCase("allShortestPaths")) ~ parens(patternForShortestPath) ^^ {
+ private def shortestPath: Parser[List[AbstractPattern]] = (SHORTESTPATH | ALLSHORTESTPATHS) ~ parens(patternForShortestPath) ^^ {
case algo ~ relInfo =>
val single = algo match {
case "shortestpath" => true
View
28 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/Predicates.scala
@@ -24,21 +24,21 @@ import expressions.{Property, Identifier, Nullable, Expression}
trait Predicates extends Base with ParserPattern with StringLiteral {
- def predicate: Parser[Predicate] = predicateLvl1 ~ rep( ignoreCase("or") ~> predicateLvl1 ) ^^ {
+ def predicate: Parser[Predicate] = predicateLvl1 ~ rep( OR ~> predicateLvl1 ) ^^ {
case head ~ rest => rest.foldLeft(head)((a,b) => Or(a,b))
}
- def predicateLvl1: Parser[Predicate] = predicateLvl2 ~ rep( ignoreCase("and") ~> predicateLvl2 ) ^^{
+ def predicateLvl1: Parser[Predicate] = predicateLvl2 ~ rep( AND ~> predicateLvl2 ) ^^{
case head ~ rest => rest.foldLeft(head)((a,b) => And(a,b))
}
def predicateLvl2: Parser[Predicate] = (
- expressionOrEntity <~ ignoreCase("is null") ^^ (x => IsNull(x))
- | expressionOrEntity <~ ignoreCase("is not null") ^^ (x => Not(IsNull(x)))
+ expressionOrEntity <~ IS <~ NULL ^^ (x => IsNull(x))
+ | expressionOrEntity <~ IS <~ NOT <~ NULL ^^ (x => Not(IsNull(x)))
| operators
- | ignoreCase("not") ~> parens(predicate) ^^ ( inner => Not(inner) )
- | ignoreCase("not") ~> predicate ^^ ( inner => Not(inner) )
- | ignoreCase("has") ~> parens(property) ^^ ( prop => Has(prop.asInstanceOf[Property]))
+ | NOT ~> parens(predicate) ^^ ( inner => Not(inner) )
+ | NOT ~> predicate ^^ ( inner => Not(inner) )
+ | HAS ~> parens(property) ^^ ( prop => Has(prop.asInstanceOf[Property]))
| parens(predicate)
| sequencePredicate
| patternPredicate
@@ -48,17 +48,17 @@ trait Predicates extends Base with ParserPattern with StringLiteral {
def sequencePredicate: Parser[Predicate] = allInSeq | anyInSeq | noneInSeq | singleInSeq | in
def symbolIterablePredicate: Parser[(Expression, String, Predicate)] =
- (identity ~ ignoreCase("in") ~ expression ~ ignoreCase("where") ~ predicate ^^ { case symbol ~ in ~ collection ~ where ~ klas => (collection, symbol, klas) }
- |identity ~> ignoreCase("in") ~ expression ~> failure("expected where"))
+ (identity ~ IN ~ expression ~ WHERE ~ predicate ^^ { case symbol ~ in ~ collection ~ where ~ klas => (collection, symbol, klas) }
+ |identity ~> IN ~ expression ~> failure("expected where"))
- def in: Parser[Predicate] = expression ~ ignoreCase("in") ~ expression ^^ {
+ def in: Parser[Predicate] = expression ~ IN ~ expression ^^ {
case checkee ~ in ~ collection => nullable(AnyInCollection(collection, "-_-INNER-_-", Equals(checkee, Identifier("-_-INNER-_-"))), collection)
}
- def allInSeq: Parser[Predicate] = ignoreCase("all") ~> parens(symbolIterablePredicate) ^^ (x => nullable(AllInCollection(x._1, x._2, x._3), x._1))
- def anyInSeq: Parser[Predicate] = ignoreCase("any") ~> parens(symbolIterablePredicate) ^^ (x => nullable(AnyInCollection(x._1, x._2, x._3), x._1))
- def noneInSeq: Parser[Predicate] = ignoreCase("none") ~> parens(symbolIterablePredicate) ^^ (x => nullable(NoneInCollection(x._1, x._2, x._3), x._1))
- def singleInSeq: Parser[Predicate] = ignoreCase("single") ~> parens(symbolIterablePredicate) ^^ (x => nullable(SingleInCollection(x._1, x._2, x._3), x._1))
+ def allInSeq: Parser[Predicate] = ALL ~> parens(symbolIterablePredicate) ^^ (x => nullable(AllInCollection(x._1, x._2, x._3), x._1))
+ def anyInSeq: Parser[Predicate] = ANY ~> parens(symbolIterablePredicate) ^^ (x => nullable(AnyInCollection(x._1, x._2, x._3), x._1))
+ def noneInSeq: Parser[Predicate] = NONE ~> parens(symbolIterablePredicate) ^^ (x => nullable(NoneInCollection(x._1, x._2, x._3), x._1))
+ def singleInSeq: Parser[Predicate] = SINGLE ~> parens(symbolIterablePredicate) ^^ (x => nullable(SingleInCollection(x._1, x._2, x._3), x._1))
def operators:Parser[Predicate] =
(expression ~ "=" ~ expression ^^ { case l ~ "=" ~ r => nullable(Equals(l, r),l,r) } |
View
12 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/ReturnClause.scala
@@ -36,14 +36,14 @@ trait ReturnClause extends Base with Expressions {
def returns =
(returnsClause
- | ignoreCase("return") ~> failure("return column list expected")
+ | RETURN ~> failure("return column list expected")
| failure("expected return clause"))
- def returnsClause: Parser[(Return, Option[Seq[AggregationExpression]])] = ignoreCase("return") ~> columnList
+ def returnsClause: Parser[(Return, Option[Seq[AggregationExpression]])] = RETURN ~> columnList
- def alias: Parser[Option[String]] = opt(ignoreCase("as") ~> identity)
+ def alias: Parser[Option[String]] = opt(AS ~> identity)
- def columnList:Parser[(Return, Option[Seq[AggregationExpression]])] = opt(ignoreCase("distinct")) ~ commaList(column) ^^ {
+ def columnList:Parser[(Return, Option[Seq[AggregationExpression]])] = opt(DISTINCT) ~ commaList(column) ^^ {
case distinct ~ returnItems => {
val columnName = returnItems.map(_.name).toList
@@ -65,9 +65,9 @@ trait ReturnClause extends Base with Expressions {
}
}
- def withSyntax = ignoreCase("with") ~> columnList | "===" ~> rep("=") ~> columnList <~ "===" <~ rep("=")
+ def withSyntax = WITH ~> columnList | "===" ~> rep("=") ~> columnList <~ "===" <~ rep("=")
- def WITH: Parser[(Return, Option[Seq[AggregationExpression]])] = withSyntax ^^ (columns => {
+ def with_clause: Parser[(Return, Option[Seq[AggregationExpression]])] = withSyntax ^^ (columns => {
val problemColumns = columns._1.returnItems.flatMap {
case ReturnItem(_, _, true) => None
View
4 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/SkipLimitClause.scala
@@ -22,9 +22,9 @@ package org.neo4j.cypher.internal.parser.v1_9
import org.neo4j.cypher.internal.commands.expressions.{Literal, Expression}
trait SkipLimitClause extends Base {
- def skip: Parser[Expression] = ignoreCase("skip") ~> numberOrParam ^^ (x => x)
+ def skip: Parser[Expression] = SKIP ~> numberOrParam ^^ (x => x)
- def limit: Parser[Expression] = ignoreCase("limit") ~> numberOrParam ^^ (x => x)
+ def limit: Parser[Expression] = LIMIT ~> numberOrParam ^^ (x => x)
private def numberOrParam: Parser[Expression] =
(positiveNumber ^^ (x => Literal(x.toInt))
View
38 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/StartClause.scala
@@ -27,11 +27,11 @@ import org.neo4j.graphdb.Direction
trait StartClause extends Base with Expressions with CreateUnique {
def start: Parser[(Seq[StartItem], Seq[NamedPath])] = createStart | readStart | failure("expected START or CREATE")
- def readStart: Parser[(Seq[StartItem], Seq[NamedPath])] = ignoreCase("start") ~> commaList(startBit) ^^ (x => (x, Seq()))
+ def readStart: Parser[(Seq[StartItem], Seq[NamedPath])] = START ~> commaList(startBit) ^^ (x => (x, Seq()))
def createStart: Parser[(Seq[StartItem], Seq[NamedPath])] = relate|create
- def create = ignoreCase("create") ~> commaList(usePattern(translate)) ^^ {
+ def create = CREATE ~> commaList(usePattern(translate)) ^^ {
case matching =>
val pathsAndItems = matching.flatten.filter(_.isInstanceOf[NamedPathWStartItems]).map(_.asInstanceOf[NamedPathWStartItems])
val startItems = matching.flatten.filter(_.isInstanceOf[StartItem]).map(_.asInstanceOf[StartItem])
@@ -79,25 +79,21 @@ trait StartClause extends Base with Expressions with CreateUnique {
| identity ~> "=" ~> opt("(") ~> failure("expected either node or relationship here")
| identity ~> failure("expected identifier assignment"))
- def nodes = ignoreCase("node")
-
- def rels = (ignoreCase("relationship") | ignoreCase("rel")) ^^^ "rel"
-
- def typ = nodes | rels | failure("expected either node or relationship here")
+ def typ = NODE | REL | failure("expected either node or relationship here")
def lookup: Parser[String => StartItem] =
- nodes ~> parens(parameter) ^^ (p => (column: String) => NodeById(column, p)) |
- nodes ~> ids ^^ (p => (column: String) => NodeById(column, p)) |
- nodes ~> idxLookup ^^ nodeIndexLookup |
- nodes ~> idxString ^^ nodeIndexString |
- nodes ~> parens("*") ^^ (x => (column: String) => AllNodes(column)) |
- rels ~> parens(parameter) ^^ (p => (column: String) => RelationshipById(column, p)) |
- rels ~> ids ^^ (p => (column: String) => RelationshipById(column, p)) |
- rels ~> idxLookup ^^ relationshipIndexLookup |
- rels ~> idxString ^^ relationshipIndexString |
- rels ~> parens("*") ^^ (x => (column: String) => AllRelationships(column)) |
- nodes ~> opt("(") ~> failure("expected node id, or *") |
- rels ~> opt("(") ~> failure("expected relationship id, or *")
+ NODE ~> parens(parameter) ^^ (p => (column: String) => NodeById(column, p)) |
+ NODE ~> ids ^^ (p => (column: String) => NodeById(column, p)) |
+ NODE ~> idxLookup ^^ nodeIndexLookup |
+ NODE ~> idxString ^^ nodeIndexString |
+ NODE ~> parens("*") ^^ (x => (column: String) => AllNodes(column)) |
+ REL ~> parens(parameter) ^^ (p => (column: String) => RelationshipById(column, p)) |
+ REL ~> ids ^^ (p => (column: String) => RelationshipById(column, p)) |
+ REL ~> idxLookup ^^ relationshipIndexLookup |
+ REL ~> idxString ^^ relationshipIndexString |
+ REL ~> parens("*") ^^ (x => (column: String) => AllRelationships(column)) |
+ NODE ~> opt("(") ~> failure("expected node id, or *") |
+ REL ~> opt("(") ~> failure("expected relationship id, or *")
def relationshipIndexString: ((String, Expression)) => (String) => RelationshipByIndexQuery = {
@@ -144,11 +140,11 @@ trait StartClause extends Base with Expressions with CreateUnique {
def id: Parser[Expression] = identity ^^ (x => Literal(x))
- def andQuery: Parser[String] = idxQuery ~ ignoreCase("and") ~ idxQueries ^^ {
+ def andQuery: Parser[String] = idxQuery ~ AND ~ idxQueries ^^ {
case q ~ and ~ qs => q + " AND " + qs
}
- def orQuery: Parser[String] = idxQuery ~ ignoreCase("or") ~ idxQueries ^^ {
+ def orQuery: Parser[String] = idxQuery ~ OR ~ idxQueries ^^ {
case q ~ or ~ qs => q + " OR " + qs
}
}
View
6 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/Updates.scala
@@ -27,7 +27,7 @@ import org.neo4j.cypher.SyntaxException
trait Updates extends Base with Expressions with StartClause {
def updates: Parser[(Seq[UpdateAction], Seq[NamedPath])] = rep(delete | set | foreach) ^^ (cmds => reduce(cmds))
- def foreach: Parser[(Seq[UpdateAction], Seq[NamedPath])] = ignoreCase("foreach") ~> "(" ~> identity ~ ignoreCase("in") ~ expression ~ ":" ~ opt(createStart) ~ opt(updates) <~ ")" ^^ {
+ def foreach: Parser[(Seq[UpdateAction], Seq[NamedPath])] = FOREACH ~> "(" ~> identity ~ IN ~ expression ~ ":" ~ opt(createStart) ~ opt(updates) <~ ")" ^^ {
case id ~ in ~ collection ~ ":" ~ creates ~ innerUpdates => {
val createCmds = creates.toSeq.map(_._1.map(_.asInstanceOf[UpdateAction])).flatten
val reducedItems: (Seq[UpdateAction], Seq[NamedPath]) = reduce(innerUpdates.toSeq)
@@ -38,7 +38,7 @@ trait Updates extends Base with Expressions with StartClause {
}
}
- def delete: Parser[(Seq[UpdateAction], Seq[NamedPath])] = ignoreCase("delete") ~> commaList(expression) ^^ {
+ def delete: Parser[(Seq[UpdateAction], Seq[NamedPath])] = DELETE ~> commaList(expression) ^^ {
case expressions => val updateActions: List[UpdateAction with Product] = expressions.map {
case Property(entity, property) => DeletePropertyAction(Identifier(entity), property)
case x => DeleteEntityAction(x)
@@ -46,7 +46,7 @@ trait Updates extends Base with Expressions with StartClause {
(updateActions, Seq())
}
- def set: Parser[(Seq[UpdateAction], Seq[NamedPath])] = ignoreCase("set") ~> commaList(propertySet) ^^ ((_,Seq()))
+ def set: Parser[(Seq[UpdateAction], Seq[NamedPath])] = SET ~> commaList(propertySet) ^^ ((_,Seq()))
def propertySet = property ~ "=" ~ expressionOrPredicate ^^ {
case p ~ "=" ~ e => PropertySetAction(p.asInstanceOf[Property], e)
View
2 cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/WhereClause.scala
@@ -23,7 +23,7 @@ import org.neo4j.cypher.internal.commands.Predicate
trait WhereClause extends Base with Expressions {
- def where: Parser[Predicate] = ignoreCase("where") ~> predicate
+ def where: Parser[Predicate] = WHERE ~> predicate
}
View
4 cypher/src/test/java/org/neo4j/cypher/javacompat/JavaExecutionEngineTests.java
@@ -217,8 +217,8 @@ public void exampleWithParameterForNodeObject() throws Exception
{
// START SNIPPET: exampleWithParameterForNodeObject
Map<String, Object> params = new HashMap<String, Object>();
- params.put( "node", andreasNode );
- ExecutionResult result = engine.execute( "start n=node({node}) return n.name", params );
+ params.put( "n", andreasNode );
+ ExecutionResult result = engine.execute( "start n=node({n}) return n.name", params );
// END SNIPPET: exampleWithParameterForNodeObject
assertThat( result.columns(), hasItem( "n.name" ) );
View
46 cypher/src/test/scala/org/neo4j/cypher/CypherParserTest.scala
@@ -447,11 +447,11 @@ class CypherParserTest extends JUnitSuite with Assertions {
@Test def relatedToWithRelationOutput() {
testAll(
- "start a = NODE(1) match a -[rel:KNOWS]-> (b) return rel",
+ "start a = NODE(1) match a -[r:KNOWS]-> (b) return r",
Query.
start(NodeById("a", 1)).
- matches(RelatedTo("a", "b", "rel", Seq("KNOWS"), Direction.OUTGOING, false, True())).
- returns(ReturnItem(Identifier("rel"), "rel")))
+ matches(RelatedTo("a", "b", "r", Seq("KNOWS"), Direction.OUTGOING, false, True())).
+ returns(ReturnItem(Identifier("r"), "r")))
}
@Test def relatedToWithoutEndName() {
@@ -1383,7 +1383,7 @@ class CypherParserTest extends JUnitSuite with Assertions {
@Test def start_with_two_nodes_and_create_relationship() {
val secondQ = Query.
- start(CreateRelationshipStartItem("r", (Identifier("a"), Map()), (Identifier("b"),Map()), "REL", Map())).
+ start(CreateRelationshipStartItem("r", (Identifier("a"), Map()), (Identifier("b"), Map()), "RELTYPE", Map())).
returns()
val q = Query.
@@ -1392,12 +1392,12 @@ class CypherParserTest extends JUnitSuite with Assertions {
returns(ReturnItem(Identifier("a"), "a"), ReturnItem(Identifier("b"), "b"))
- testFrom_1_8("start a=node(0), b=node(1) with a,b create a-[r:REL]->b", q)
+ testFrom_1_8("start a=node(0), b=node(1) with a,b create a-[r:RELTYPE]->b", q)
}
@Test def start_with_two_nodes_and_create_relationship_using_alternative_with_syntax() {
val secondQ = Query.
- start(CreateRelationshipStartItem("r", (Identifier("a"),Map()), (Identifier("b"),Map()), "REL", Map())).
+ start(CreateRelationshipStartItem("r", (Identifier("a"),Map()), (Identifier("b"),Map()), "RELTYPE", Map())).
returns()
val q = Query.
@@ -1409,13 +1409,13 @@ class CypherParserTest extends JUnitSuite with Assertions {
testFrom_1_8("""
start a=node(0), b=node(1)
========= a,b ============
-create a-[r:REL]->b
+create a-[r:RELTYPE]->b
""", q)
}
@Test def create_relationship_with_properties() {
val secondQ = Query.
- start(CreateRelationshipStartItem("r", (Identifier("a"),Map()), (Identifier("b"),Map()), "REL",
+ start(CreateRelationshipStartItem("r", (Identifier("a"),Map()), (Identifier("b"),Map()), "RELTYPE",
Map("why" -> Literal(42), "foo" -> Literal("bar"))
)).
returns()
@@ -1426,27 +1426,27 @@ create a-[r:REL]->b
returns(ReturnItem(Identifier("a"), "a"), ReturnItem(Identifier("b"), "b"))
- testFrom_1_8("start a=node(0), b=node(1) with a,b create a-[r:REL {why : 42, foo : 'bar'}]->b", q)
+ testFrom_1_8("start a=node(0), b=node(1) with a,b create a-[r:RELTYPE {why : 42, foo : 'bar'}]->b", q)
}
@Test def create_relationship_without_identifier() {
- testFrom_1_8("create ({a})-[:REL]->({a})",
+ testFrom_1_8("create ({a})-[:RELTYPE]->({a})",
Query.
- start(CreateRelationshipStartItem(" UNNAMED1", (ParameterExpression("a"),Map()), (ParameterExpression("a"),Map()), "REL", Map())).
+ start(CreateRelationshipStartItem(" UNNAMED1", (ParameterExpression("a"),Map()), (ParameterExpression("a"),Map()), "RELTYPE", Map())).
returns())
}
@Test def create_relationship_with_properties_from_map() {
- testFrom_1_8("create ({a})-[:REL {param}]->({a})",
+ testFrom_1_8("create ({a})-[:RELTYPE {param}]->({a})",
Query.
- start(CreateRelationshipStartItem(" UNNAMED1", (ParameterExpression("a"),Map()), (ParameterExpression("a"),Map()), "REL", Map("*" -> ParameterExpression("param")))).
+ start(CreateRelationshipStartItem(" UNNAMED1", (ParameterExpression("a"),Map()), (ParameterExpression("a"),Map()), "RELTYPE", Map("*" -> ParameterExpression("param")))).
returns())
}
@Test def create_relationship_without_identifier2() {
- testFrom_1_8("create ({a})-[:REL]->({a})",
+ testFrom_1_8("create ({a})-[:RELTYPE]->({a})",
Query.
- start(CreateRelationshipStartItem(" UNNAMED1", (ParameterExpression("a"),Map()), (ParameterExpression("a"),Map()), "REL", Map())).
+ start(CreateRelationshipStartItem(" UNNAMED1", (ParameterExpression("a"),Map()), (ParameterExpression("a"),Map()), "RELTYPE", Map())).
returns())
}
@@ -1496,11 +1496,11 @@ create a-[r:REL]->b
val q = Query.
start(NodeById("a", 0)).
- namedPaths(NamedPath("p", RelatedTo("a", "b", "r", "REL", Direction.OUTGOING))).
+ namedPaths(NamedPath("p", RelatedTo("a", "b", "r", "RELTYPE", Direction.OUTGOING))).
tail(secondQ).
returns(ReturnItem(Identifier("p"), "p"))
- testFrom_1_8("start a=node(0) match p = a-[r:REL]->b with p foreach(n in nodes(p) : set n.touched = true ) ", q)
+ testFrom_1_8("start a=node(0) match p = a-[r:RELTYPE]->b with p foreach(n in nodes(p) : set n.touched = true ) ", q)
}
@Test def simple_read_first_and_update_next() {
@@ -1519,7 +1519,7 @@ create a-[r:REL]->b
@Test def simple_start_with_two_nodes_and_create_relationship() {
val secondQ = Query.
- start(CreateRelationshipStartItem("r", (Identifier("a"), Map()), (Identifier("b"), Map()), "REL", Map())).
+ start(CreateRelationshipStartItem("r", (Identifier("a"), Map()), (Identifier("b"), Map()), "RELTYPE", Map())).
returns()
val q = Query.
@@ -1528,12 +1528,12 @@ create a-[r:REL]->b
returns(AllIdentifiers())
- testFrom_1_8("start a=node(0), b=node(1) create a-[r:REL]->b", q)
+ testFrom_1_8("start a=node(0), b=node(1) create a-[r:RELTYPE]->b", q)
}
@Test def simple_create_relationship_with_properties() {
val secondQ = Query.
- start(CreateRelationshipStartItem("r", (Identifier("b"), Map()), (Identifier("a"), Map()), "REL",
+ start(CreateRelationshipStartItem("r", (Identifier("b"), Map()), (Identifier("a"), Map()), "RELTYPE",
Map("why" -> Literal(42), "foo" -> Literal("bar"))
)).
returns()
@@ -1544,7 +1544,7 @@ create a-[r:REL]->b
returns(AllIdentifiers())
- testFrom_1_8("start a=node(0), b=node(1) create a<-[r:REL {why : 42, foo : 'bar'}]-b", q)
+ testFrom_1_8("start a=node(0), b=node(1) create a<-[r:RELTYPE {why : 42, foo : 'bar'}]-b", q)
}
@Test def simple_delete_node() {
@@ -1593,11 +1593,11 @@ create a-[r:REL]->b
val q = Query.
start(NodeById("a", 0)).
- namedPaths(NamedPath("p", RelatedTo("a", "b", "r", "REL", Direction.OUTGOING))).
+ namedPaths(NamedPath("p", RelatedTo("a", "b", "r", "RELTYPE", Direction.OUTGOING))).
tail(secondQ).
returns(AllIdentifiers())
- testFrom_1_8("start a=node(0) match p = a-[r:REL]->b foreach(n in nodes(p) : set n.touched = true ) ", q)
+ testFrom_1_8("start a=node(0) match p = a-[r:RELTYPE]->b foreach(n in nodes(p) : set n.touched = true ) ", q)
}
@Test def returnAll() {
View
7 cypher/src/test/scala/org/neo4j/cypher/ErrorMessagesTest.scala
@@ -166,13 +166,6 @@ class ErrorMessagesTest extends ExecutionEngineHelper with Assertions with Strin
15)
}
- @Test def startExpressionWithoutIdentifier() {
- expectSyntaxError(
- "start a = node:node_auto_index(name=\"magnus\"),node:node_auto_index(name=\"sebastian) return b,c",
- "expected identifier assignment",
- 50)
- }
-
@Test def functions_and_stuff_have_to_be_renamed_when_sent_through_with() {
expectError(
"START a=node(0) with a, count(*) return a",
View
8 cypher/src/test/scala/org/neo4j/cypher/ExecutionEngineTest.scala
@@ -54,9 +54,9 @@ class ExecutionEngineTest extends ExecutionEngineHelper {
}
@Test def shouldFilterOnGreaterThan() {
- val result = parseAndExecute("start node=node(0) where 0<1 return node")
+ val result = parseAndExecute("start n=node(0) where 0<1 return n")
- assertEquals(List(refNode), result.columnAs[Node]("node").toList)
+ assertEquals(List(refNode), result.columnAs[Node]("n").toList)
}
@Test def shouldFilterOnRegexp() {
@@ -1794,9 +1794,9 @@ RETURN x0.name?
@Test def listing_rel_types_multiple_times_should_not_give_multiple_returns() {
val a = createNode()
val b = createNode()
- relate(a, b, "REL")
+ relate(a, b, "RELX")
- val result = parseAndExecute("start a=node(1) match a-[:REL|REL]-b return b").toList
+ val result = parseAndExecute("start a=node(1) match a-[:RELX|RELX]-b return b").toList
assert(List(Map("b" -> b)) === result)
}
View
8 cypher/src/test/scala/org/neo4j/cypher/MutatingIntegrationTests.scala
@@ -74,7 +74,7 @@ class MutatingIntegrationTests extends ExecutionEngineHelper with Assertions wit
@Test
def create_two_nodes_and_a_relationship_between_them() {
- val result = parseAndExecute("create a, b, a-[r:REL]->b")
+ val result = parseAndExecute("create a, b, a-[r:RELX]->b")
assertStats(result, nodesCreated = 2, relationshipsCreated = 1)
}
@@ -133,7 +133,7 @@ class MutatingIntegrationTests extends ExecutionEngineHelper with Assertions wit
val b = createNode()
val c = createNode()
- val result = parseAndExecute("create n with n start x = node(1,2,3) create n-[:REL]->x")
+ val result = parseAndExecute("create n with n start x = node(1,2,3) create n-[:RELX]->x")
assertStats(result,
nodesCreated = 1,
relationshipsCreated = 3
@@ -215,7 +215,7 @@ class MutatingIntegrationTests extends ExecutionEngineHelper with Assertions wit
createNode()
createNode()
- val r = parseAndExecute("start a = node(1), b = node(2) create a-[r:REL {param}]->b return r", "param" -> Map("name" -> "Andres", "age" -> 66)).
+ val r = parseAndExecute("start a = node(1), b = node(2) create a-[r:RELX {param}]->b return r", "param" -> Map("name" -> "Andres", "age" -> 66)).
toList.head("r").asInstanceOf[Relationship]
assert(r.getProperty("name") === "Andres")
@@ -316,7 +316,7 @@ foreach(n in nodes(p) :
relate(root, b)
relate(root, c)
- parseAndExecute("start root=node(1) match root-->other create (new {name:other.name}), root-[:REL]->new")
+ parseAndExecute("start root=node(1) match root-->other create (new {name:other.name}), root-[:RELX]->new")
val result = parseAndExecute("start root=node(1) match root-->other return other.name order by other.name").columnAs[String]("other.name").toList
assert(result === List("Alfa", "Alfa", "Beta", "Beta", "Gamma", "Gamma"))
View
4 cypher/src/test/scala/org/neo4j/cypher/SemanticErrorTest.scala
@@ -29,8 +29,8 @@ class SemanticErrorTest extends ExecutionEngineHelper {
}
@Test def throwOnDisconnectedPattern() {
- expectedError("start x=node(0) match a-[rel]->b return x",
- "All parts of the pattern must either directly or indirectly be connected to at least one bound entity. These identifiers were found to be disconnected: a, b, rel")
+ expectedError("start x=node(0) match a-[FRIEND]->b return x",
+ "All parts of the pattern must either directly or indirectly be connected to at least one bound entity. These identifiers were found to be disconnected: a, b, FRIEND")
}
@Test def defineNodeAndTreatItAsARelationship() {
View
2 cypher/src/test/scala/org/neo4j/cypher/docgen/CreateTest.scala
@@ -86,7 +86,7 @@ class CreateTest extends DocumentingTestBase with StatisticsChecker {
title = "Using expressions for nodes end points",
text = "You can use any expression as a node, as long as it returns a node. Just make sure to encase your " +
"expression in parenthesis.",
- queryText = "start a=node(" + aId + ") with collect(a) as nodes start b=node(" + bId + ") create (head(nodes))-[r:REL]->b return r",
+ queryText = "start a=node(" + aId + ") with collect(a) as nodes start b=node(" + bId + ") create (head(nodes))-[r:RELX]->b return r",
returns = "The created relationship is returned.",
assertions = (p) => assert(p.size === 1)
)

0 comments on commit 2481c7d

Please sign in to comment.
Something went wrong with that request. Please try again.