Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.bigdata.rdf.sail.sparql.ast.sparql.jj Maven / Gradle / Ivy
/*@bgen(jjtree) Generated By:JJTree: Do not edit this line. sparql.jj */
/*@egen*//**
Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved.
Contact:
SYSTAP, LLC DBA Blazegraph
2501 Calvert ST NW #106
Washington, DC 20008
[email protected]
This program 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; version 2 of the License.
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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* @author: Bryan Thompson
* @openrdf
*
* "make javacc" to rebuild. Be sure to first remove the sparql.jj file
* so it will generate a new one.
*
* Updated 6/7/14 by Mike Personick. Updated to capture the delta between the
* Sesame 2.6.10/2.7.12 sparql.jjt files.
*/
/*
* Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007.
*
* Licensed under the Aduna BSD-style license.
*/
/*
* SPARQL JJTree input file for JavaCC, a Java Compiler Compiler. JavaCC can be
* downloaded from https://javacc.dev.java.net/
*
* author: Arjohn Kampman
*/
options {
STATIC=false;
UNICODE_INPUT=true;
JAVA_UNICODE_ESCAPE=true; // pre-process unicode escapes, see section A.2 of spec
}
PARSER_BEGIN(SyntaxTreeBuilder)
package com.bigdata.rdf.sail.sparql.ast;
import java.io.StringReader;
import org.openrdf.model.URI;
import org.openrdf.model.vocabulary.RDF;
import org.openrdf.model.vocabulary.XMLSchema;
import org.openrdf.query.algebra.Compare.CompareOp;
import org.openrdf.query.algebra.MathExpr.MathOp;
import org.openrdf.rio.RDFParser.DatatypeHandling;
public class SyntaxTreeBuilder/*@bgen(jjtree)*/implements SyntaxTreeBuilderTreeConstants/*@egen*/ {/*@bgen(jjtree)*/
protected JJTSyntaxTreeBuilderState jjtree = new JJTSyntaxTreeBuilderState();
/*@egen*/
/**
* Parses the supplied SPARQL query and builds a syntax tree from it.
*
* @param query A SPARQL query string.
* @return The root of the syntax tree.
* @throws TokenMgrError If the query was syntactically incorrect.
* @throws ParseException If the query was syntactically incorrect.
*/
public static ASTQueryContainer parseQuery(final String query)
throws TokenMgrError, ParseException
{
final SyntaxTreeBuilder stb = new SyntaxTreeBuilder( new StringReader(query) );
// Set size of tab to 1 to force tokenmanager to report correct column
// index for substring splitting of service graph pattern.
stb.jj_input_stream.setTabSize(1);
final ASTQueryContainer container = stb.QueryContainer();
container.setSourceString(query);
return container;
}
/**
* Parses the supplied SPARQL update sequence and builds a syntax tree from it.
*
* @param sequence A SPARQL update sequence string.
* @return The root of the syntax tree.
* @throws TokenMgrError If the update sequence was syntactically incorrect.
* @throws ParseException If the update sequence was syntactically incorrect.
*/
public static ASTUpdateSequence parseUpdateSequence(final String sequence)
throws TokenMgrError, ParseException
{
final SyntaxTreeBuilder stb = new SyntaxTreeBuilder( new StringReader(sequence) );
final ASTUpdateSequence seq = stb.UpdateSequence();
seq.setSourceString(sequence);
return seq;
}
/**
* Trims n character from the start and end of the supplied string.
*/
private static String _trimString(String s, int n) {
if (s.length() >= 2 * n) {
s = s.substring(n, s.length() - n);
}
return s;
}
private String readToMatchingBrace() {
StringBuilder sb = new StringBuilder();
Token tok;
int nesting = 1;
boolean previousTokenDtSep = false;
while (true) {
tok = getToken(1);
if (!previousTokenDtSep && ! tok.image.equals("^^") && !tok.image.startsWith("@")) {
sb.append(" ");
}
if (tok.kind == LBRACE) nesting++;
if (tok.kind == RBRACE) {
nesting--;
if (nesting == 0) break;
}
// To provide correct line numbers (see https://jira.blazegraph.com/browse/BLZG-1397)
// we should keep line breaks and one-line comments. So, we are adding special tokens
// (comments and and new line char) per https://javacc.java.net/doc/tokenmanager.html
if (tok.specialToken != null) {
// The above statement determines that there is a special token
Token tmp_t = tok.specialToken;
while (tmp_t.specialToken != null)
tmp_t = tmp_t.specialToken;
// The above line walks back the special token chain until it
// reaches the first special token after the previous regular
// token.
while (tmp_t != null) {
sb.append(tmp_t.image);
tmp_t = tmp_t.next;
}
// The above loop now walks the special token chain in the forward
// direction printing them in the process.
}
sb.append(tok.image);
previousTokenDtSep = tok.image.equals("^^");
tok = getNextToken();
}
return sb.toString();
}
}
PARSER_END(SyntaxTreeBuilder)
//
// tokens
//
TOKEN :
{
// Whitespace characters
<#WS_CHAR: " " | "\t" | "\r" | "\f">
}
SKIP :
{
>
}
SPECIAL_TOKEN :
{
|
}
// Special characters
TOKEN :
{
|
|
|
|
|
|
|
|
|
|
| ">
|
|
| =">
|
|
|
|
|
|
|
|
|
|
|
| (|)* >
| (|)* >
}
TOKEN :
{
// Note: case-sensitive!
}
TOKEN [IGNORE_CASE] :
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
TOKEN [IGNORE_CASE] : // Bigdata extension specific tokens
{
|
|
| >
|
|
|
|
| >">
// RDFParserOptions (for LOAD)
|
|
|
|
|
|
|
// Managing Truth Maintenance
|
|
|
|
}
TOKEN [IGNORE_CASE] : // SPARQL 1.1 Update-specific tokens
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
TOKEN:
{
", "\"", "{", "}", "|", "^", "`", "\\", "\u0000"-" "])* ">">
| )? ":">
| )? ":" > // Note: PN_LOCAL not optional, case handled by PNAME_NS
| | ) ((|".")* )? >
| >
| >
| )+ ("-" (|)+)*>
| )+>
| >
| >
| |)>
| <#DECIMAL1: ()+ "." ()*>
| <#DECIMAL2: "." ()+>
| >
| >
| ||)>
| <#DOUBLE1: ()+ "." ()* >
| <#DOUBLE2: "." ()+ >
| <#DOUBLE3: ()+ >
| <#EXPONENT: ["e","E"] (["+","-"])? ()+>
| >
| >
| |)* "'">
| |)* "\"">
| |) )* "'''">
| |) )* "\"\"\"">
| <#SAFE_CHAR1: (~["'", "\\", "\r", "\n"])>
| <#SAFE_CHAR2: (~["\"", "\\", "\r", "\n"])>
| <#SAFE_CHAR_LONG1: (~["'","\\"])>
| <#SAFE_CHAR_LONG2: (~["\"","\\"])>
| <#ECHAR: "\\" ["t", "b", "n", "r", "f", "\\", "\"", "'"]>
| <#HEX: ["0"-"9"] | ["A"-"F"] | ["a"-"f"]>
| <#ALPHA: ["a"-"z","A"-"Z"]>
| <#NUM: ["0"-"9"]>
}
TOKEN:
{
<#PN_CHARS_BASE:
| ["\u00c0"-"\u00d6"] | ["\u00d8"-"\u00f6"] | ["\u00f8"-"\u02ff"] | ["\u0370"-"\u037d"]
| ["\u037f"-"\u1fff"] | ["\u200c"-"\u200d"] | ["\u2070"-"\u218f"] | ["\u2c00"-"\u2fef"]
| ["\u3001"-"\ud7ff"] | ["\uf900"-"\ufdcf"] | ["\ufdf0"-"\ufffd"]
// | ["\u10000"-"\uefffF"] FIXME: JavaCC/Java can't handle this?
>
| <#PN_CHARS_U: | "_">
| <#VAR_CHAR: | | "\u00b7" | ["\u0300"-"\u036f"] | ["\u203f"-"\u2040"]>
| <#PN_CHARS: | "-" | | "\u00b7" | ["\u0300"-"\u036f"] | ["\u203f"-"\u2040"]>
| <#PN_PREFIX: ( ( | ".")* )?>
| <#PN_LOCAL: ( | ":" | | ) ( ( | "." | ":" | )* ( | ":" | ) )?>
| <#PLX: | >
| <#PERCENT: "%" >
| <#PN_LOCAL_ESC: "\\" [ "_", "~", ".", "-", "!", "$", "&", "\"", "(", ")", "*", "+", ",", ";", "=", "/", "?", "#", "@", "%" ]>
| <#VARNAME: ( | ) ()*>
}
//
// grammar
//
ASTUpdateSequence UpdateSequence():
{/*@bgen(jjtree) UpdateSequence */
ASTUpdateSequence jjtn000 = new ASTUpdateSequence(JJTUPDATESEQUENCE);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) UpdateSequence */
try {
/*@egen*/
UpdateContainer() [ UpdateSequence() ] /*@bgen(jjtree)*/
{
jjtree.closeNodeScope(jjtn000, true);
jjtc000 = false;
}
/*@egen*/
{ return jjtn000; }/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
ASTUpdateContainer UpdateContainer():
{/*@bgen(jjtree) UpdateContainer */
ASTUpdateContainer jjtn000 = new ASTUpdateContainer(JJTUPDATECONTAINER);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) UpdateContainer */
try {
/*@egen*/
Prolog() [ Update() ]/*@bgen(jjtree)*/
{
jjtree.closeNodeScope(jjtn000, true);
jjtc000 = false;
}
/*@egen*/
{ return jjtn000; }/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
ASTQueryContainer QueryContainer():
{/*@bgen(jjtree) QueryContainer */
ASTQueryContainer jjtn000 = new ASTQueryContainer(JJTQUERYCONTAINER);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) QueryContainer */
try {
/*@egen*/
Prolog() Query() /*@bgen(jjtree)*/
{
jjtree.closeNodeScope(jjtn000, true);
jjtc000 = false;
}
/*@egen*/
{ return jjtn000; }/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void Prolog() :
{}
{
( PrefixDecl() | BaseDecl() )*
}
void BaseDecl() :
{/*@bgen(jjtree) BaseDecl */
ASTBaseDecl jjtn000 = new ASTBaseDecl(JJTBASEDECL);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/ Token t; }
{/*@bgen(jjtree) BaseDecl */
try {
/*@egen*/
t = /*@bgen(jjtree)*/
{
jjtree.closeNodeScope(jjtn000, true);
jjtc000 = false;
}
/*@egen*/ {jjtn000.setIRI(_trimString(t.image, 1));}/*@bgen(jjtree)*/
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void PrefixDecl() :
{/*@bgen(jjtree) PrefixDecl */
ASTPrefixDecl jjtn000 = new ASTPrefixDecl(JJTPREFIXDECL);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/ Token prefix; }
{/*@bgen(jjtree) PrefixDecl */
try {
/*@egen*/
prefix = IRI()/*@bgen(jjtree)*/
{
jjtree.closeNodeScope(jjtn000, true);
jjtc000 = false;
}
/*@egen*/
{
// Remove trailing colon from prefix
String prefixStr = prefix.image;
prefixStr = prefixStr.substring(0, prefixStr.length() - 1);
jjtn000.setPrefix(prefixStr);
}/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void Query() :
{}
{
(SelectQuery() | ConstructQuery() | DescribeQuery() | AskQuery()) }
void SelectQuery() :
{/*@bgen(jjtree) SelectQuery */
ASTSelectQuery jjtn000 = new ASTSelectQuery(JJTSELECTQUERY);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) SelectQuery */
try {
/*@egen*/
Select()
( DatasetClause() )*
( NamedSubquery() )*
WhereClause()
SolutionModifier()
[BindingsClause()]/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void SubSelect() : // subselect does not accept dataset clauses
{/*@bgen(jjtree) SelectQuery */
ASTSelectQuery jjtn000 = new ASTSelectQuery(JJTSELECTQUERY);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) SelectQuery */
try {
/*@egen*/
Select()
WhereClause()
SolutionModifier()
[BindingsClause()]/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void Select() :
{/*@bgen(jjtree) Select */
ASTSelect jjtn000 = new ASTSelect(JJTSELECT);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) Select */
try {
/*@egen*/
[
{jjtn000.setDistinct(true);}
|
{jjtn000.setReduced(true);}
]
(
/*@bgen(jjtree)*/
{
jjtree.closeNodeScope(jjtn000, true);
jjtc000 = false;
}
/*@egen*/ { jjtn000.setWildcard(true); }
|
( ProjectionElem() )+
)/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void ProjectionElem() :
{/*@bgen(jjtree) ProjectionElem */
ASTProjectionElem jjtn000 = new ASTProjectionElem(JJTPROJECTIONELEM);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) ProjectionElem */
try {
/*@egen*/
Var()
|
Expression() Var() /*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void ConstructQuery() :
{/*@bgen(jjtree) ConstructQuery */
ASTConstructQuery jjtn000 = new ASTConstructQuery(JJTCONSTRUCTQUERY);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) ConstructQuery */
try {
/*@egen*/
Construct()
( DatasetClause() )*
( NamedSubquery() )*
WhereClause()
SolutionModifier()
[BindingsClause()]/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void Construct() :
{/*@bgen(jjtree) Construct */
ASTConstruct jjtn000 = new ASTConstruct(JJTCONSTRUCT);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) Construct */
try {
/*@egen*/