All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.semanticwb.rdf.sparql.SparqlParser.g4 Maven / Gradle / Ivy

Go to download

Code-generation engine and core classes for the SemanticWebBuilder framework

The newest version!
/*
 *    Copyright 2007-2012 The sparkle-g Team
 *
 *    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.
 */

/**
 * @author Simone Tripodi   (simone.tripodi)
 * @author Michele Mostarda (michele.mostarda)
 * @author Juergen Pfundt   (Juergen.Pfundt)
 * @version $Id: Sparql.g 523 2012-02-17 23:10:57Z [email protected] $
 */
parser grammar SparqlParser;

options{
tokenVocab=SparqlLexer;
}

// $'|'<='|'>=') expression # relationalExpression
    | expression ('&&' expression)                          # conditionalAndExpression
    | expression ('||' expression)                          # conditionalOrExpression
    ;

unaryLiteralExpression
    : (numericLiteralPositive|numericLiteralNegative) (op=('*'|'/') unaryExpression)? 
    ;

unaryExpression
    : op=('!'|'+'|'-')? primaryExpression
    ;

primaryExpression
    : '(' expression ')' | builtInCall | iriRefOrFunction | rdfLiteral | numericLiteral | booleanLiteral | var
    ;

builtInCall
    : aggregate
    | STR '(' expression ')'
    | LANG '(' expression ')'
    | LANGMATCHES '(' expression ',' expression ')'
    | DATATYPE '(' expression ')'
    | BOUND '(' var ')'
    | IRI '(' expression ')'
    | URI '(' expression ')'
    | BNODE '(' expression? ')'
    | RAND '(' ')'
    | ABS '(' expression ')'
    | CEIL '(' expression ')'
    | FLOOR '(' expression ')'
    | ROUND '(' expression ')'
    | CONCAT '(' expressionList? ')'
    | subStringExpression
    | STRLEN '(' expression ')'
    | strReplaceExpression
    | UCASE '(' expression ')'
    | LCASE '(' expression ')'
    | ENCODE_FOR_URI '(' expression ')'
    | CONTAINS '(' expression ',' expression ')'
    | STRSTARTS '(' expression ',' expression ')'
    | STRENDS '(' expression ',' expression ')'
    | STRBEFORE '(' expression ',' expression ')'
    | STRAFTER '(' expression ',' expression ')'
    | YEAR '(' expression ')'
    | MONTH '(' expression ')'
    | DAY '(' expression ')'
    | HOURS '(' expression ')'
    | MINUTES '(' expression ')'
    | SECONDS '(' expression ')'
    | TIMEZONE '(' expression ')'
    | TZ '(' expression ')'
    | NOW '(' ')'
    | UUID '(' ')'
    | STRUUID '(' ')'
    | MD5 '(' expression ')'
    | SHA1 '(' expression ')'
    | SHA256 '(' expression ')'
    | SHA384 '(' expression ')'
    | SHA512 '(' expression ')'
    | COALESCE '(' expressionList? ')'
    | IF '(' expression ',' expression ',' expression ')'
    | STRLANG '(' expression ',' expression ')'
    | STRDT '(' expression ',' expression ')'
    | SAMETERM '(' expression ',' expression ')'
    | ISIRI '(' expression ')'
    | ISURI '(' expression ')'
    | ISBLANK '(' expression ')'
    | ISLITERAL '(' expression ')'
    | ISNUMERIC '(' expression ')'
    | regexExpression
    | existsFunction
    | notExistsFunction
    ;

regexExpression
    : REGEX '(' expression ',' expression (',' expression)? ')'
    ;
    
subStringExpression
    : SUBSTR '(' expression ',' expression (',' expression)? ')'
    ;
    
strReplaceExpression
    : REPLACE '(' expression ',' expression ',' expression (',' expression)? ')'
    ;
    
existsFunction
    : EXISTS groupGraphPattern
    ;

notExistsFunction
    : NOT EXISTS groupGraphPattern
    ;

aggregate
    : COUNT '(' DISTINCT? (ASTERISK | expression) ')'
    | SUM '(' DISTINCT? expression ')'
    | MIN '(' DISTINCT? expression ')'
    | MAX '(' DISTINCT? expression ')'
    | AVG '(' DISTINCT? expression ')'
    | SAMPLE '(' DISTINCT? expression ')'
    | GROUP_CONCAT '(' DISTINCT? expression (';' SEPARATOR '=' string)? ')'
    ;
    
iriRefOrFunction
    : iri argList?
    ;

rdfLiteral
    : string (LANGTAG | ('^^' iri))?
    ;

numericLiteral
    : numericLiteralUnsigned | numericLiteralPositive | numericLiteralNegative
    ;

numericLiteralUnsigned
    : INTEGER | DECIMAL | DOUBLE
    ;

numericLiteralPositive
    : INTEGER_POSITIVE | DECIMAL_POSITIVE | DOUBLE_POSITIVE
    ;

numericLiteralNegative
    : INTEGER_NEGATIVE | DECIMAL_NEGATIVE | DOUBLE_NEGATIVE
    ;

booleanLiteral
    : TRUE | FALSE
    ;

string
    : STRING_LITERAL1 | STRING_LITERAL2 | STRING_LITERAL_LONG1 | STRING_LITERAL_LONG2
    ;

iri
    : IRIREF | prefixedName
    ;

prefixedName
    : PNAME_LN | PNAME_NS
    ;

blankNode
    : BLANK_NODE_LABEL | anon
    ;

anon
    : '[' ']'
    ;
// $>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy