Permalink
Browse files

All strings are now found in a single file

  • Loading branch information...
1 parent efc1d08 commit a2fc9962de46fd92b8006da006e434ee4b4f29fe @systay committed Jun 6, 2012
@@ -77,7 +77,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) ~ withClause ~ opt(start) ~ updates ~ body ^^ {
case matching ~ where ~ returns ~ start ~ updates ~ nextQ => {
val (pattern, namedPaths) = extractMatches(matching)
val startItems = start match {
@@ -21,7 +21,7 @@ package org.neo4j.cypher.internal.parser.v1_8
import org.neo4j.cypher.internal.commands._
-trait Expressions extends Base with ParserPattern with Predicates {
+trait Expressions extends Base with ParserPattern with Predicates with Strings {
def expression: Parser[Expression] = term ~ rep("+" ~ term | "-" ~ term) ^^ {
case head ~ rest =>
var result = head
@@ -47,9 +47,9 @@ trait Expressions extends Base with ParserPattern with Predicates {
}
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,15 +92,15 @@ trait Expressions extends Base with ParserPattern with Predicates {
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)
}
@@ -152,7 +152,7 @@ trait Expressions extends Base with ParserPattern with Predicates {
def aggregateFunctionNames: Parser[String] = ignoreCases("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 {
}
}
- 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)
@@ -21,8 +21,8 @@ package org.neo4j.cypher.internal.parser.v1_8
import org.neo4j.cypher.internal.commands._
-trait MatchClause extends Base with ParserPattern {
- def matching: Parser[(Match, NamedPaths)] = ignoreCase("match") ~> usePattern(matchTranslator) ^^ {
+trait MatchClause extends Base with ParserPattern with Strings {
+ def matching: Parser[(Match, NamedPaths)] = 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])
@@ -22,21 +22,17 @@ package org.neo4j.cypher.internal.parser.v1_8
import org.neo4j.cypher.internal.commands.{Sort, 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) ^^ {
+trait OrderByClause extends Base with Expressions with Strings {
+ def ascOrDesc:Parser[Boolean] = opt(ASCENDING | DESCENDING) ^^ {
case None => true
case Some(txt) => txt.toLowerCase.startsWith("a")
}
def sortItem :Parser[SortItem] = expression ~ ascOrDesc ^^ { case expression ~ reverse => SortItem(expression, reverse) }
def order: Parser[Sort] =
- (ignoreCase("order by") ~> commaList(sortItem) ^^ { case items => Sort(items:_*) }
- | ignoreCase("order") ~> failure("expected by"))
+ (ORDER ~> BY ~> commaList(sortItem) ^^ { case items => Sort(items:_*) }
+ | ORDER ~> failure("expected by"))
}
@@ -22,7 +22,7 @@ package org.neo4j.cypher.internal.parser.v1_8
import org.neo4j.graphdb.Direction
import org.neo4j.cypher.internal.commands.{True, Entity, Expression}
-trait ParserPattern extends Base {
+trait ParserPattern extends Base with Strings {
def usePattern[T](translator: AbstractPattern => Maybe[T], acceptable: Seq[T] => Boolean): Parser[Seq[T]] = Parser {
case in =>
@@ -129,7 +129,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]] = (SHORTEST_PATH | ALL_SHORTEST_PATHS) ~ parens(patternForShortestPath) ^^ {
case algo ~ relInfo =>
val single = algo match {
case "shortestpath" => true
@@ -22,21 +22,21 @@ package org.neo4j.cypher.internal.parser.v1_8
import org.neo4j.cypher.internal.commands._
-trait Predicates extends Base with ParserPattern {
- def predicate: Parser[Predicate] = predicateLvl1 ~ rep( ignoreCase("or") ~> predicateLvl1 ) ^^ {
+trait Predicates extends Base with ParserPattern with Strings {
+ 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 ~ ignoreCase("null") ^^ (x => IsNull(x))
+ | expressionOrEntity <~ IS <~ NOT <~ ignoreCase("null") ^^ (x => Not(IsNull(x)))
| operators
- | ignoreCase("not") ~> predicate ^^ ( inner => Not(inner) )
- | ignoreCase("has") ~> parens(property) ^^ ( prop => Has(prop.asInstanceOf[Property]))
+ | NOT ~> predicate ^^ ( inner => Not(inner) )
+ | HAS ~> parens(property) ^^ ( prop => Has(prop.asInstanceOf[Property]))
| parens(predicate)
| sequencePredicate
| patternPredicate
@@ -46,20 +46,20 @@ trait Predicates extends Base with ParserPattern {
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 ~ iterable ~ where ~ klas => (iterable, symbol, klas) }
- |identity ~> ignoreCase("in") ~ expression ~> failure("expected where"))
+ (identity ~ IN ~ expression ~ WHERE ~ predicate ^^ { case symbol ~ in ~ iterable ~ where ~ klas => (iterable, 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 => AnyInIterable(collection, "-_-INNER-_-", Equals(checkee, Entity("-_-INNER-_-")))
}
- def allInSeq: Parser[Predicate] = ignoreCase("all") ~> parens(symbolIterablePredicate) ^^ (x => AllInIterable(x._1, x._2, x._3))
+ def allInSeq: Parser[Predicate] = ALL ~> parens(symbolIterablePredicate) ^^ (x => AllInIterable(x._1, x._2, x._3))
- def anyInSeq: Parser[Predicate] = ignoreCase("any") ~> parens(symbolIterablePredicate) ^^ (x => AnyInIterable(x._1, x._2, x._3))
+ def anyInSeq: Parser[Predicate] = ANY ~> parens(symbolIterablePredicate) ^^ (x => AnyInIterable(x._1, x._2, x._3))
- def noneInSeq: Parser[Predicate] = ignoreCase("none") ~> parens(symbolIterablePredicate) ^^ (x => NoneInIterable(x._1, x._2, x._3))
+ def noneInSeq: Parser[Predicate] = NONE ~> parens(symbolIterablePredicate) ^^ (x => NoneInIterable(x._1, x._2, x._3))
- def singleInSeq: Parser[Predicate] = ignoreCase("single") ~> parens(symbolIterablePredicate) ^^ (x => SingleInIterable(x._1, x._2, x._3))
+ def singleInSeq: Parser[Predicate] = SINGLE ~> parens(symbolIterablePredicate) ^^ (x => SingleInIterable(x._1, x._2, x._3))
def operators:Parser[Predicate] =
(expression ~ "=" ~ expression ^^ { case l ~ "=" ~ r => nullable(Equals(l, r),l,r) } |
@@ -23,7 +23,7 @@ import org.neo4j.cypher.internal.commands._
import org.neo4j.cypher.SyntaxException
-trait ReturnClause extends Base with Expressions {
+trait ReturnClause extends Base with Expressions with Strings {
def column : Parser[ReturnColumn] = returnItem ~ alias ^^ {
case col ~ Some(newName) => col.rename(newName)
case col ~ None => col
@@ -35,14 +35,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[Aggregation])] = ignoreCase("return") ~> columnList
+ def returnsClause: Parser[(Return, Option[Aggregation])] = RETURN ~> columnList
- def alias: Parser[Option[String]] = opt(ignoreCase("as") ~> identity)
+ def alias: Parser[Option[String]] = opt(AS ~> identity)
- def columnList:Parser[(Return, Option[Aggregation])] = opt(ignoreCase("distinct")) ~ commaList(column) ^^ {
+ def columnList:Parser[(Return, Option[Aggregation])] = opt(DISTINCT) ~ commaList(column) ^^ {
case distinct ~ returnItems => {
val columnName = returnItems.map(_.name).toList
@@ -64,9 +64,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[Aggregation])] = withSyntax ^^ (columns => {
+ def withClause: Parser[(Return, Option[Aggregation])] = withSyntax ^^ (columns => {
val problemColumns = columns._1.returnItems.flatMap {
case ReturnItem(_, _, true) => None
@@ -21,10 +21,10 @@ package org.neo4j.cypher.internal.parser.v1_8
import org.neo4j.cypher.internal.commands.{Literal, Expression}
-trait SkipLimitClause extends Base {
- def skip: Parser[Expression] = ignoreCase("skip") ~> numberOrParam ^^ (x => x)
+trait SkipLimitClause extends Base with Strings {
+ 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))
@@ -23,12 +23,12 @@ import org.neo4j.cypher.internal.commands._
import org.neo4j.graphdb.Direction
-trait StartClause extends Base with Expressions {
+trait StartClause extends Base with Expressions with Strings {
def start: Parser[Start] = createStart | readStart
- def readStart :Parser[Start] = ignoreCase("start") ~> commaList(startBit) ^^ (x => Start(x: _*)) | failure("expected START or CREATE")
+ def readStart :Parser[Start] = START ~> commaList(startBit) ^^ (x => Start(x: _*)) | failure("expected START or CREATE")
- def createStart = ignoreCase("create") ~> commaList(usePattern(translate)) ^^ (x => Start(x.flatten: _*))
+ def createStart = CREATE ~> commaList(usePattern(translate)) ^^ (x => Start(x.flatten: _*))
private def translate(abstractPattern: AbstractPattern): Maybe[StartItem] = abstractPattern match {
@@ -55,24 +55,23 @@ trait StartClause extends Base with Expressions {
| 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 rels = (RELATIONSHIP | REL) ^^^ "rel"
- def typ = nodes | rels | failure("expected either node or relationship here")
+ def typ = NODE | rels | 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)) |
+ 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)) |
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 *") |
+ NODE ~> opt("(") ~> failure("expected node id, or *") |
rels ~> opt("(") ~> failure("expected relationship id, or *")
@@ -119,14 +118,6 @@ trait StartClause extends Base with Expressions {
| "=" ~> failure("Need index key"))
def id: Parser[Expression] = identity ^^ (x => Literal(x))
-
- def andQuery: Parser[String] = idxQuery ~ ignoreCase("and") ~ idxQueries ^^ {
- case q ~ and ~ qs => q + " AND " + qs
- }
-
- def orQuery: Parser[String] = idxQuery ~ ignoreCase("or") ~ idxQueries ^^ {
- case q ~ or ~ qs => q + " OR " + qs
- }
}
@@ -0,0 +1,85 @@
+/**
+ * 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_8
+
+trait Strings extends Base {
+ //KEYWORDS
+ def WHERE = ignoreCase("where")
+ def FOREACH = ignoreCase("foreach")
+ def IN = ignoreCase("in")
+ def DELETE = ignoreCase("delete")
+ def SET = ignoreCase("set")
+ def RELATE = ignoreCase("relate")
+ def START = ignoreCase("start")
+ def NODE = ignoreCase("node")
+ def RELATIONSHIP = ignoreCase("relationship")
+ def REL = ignoreCase("rel")
+ def CREATE = ignoreCase("create")
+ def RETURN = ignoreCase("return")
+ def AS = ignoreCase("as")
+ def DISTINCT = ignoreCase("distinct")
+ def WITH = ignoreCase("with")
+ def SKIP = ignoreCase("skip")
+ def LIMIT = ignoreCase("limit")
+ def AND = ignoreCase("and")
+ def OR = ignoreCase("or")
+ def NOT = ignoreCase("not")
+ def IS = ignoreCase("IS")
+ def ORDER = ignoreCase("order")
+ def BY = ignoreCase("by")
+ def DESCENDING = ignoreCases("descending", "desc")
+ def ASCENDING = ignoreCases("ascending", "asc")
+ def MATCH = ignoreCase("match")
+ def TRUE = ignoreCase("true")
+ def FALSE = ignoreCase("false")
+ def NULL = ignoreCase("null")
+
+ //FUNCTIONS
+ def HAS = ignoreCase("has")
+ def ALL = ignoreCase("all")
+ def ANY = ignoreCase("any")
+ def NONE = ignoreCase("none")
+ def SINGLE = ignoreCase("single")
+ def SHORTEST_PATH = ignoreCase("shortestpath")
+ def ALL_SHORTEST_PATHS = ignoreCase("allShortestPaths")
+ def EXTRACT = ignoreCase("extract")
+ def COALESCE = ignoreCase("coalesce")
+ def FILTER = ignoreCase("filter")
+
+ def TYPE = ignoreCase("type")
+ def ID = ignoreCase("id")
+ def LENGTH = ignoreCase("length")
+ def NODES = ignoreCase("nodes")
+ def RELS = ignoreCase("rels")
+ def RELATIONSHIPS = ignoreCase("relationships")
+ def ABS = ignoreCase("abs")
+ def ROUND = ignoreCase("round")
+ def SQRT = ignoreCase("sqrt")
+ def SIGN = ignoreCase("sign")
+ def HEAD = ignoreCase("head")
+ def LAST = ignoreCase("last")
+ def TAIL = ignoreCase("tail")
+ def COUNT = ignoreCase("count")
+ def SUM = ignoreCase("sum")
+ def MIN = ignoreCase("min")
+ def MAX = ignoreCase("max")
+ def AVG = ignoreCase("avg")
+ def COLLECT = ignoreCase("collect")
+}
Oops, something went wrong.

0 comments on commit a2fc996

Please sign in to comment.