Skip to content

Commit

Permalink
added grammar definition for MATCH syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
luigidellaquila committed May 25, 2015
1 parent 3d09cc7 commit c31ef20
Show file tree
Hide file tree
Showing 12 changed files with 4,150 additions and 3,125 deletions.
126 changes: 126 additions & 0 deletions core/src/main/grammar/OrientSQL.jjt
Expand Up @@ -82,6 +82,8 @@ TOKEN:
|
< TRAVERSE: ( "t" | "T") ( "r" | "R") ( "a" | "A") ( "v" | "V") ( "e" | "E") ( "r" | "R") ( "s" | "S") ( "e" | "E") >
|
< MATCH: ( "m" | "M" ) ( "a" | "A" ) ( "t" | "T" ) ( "c" | "C" ) ( "h" | "H" ) >
|
< INSERT: ( "i" | "I" ) ( "n" | "N" ) ( "s" | "S" ) ( "e" | "E" ) ( "r" | "R" ) ( "t" | "T" ) >
|
< CREATE: ( "c" | "C" ) ( "r" | "R" ) ( "e" | "E" ) ( "a" | "A" ) ( "t" | "T" ) ( "e" | "E" ) >
Expand Down Expand Up @@ -186,8 +188,14 @@ TOKEN:
|
< MAXDEPTH: ( "m" | "M" ) ( "a" | "A" ) ( "x" | "X" ) ( "d" | "D" ) ( "e" | "E" ) ( "p" | "P" ) ( "t" | "T" ) ( "h" | "H" ) >
|
< MINDEPTH: ( "m" | "M" ) ( "i" | "I" ) ( "n" | "N" ) ( "d" | "D" ) ( "e" | "E" ) ( "p" | "P" ) ( "t" | "T" ) ( "h" | "H" ) >
|
< THIS: "@this" >
|
< CLASS: ( "c" | "C" ) ( "l" | "L" ) ( "a" | "A" ) ( "s" | "S" ) ( "s" | "S" ) >
|
< CLASSES: ( "c" | "C" ) ( "l" | "L" ) ( "a" | "A" ) ( "s" | "S" ) ( "s" | "S" ) ( "e" | "E" ) ( "s" | "S" ) >
|
< RECORD_ATTRIBUTE: <RID_ATTR> | <CLASS_ATTR> | <VERSION_ATTR> | <SIZE_ATTR> | <TYPE_ATTR> | <RAW_ATTR> >
|
< #RID_ATTR: "@" ( ( "r" | "R" ) ( "i" | "I" ) ( "d" | "D" )) >
Expand Down Expand Up @@ -466,6 +474,12 @@ OIdentifier Identifier():
|
token = <LUCENE>
|
token = <CLASS>
|
token = <CLASSES>
|
token = <MINDEPTH>
|
(
//TODO REPLACE THIS WITH <QUOTED_IDENTIFIER>
<BACKTICK>
Expand Down Expand Up @@ -618,6 +632,8 @@ OStatement Statement():
result = CreateEdgeStatement()
|
result = UpdateStatement()
|
result = MatchStatement()

) [ <SEMICOLON> ] { return result; }
}
Expand Down Expand Up @@ -692,6 +708,27 @@ OTraverseStatement TraverseStatement():
{return jjtThis;}
}

OMatchStatement MatchStatement():
{
OMatchExpression lastMatchExpr = null;
OIdentifier lastReturn = null;
}
{
(
<MATCH>
lastMatchExpr = MatchExpression() { jjtThis.matchExpressions.add(lastMatchExpr); }
(
<COMMA>
lastMatchExpr = MatchExpression() { jjtThis.matchExpressions.add(lastMatchExpr); }
)*
<RETURN>
lastReturn = Identifier() { jjtThis.returnItems.add(lastReturn); }
(
<COMMA>
lastReturn = Identifier() { jjtThis.returnItems.add(lastReturn); }
)*
){ return jjtThis; }
}

ODeleteStatement DeleteStatement():
{}
Expand Down Expand Up @@ -2689,4 +2726,93 @@ OJson Json():



OMatchExpression MatchExpression():
{ OMatchPathItem nextItem = null; }
{
(
jjtThis.origin = MatchFilter()
(
(
nextItem = MatchPathItem()
|
nextItem = MultiMatchPathItem()
)
{ jjtThis.items.add(nextItem); }
)*
) { return jjtThis; }
}


OMatchPathItem MatchPathItem():
{}
{
(
jjtThis.method = MethodCall()
[ jjtThis.filter = MatchFilter() ]
){ return jjtThis; }
}

OMatchPathItem MultiMatchPathItem():
{ OMatchPathItem nextItem = null; }
{
(
<LPAREN>
(
nextItem = MatchPathItem() { jjtThis.items.add(nextItem); }
)*
<RPAREN>
[ jjtThis.filter = MatchFilter() ]
){ return jjtThis; }
}


OMatchFilter MatchFilter():
{ OMatchFilterItem lastItem = null; }
{
(
<LBRACE>
[
lastItem = MatchFilterItem() { jjtThis.items.add(lastItem); }
(
<COMMA>
lastItem = MatchFilterItem() { jjtThis.items.add(lastItem); }
)*
]
<RBRACE>
) { return jjtThis; }
}

OMatchFilterItem MatchFilterItem():
{}
{
(
(
<CLASS> <COLON> jjtThis.className = Expression()
)
|
(
<CLASSES> <COLON> jjtThis.classNames = Expression()
)
|
(
<AS> <COLON> jjtThis.alias = Expression()
)
|
(
<MINDEPTH> <COLON> jjtThis.minDepth = Integer()
)
|
(
<MAXDEPTH> <COLON> jjtThis.maxDepth = Integer()
)
|
(
<WHERE> <COLON> <LPAREN>
(
jjtThis.filter = WhereClause()
)
<RPAREN>
)
)
{ return jjtThis; }
}
@@ -0,0 +1,25 @@
/* Generated By:JJTree: Do not edit this line. OMatchExpression.java Version 4.3 */
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=O,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package com.orientechnologies.orient.core.sql.parser;

import java.util.ArrayList;
import java.util.List;

public class OMatchExpression extends SimpleNode {
protected OMatchFilter origin;
protected List<OMatchPathItem> items = new ArrayList<OMatchPathItem>();

public OMatchExpression(int id) {
super(id);
}

public OMatchExpression(OrientSql p, int id) {
super(p, id);
}

/** Accept the visitor. **/
public Object jjtAccept(OrientSqlVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}
/* JavaCC - OriginalChecksum=73491fb653c32baf66997290db29f370 (do not edit this line) */
@@ -0,0 +1,24 @@
/* Generated By:JJTree: Do not edit this line. OMatchFilter.java Version 4.3 */
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=O,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package com.orientechnologies.orient.core.sql.parser;

import java.util.ArrayList;
import java.util.List;

public class OMatchFilter extends SimpleNode {
protected List<OMatchFilterItem> items = new ArrayList<OMatchFilterItem>();

public OMatchFilter(int id) {
super(id);
}

public OMatchFilter(OrientSql p, int id) {
super(p, id);
}

/** Accept the visitor. **/
public Object jjtAccept(OrientSqlVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}
/* JavaCC - OriginalChecksum=6b099371c69e0d0c1c106fc96b3072de (do not edit this line) */
@@ -0,0 +1,27 @@
/* Generated By:JJTree: Do not edit this line. OMatchFilterItem.java Version 4.3 */
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=O,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package com.orientechnologies.orient.core.sql.parser;

public class OMatchFilterItem extends SimpleNode {
protected OExpression className;
protected OExpression classNames;
protected OExpression alias;
protected OWhereClause filter;
protected OArrayRangeSelector depth;
protected OInteger minDepth;
protected OInteger maxDepth;

public OMatchFilterItem(int id) {
super(id);
}

public OMatchFilterItem(OrientSql p, int id) {
super(p, id);
}

/** Accept the visitor. **/
public Object jjtAccept(OrientSqlVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}
/* JavaCC - OriginalChecksum=74bf4765509f102180cac29f2295031e (do not edit this line) */
@@ -0,0 +1,22 @@
/* Generated By:JJTree: Do not edit this line. OMatchPathItem.java Version 4.3 */
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=O,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package com.orientechnologies.orient.core.sql.parser;

public class OMatchPathItem extends SimpleNode {
protected OMethodCall method;
protected OMatchFilter filter;

public OMatchPathItem(int id) {
super(id);
}

public OMatchPathItem(OrientSql p, int id) {
super(p, id);
}

/** Accept the visitor. **/
public Object jjtAccept(OrientSqlVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}
/* JavaCC - OriginalChecksum=ffe8e0ffde583d7b21c9084eff6a8944 (do not edit this line) */
@@ -0,0 +1,25 @@
/* Generated By:JJTree: Do not edit this line. OMatchStatement.java Version 4.3 */
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=O,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package com.orientechnologies.orient.core.sql.parser;

import java.util.ArrayList;
import java.util.List;

public class OMatchStatement extends OStatement {
protected List<OMatchExpression> matchExpressions = new ArrayList<OMatchExpression>();
protected List<OIdentifier> returnItems = new ArrayList<OIdentifier>();

public OMatchStatement(int id) {
super(id);
}

public OMatchStatement(OrientSql p, int id) {
super(p, id);
}

/** Accept the visitor. **/
public Object jjtAccept(OrientSqlVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}
/* JavaCC - OriginalChecksum=6ff0afbe9d31f08b72159fcf24070c9f (do not edit this line) */
@@ -0,0 +1,24 @@
/* Generated By:JJTree: Do not edit this line. OMultiMatchPathItem.java Version 4.3 */
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=O,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package com.orientechnologies.orient.core.sql.parser;

import java.util.ArrayList;
import java.util.List;

public class OMultiMatchPathItem extends OMatchPathItem {
protected List<OMatchPathItem> items = new ArrayList<OMatchPathItem>();

public OMultiMatchPathItem(int id) {
super(id);
}

public OMultiMatchPathItem(OrientSql p, int id) {
super(p, id);
}

/** Accept the visitor. **/
public Object jjtAccept(OrientSqlVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}
/* JavaCC - OriginalChecksum=f18f107768de80b8941f166d7fafb3c0 (do not edit this line) */

0 comments on commit c31ef20

Please sign in to comment.