Skip to content

Commit

Permalink
new parser: added support to traverse strategy and parallel, fixed so…
Browse files Browse the repository at this point in the history
…me test cases (old unsupported stuff)
  • Loading branch information
luigidellaquila committed Jan 26, 2015
1 parent 7bc203a commit 3fdfaed
Show file tree
Hide file tree
Showing 14 changed files with 3,103 additions and 3,000 deletions.
26 changes: 21 additions & 5 deletions core/src/main/grammar/OrientSQL.jjt
Expand Up @@ -161,6 +161,14 @@ TOKEN:
< NOCACHE: ( "n" | "N" ) ( "o" | "O" ) ( "c" | "C" ) ( "a" | "A" ) ( "c" | "C" ) ( "h" | "H" ) ( "e" | "E" ) >
|
< UNSAFE: ( "u" | "U" ) ( "n" | "N" ) ( "s" | "S" ) ( "a" | "A" ) ( "f" | "F" ) ( "e" | "E" ) >
|
< PARALLEL: ( "p" | "P" ) ( "a" | "A" ) ( "r" | "R" ) ( "a" | "A" ) ( "l" | "L" ) ( "l" | "L" ) ( "e" | "E" ) ( "l" | "L" ) >
|
< STRATEGY: ( "s" | "S" ) ( "t" | "T" ) ( "r" | "R" ) ( "a" | "A" ) ( "t" | "T" ) ( "e" | "E" ) ( "g" | "G" ) ( "y" | "Y" ) >
|
< DEPTH_FIRST: ( "d" | "d" ) ( "e" | "E" ) ( "p" | "P" ) ( "t" | "T" ) ( "h" | "H" ) "_" ( "f" | "F" ) ( "i" | "I" ) ( "r" | "R" ) ( "s" | "S" ) ( "t" | "T" ) >
|
< BREADTH_FIRST: ( "b" | "B" ) ( "r" | "R" ) ( "e" | "E" ) ( "a" | "A" ) ( "d" | "D" ) ( "t" | "T" ) ( "h" | "H" ) "_" ( "f" | "F" ) ( "i" | "I" ) ( "r" | "R" ) ( "s" | "S" ) ( "t" | "T" ) >
|
< THIS: "@this" >
|
Expand Down Expand Up @@ -512,12 +520,15 @@ OSelectWithoutTargetStatement SelectWithoutTargetStatement():
{
(
<SELECT>
ValueItem() [<AS> Alias() ]
Expression() [<AS> Alias() ]
(
<COMMA> ValueItem() [<AS> Alias() ]
<COMMA> Expression() [<AS> Alias() ]
)*
[ jjtThis.letClause = LetClause() ]
[ FetchPlan() ] [ <NOCACHE> ]
[ FetchPlan() ]
[ Timeout() ]
[ <PARALLEL> ]
[ <NOCACHE> ]
) { return jjtThis; }
}

Expand All @@ -531,8 +542,8 @@ OSelectStatement SelectStatement():
jjtThis.target = FromClause()
[ jjtThis.letClause = LetClause() ]
[ <WHERE> jjtThis.whereClause = WhereClause() ]
[ jjtThis.orderBy = OrderBy() ]
[ jjtThis.groupBy = GroupBy() ]
[ jjtThis.orderBy = OrderBy() ]
(
[
jjtThis.skip = Skip() [ jjtThis.limit = Limit() ]
Expand All @@ -541,7 +552,9 @@ OSelectStatement SelectStatement():
]
)
[ jjtThis.fetchPlan = FetchPlan() ]
[ <LOCK> <RECORD> {jjtThis.lockRecord = true;} ]
[ Timeout() ]
[ <LOCK> <RECORD> {jjtThis.lockRecord = true;} ]
[ <PARALLEL> ]
[ <NOCACHE> ]
) {return jjtThis;}
}
Expand All @@ -556,6 +569,7 @@ OTraverseStatement TraverseStatement():
FromClause()
[ <WHILE> WhereClause() ]
[ Limit() ]
[ <STRATEGY> ( <DEPTH_FIRST> | <BREADTH_FIRST> ) ]
) {return jjtThis;}
}

Expand Down Expand Up @@ -709,6 +723,7 @@ OInsertStatement InsertStatement():
|
IndexIdentifier()
)
[ <RETURN> Projection() ]
InsertBody()
[ <UNSAFE> ]
) {return jjtThis;}
Expand All @@ -724,6 +739,7 @@ void InsertBody():
<LPAREN> Identifier() (<COMMA> Identifier())* <RPAREN>
<VALUES>
<LPAREN> Expression() (<COMMA> Expression())* <RPAREN>
( <COMMA> <LPAREN> Expression() (<COMMA> Expression())* <RPAREN> )*
)
|
LOOKAHEAD(3)
Expand Down
@@ -1,77 +1,77 @@
/*
*
* * Copyright 2014 Orient Technologies LTD (info(at)orientechnologies.com)
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *
* * For more information: http://www.orientechnologies.com
*
*/
*
* * Copyright 2014 Orient Technologies LTD (info(at)orientechnologies.com)
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *
* * For more information: http://www.orientechnologies.com
*
*/
package com.orientechnologies.orient.core.exception;

import com.orientechnologies.common.exception.OException;
import com.orientechnologies.orient.core.sql.OCommandSQLParsingException;

public class OQueryParsingException extends OException {
public class OQueryParsingException extends OCommandSQLParsingException {

private String text;
private int position = -1;
private static final long serialVersionUID = -7430575036316163711L;
private String text;
private int position = -1;
private static final long serialVersionUID = -7430575036316163711L;

public OQueryParsingException(final String iMessage) {
super(iMessage);
}
public OQueryParsingException(final String iMessage) {
super(iMessage);
}

public OQueryParsingException(final String iMessage, final Throwable cause) {
super(iMessage, cause);
}
public OQueryParsingException(final String iMessage, final Throwable cause) {
super(iMessage, cause);
}

public OQueryParsingException(final String iMessage, final String iText, final int iPosition, final Throwable cause) {
super(iMessage, cause);
text = iText;
position = iPosition;
}
public OQueryParsingException(final String iMessage, final String iText, final int iPosition, final Throwable cause) {
super(iMessage, cause);
text = iText;
position = iPosition;
}

public OQueryParsingException(final String iMessage, final String iText, final int iPosition) {
super(iMessage);
text = iText;
position = iPosition;
}
public OQueryParsingException(final String iMessage, final String iText, final int iPosition) {
super(iMessage);
text = iText;
position = iPosition;
}

@Override
public String getMessage() {
StringBuilder buffer = new StringBuilder();
if (position > -1) {
buffer.append("Error on parsing query at position #");
buffer.append(position);
buffer.append(": ");
}
@Override
public String getMessage() {
StringBuilder buffer = new StringBuilder();
if (position > -1) {
buffer.append("Error on parsing query at position #");
buffer.append(position);
buffer.append(": ");
}

buffer.append(super.getMessage());
buffer.append(super.getMessage());

if (text != null) {
buffer.append("\nQuery: ");
buffer.append(text);
buffer.append("\n------");
for (int i = 0; i < position - 1; ++i)
buffer.append("-");
if (text != null) {
buffer.append("\nQuery: ");
buffer.append(text);
buffer.append("\n------");
for (int i = 0; i < position - 1; ++i)
buffer.append("-");

buffer.append("^");
}
return buffer.toString();
}
buffer.append("^");
}
return buffer.toString();
}

public String getText() {
return text;
}
public String getText() {
return text;
}

}
@@ -1,63 +1,67 @@
/*
*
* * Copyright 2014 Orient Technologies LTD (info(at)orientechnologies.com)
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *
* * For more information: http://www.orientechnologies.com
*
*/
*
* * Copyright 2014 Orient Technologies LTD (info(at)orientechnologies.com)
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *
* * For more information: http://www.orientechnologies.com
*
*/
package com.orientechnologies.orient.core.sql;

import com.orientechnologies.common.exception.OException;

public class OCommandSQLParsingException extends OException {

private String text;
private int position;
private static final long serialVersionUID = -7430575036316163711L;

public OCommandSQLParsingException(String iMessage) {
super(iMessage, null);
}

public OCommandSQLParsingException(String iMessage, String iText, int iPosition, Throwable cause) {
super(iMessage, cause);
text = iText;
position = iPosition;
}

public OCommandSQLParsingException(String iMessage, String iText, int iPosition) {
super(iMessage);
text = iText;
position = iPosition;
}

@Override
public String getMessage() {
StringBuilder buffer = new StringBuilder();
buffer.append("Error on parsing command at position #");
buffer.append(position);
buffer.append(": " + super.getMessage());
if (text != null) {
buffer.append("\nCommand: ");
buffer.append(text);
buffer.append("\n---------");
for (int i = 0; i < position - 1; ++i)
buffer.append("-");

buffer.append("^");
}
return buffer.toString();
}
private String text;
private int position;
private static final long serialVersionUID = -7430575036316163711L;

public OCommandSQLParsingException(String iMessage) {
super(iMessage, null);
}

public OCommandSQLParsingException(String iMessage, String iText, int iPosition, Throwable cause) {
super(iMessage, cause);
text = iText;
position = iPosition;
}

public OCommandSQLParsingException(final String iMessage, final Throwable cause) {
super(iMessage, cause);
}

public OCommandSQLParsingException(String iMessage, String iText, int iPosition) {
super(iMessage);
text = iText;
position = iPosition;
}

@Override
public String getMessage() {
StringBuilder buffer = new StringBuilder();
buffer.append("Error on parsing command at position #");
buffer.append(position);
buffer.append(": " + super.getMessage());
if (text != null) {
buffer.append("\nCommand: ");
buffer.append(text);
buffer.append("\n---------");
for (int i = 0; i < position - 1; ++i)
buffer.append("-");

buffer.append("^");
}
return buffer.toString();
}
}

0 comments on commit 3fdfaed

Please sign in to comment.