/* * GeoTools - The Open Source Java GIS Tookit * http://geotools.orgLITERAL * * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)SpatialRelateLikeSpatialRelateLike * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library 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 * Lesser General Public License for more details. */ options { STATIC=false; NODE_SCOPE_HOOK=true; NODE_DEFAULT_VOID=true; MULTI=false; BUILD_NODE_FILES=false; // Generates sample implementations for SimpleNode and any other nodes used in the grammar NODE_PACKAGE="org.geotools.filter.text.generated.parsers"; SANITY_CHECK=true; VISITOR=false; FORCE_LA_CHECK=false; // force lookahead ambiguity checking in such instances. This option don't take into account the locak lookagead // debug DEBUG_TOKEN_MANAGER=false; DEBUG_PARSER=false; } PARSER_BEGIN(ECQLParser) package org.geotools.filter.text.generated.parsers; import java.util.HashSet; import java.util.Set; /** * ECQLParser is the result of a javacc jjtree grammar. * * @author Mauricio Pazos - Axios Engineering * @since 2.6 */ public class ECQLParser { public void jjtreeOpenNodeScope(Node n) throws ParseException { } public void jjtreeCloseNodeScope(Node n) throws ParseException { } // initialize geooperations protected static final Set GEOOP = new HashSet(); static { GEOOP.add("EQUALS"); GEOOP.add("DISJOINT"); GEOOP.add("INTERSECTS"); GEOOP.add("TOUCHES"); GEOOP.add("CROSSES"); GEOOP.add("WITHIN"); GEOOP.add("CONTAINS"); GEOOP.add("OVERLAPS"); GEOOP.add("RELATE"); GEOOP.add("BBOX"); } protected boolean isGeoOp() { return "(".equals(getToken(2).image) && GEOOP.contains(getToken(1).image.toUpperCase()); } protected static final Set RELGEOOP = new HashSet(); static { RELGEOOP.add("DWITHIN"); RELGEOOP.add("BEYOND"); } protected boolean isRelGeoOp() { return "(".equals(getToken(2).image) && RELGEOOP.contains(getToken(1).image.toUpperCase()); } } PARSER_END(ECQLParser) SKIP : /* WHITE SPACE */ { " " | "\t" | "\n" | "\r" | "\f" } /* * */ TOKEN: { < STRING_LITERAL: "'" ( "''" | ~["'"] )* "'" > : DEFAULT } /* * keywords */ TOKEN [IGNORE_CASE]: /* keywords */ { < AND: "and" | "&&"> | < OR: "or"> | < NOT: "not" | "!"> | < EQ: "eq" | "==" | "="> | < NEQ: "neq" | "<>" > | < GT: "gt" | ">" > | < LT: "lt" | "<" > | < GTE: "gte" | ">="> | < LTE: "lte" | "<="> | < TRUE: "true"> | < FALSE: "false"> | < UNKNOWN: "unknown"> | < LIKE: "like" > | < BETWEEN: "between"> | < ID: "id" > | < IN: "in" > | < IS: "is" > | < NULL: "null" > } TOKEN [IGNORE_CASE]: /* include all and exclude all filters */ { < INCLUDE: "include"> | < EXCLUDE: "exclude"> } TOKEN [IGNORE_CASE]: /* geometry markers */ { < POINT: "point"> | < LINESTRING: "linestring"> | < POLYGON: "polygon"> | < MULTIPOINT: "multipoint"> | < MULTILINESTRING: "multilinestring"> | < MULTIPOLYGON: "multipolygon"> | < GEOMETRYCOLLECTION: "geometrycollection"> | < ENVELOPE: "envelope"> } TOKEN [IGNORE_CASE]: /* temporal expression*/ { | | | } TOKEN [IGNORE_CASE]: /* existence predicate*/ { | } TOKEN [IGNORE_CASE]: { < EQUALS: "equals"> | < DISJOINT: "disjoint"> | < INTERSECTS: "intersects"> | < TOUCHES: "touches"> | < CROSSES: "crosses"> | < WITHIN: "within"> | < CONTAINS: "contains"> | < OVERLAPS: "overlaps"> | < RELATE: "relate"> | < BBOX: "bbox"> } TOKEN [IGNORE_CASE]: /* relgeoop name */ { < DWITHIN: "dwithin"> | < BEYOND: "beyond"> } TOKEN [IGNORE_CASE]: { | | | | } TOKEN: { < LP: "("> | < RP: ")"> | < LSP: "["> | < RSP: "]"> | < COMMA: ","> | < SENTENCE_SEPARATOR: ";"> | < PERIOD: "."> | < SLASH: "/"> | // < PERIOD_SEP: > | // < DIV: > | < COLON: ":"> | < MULT: "*"> | < PLUS: "+"> | < MINUS: "-" > } // Note, because float and int can technically have the same grammar, // put int first to make token manager have preference for it... // The same case occurs between identifier and duration tokens, // then DURATION has preference over IDENTIFIER TOKEN [IGNORE_CASE]: /* Literals */ { < INTEGER_LITERAL: ()+ > | < FLOATING_LITERAL: ( ( )* "." ( )+ ()? ) | ( ( )+ ("." ( )*)? ()? ) > | < #DUR_DAY: ()+ "D" > | < #DUR_MONTH: ()+ "M" ()? > | < #DUR_YEAR: ()+ "Y" ()? > | < #DUR_DATE: ( | | ) ("T" )?> | < #DUR_HOUR: ()+ "H" ()?> | < #DUR_MINUTE:()+ "M" ()? > | < #DUR_SECOND:()+ "S" > | < #DUR_TIME: ( | | ) > | < DURATION: ("P" | "T" ) > | < #FULL_DATE: "-" "-" > | < #UTC_TIME: ":" ":" ("." ()+)? "Z" > | < DATE_TIME : "T" > | < IDENTIFIER: ( (|)*) > | < LETTER: [ "a"-"z", "A"-"Z" , "_"] > | < DIGIT: [ "0"-"9"] > | < #EXPONENT: ["e","E"] (["+","-"])? ()+ > } /* * Program structuring syntax to parse a single filter. */ Node FilterCompilationUnit() : {} { SearchCondition() {return jjtree.rootNode();} } /* * Program structuring syntax to parse a single expression. */ Node ExpressionCompilationUnit() : {} { ECQLExpression() {return jjtree.rootNode();} } void ECQLExpression()#void: {} { Expression() } /* * Program structuring syntax to parse a list of filters. */ Node FilterListCompilationUnit() : {} { SequenceOfSearchConditions() {return jjtree.rootNode();} } /* * ::= * * | ; */ void SequenceOfSearchConditions() #void: {} { SearchCondition() ( SearchCondition())* } void SearchCondition() #void: {} { BooleanValueExpression() } /* * ::= * * | OR */ void BooleanValueExpression() #void: {} { BooleanTerm()( BooleanTerm() #Boolean_Or_Node )* } /* * ::= * * | AND */ void BooleanTerm() #void : {} { BooleanFactor()( BooleanFactor() #Boolean_And_Node )* } void BooleanFactor() #void: {} { BooleanPrimary() #Boolean_Not_Node | BooleanPrimary() } void BooleanPrimary() #void: {} { LOOKAHEAD(Predicate()) Predicate() | IncludeExcludePredicate() | SearchCondition() | SearchCondition() | RoutineInvocation() } /* * ::= * | * | * | * | (*not supported*) * | * | (*extension*) * | (*extesion*) * | */ void Predicate() #void: {} { LOOKAHEAD(3) Expression() ( LOOKAHEAD(2) TextPredicate() | LOOKAHEAD(2) ExistencePredicate() | LOOKAHEAD(2) NullPredicate() | LOOKAHEAD(2) BetweenPredicate() | LOOKAHEAD(2) TemporalPredicate() | ComparisonPredicate() ) | LOOKAHEAD(3) IdPredicate() | InPredicate() } /* ---------------------------------------- * * * ---------------------------------------- * /* * ::= "ID" "IN" * ::= , {"," id value} */ void IdPredicate() #void: {} { LOOKAHEAD(3) IdList() #Not_Id_Predicate_Node | IdList() #Id_Predicate_Node } void IdList() #void: {} { IdValue()( IdValue() )* } void IdValue() #FEATURE_ID_NODE: {} { | } /* ---------------------------------------- * * * ---------------------------------------- * /* /* ::= [ "NOT" ] "IN" * ::= "(" ")" * ::= {"," } */ void InPredicate() #void: {} { LOOKAHEAD(4) Attribute() InPredicateList() #Not_In_Predicate_Node | Attribute() InPredicateList() #In_Predicate_Node } void InPredicateList() #void: {} { ExpressionInList()( ExpressionInList() )* } void ExpressionInList() #Expression_In_List_Node: {} { Expression() } /* ---------------------------------------- * * * ---------------------------------------- * /* * ::= * * | * | */ void RoutineInvocation() #void: {} { LOOKAHEAD({ isGeoOp() }) RoutineInvocationGeoOp() | LOOKAHEAD({ isRelGeoOp() }) RoutineInvocationRelGeoOp() | RoutineInvocationGeneric() } void RoutineInvocationGeoOp() #void: {} { GeoRoutineArgumentList() #RoutineInvocation_GeoOp_Equal_Node | GeoRoutineArgumentList() #RoutineInvocation_GeoOp_Disjoint_Node | GeoRoutineArgumentList() #RoutineInvocation_GeoOp_Intersect_Node | GeoRoutineArgumentList() #RoutineInvocation_GeoOp_Touch_Node | GeoRoutineArgumentList() #RoutineInvocation_GeoOp_Cross_Node | GeoRoutineArgumentList() #RoutineInvocation_GeoOp_Within_Node | GeoRoutineArgumentList() #RoutineInvocation_GeoOp_Contain_Node | GeoRoutineArgumentList() #RoutineInvocation_GeoOp_Overlap_Node | GeoRoutineArgumentList() RelateTail() | BBoxArgumentList() } void RelateTail() #void: {} { #Relate_Node // FIXME | SpatialRelateLike() } /* void SpatialRelateLike() #void: {} { LOOKAHEAD(2) CharacterPattern() #Not_SpatialRelateLike_Node | Pattern9IM() #SpatialRelateLike_Node } * * ::= * * * * * ::= "T" | "F" | "*" | "0" | "1" | "2" * void Pattern9IM() #Pattern9IM_Node: {} { CharacterPattern() } */ /* * ::= * * */ void GeoRoutineArgumentList() #void: {} { Expression() Expression() } /* * ::= * "(" "," ")" * | "(" "," * "," * "," * "," * * [, srs] ")" * * ::= * ::= * ::= * ::= * ::= */ void BBoxArgumentList() #void: {} { Expression() BBoxArgListTail() } void BBoxArgListTail() #void: {} { BoundingBox() | (Function() | GeometryLiteral()) } void BoundingBox() #void: {} { NumericLiteral() NumericLiteral() NumericLiteral() NumericLiteral() ( #RoutineInvocation_GeoOp_BBOX_Node | StringLiteral() #RoutineInvocation_GeoOp_BBOX_SRS_Node) } /* * ::= DWITHIN | BEYOND */ void RoutineInvocationRelGeoOp() #void: {} { RelGeoRoutineArgumentList() #RoutineInvocation_RelOp_DWITHIN_Node | RelGeoRoutineArgumentList() #RoutineInvocation_RelOp_BEYOND_Node } /* * ::= * */ void RelGeoRoutineArgumentList() #void: {} { Expression() Expression() Tolerance() // Attribute() GeometryLiteral() Tolerance() } /* * ::= */ void Tolerance() : {} { UnsignedNumericLiteral() #Tolerance_Node DistanceUnits() } /** * ::= * 'feet' | 'meters' | 'statute miles' | * 'nautical miles' | 'kilometers' * * TODO this set of units is just an example. The real list of distance unit must be developed */ void DistanceUnits() #DistanceUnits_Node: {} { | | | | } /* * ::= * * | * | * | * | * | * | * | */ void GeometryLiteral() #GeometryLiteral: {} { PointTaggedText() | LineStringTaggedText() | PolygonTaggedText() | MultiPointTaggedText() | MultiLineStringTaggedText() | MultiPolygonTaggedText() | GeometryCollectionTaggedText() | EnvelopeTaggedText() } /* * ::= * | * * [] * ::= * [ { }... ] * * ::= * * | * | (*Extension*) * | (*Extension*) */ void RoutineInvocationGeneric() #void: {} { Function() } /* ---------------------------------------- * * End * ---------------------------------------- * /* ---------------------------------------- * * * ---------------------------------------- * /* * ::= * | */ void IncludeExcludePredicate() #void: {} { #Include_Node | #Exclude_Node } /* ---------------------------------------- * * * ---------------------------------------- * /* * ::= * */ void ComparisonPredicate() : {} { Expression() #ComparisonPredicate_EQ_Node | Expression() #ComparisonPredicate_GT_Node | Expression() #ComparisonPredicate_LT_Node | Expression() #ComparisonPredicate_GTE_Node | Expression() #ComparisonPredicate_LTE_Node | Expression() #ComparisonPredicate_Not_Equal_Node } /* * ::= IS [ NOT ] NULL */ void NullPredicate() : {} { LOOKAHEAD(3) #NullPredicateNode | #NotNullPredicateNode } /* ---------------------------------------- * * * ---------------------------------------- * * ::= * BEFORE * | BEFORE OR DURING * | DURING * | DURING OR AFTER * | AFTER */ void TemporalPredicate() #void: {} { TemporalPredicateBefore() | TemporalPredicateAfter() | TemporalPredicateDuring() } void TemporalPredicateBefore()#void: {} { DateTimeExpression() #TPBefore_DateTime_Node | Period() #TPBefore_Or_During_Period_Node } void TemporalPredicateAfter() #TPAfter_DateTime_Node: {} { DateTimeExpression() } void TemporalPredicateDuring()#void: {} { Period() #TPDuring_Period_Node | Period() #TPDuring_Or_After_Period_Node } /* * | */ void DateTimeExpression()#void: {} { LOOKAHEAD(2) Period() | DateTime() } /* * ::= * "/" * | "/" * | "/" */ void Period() #void: {} { LOOKAHEAD(2) DateTime() PeriodTail() | Duration() DateTime() #Period_With_Duration_Date_Node } void PeriodTail()#void: {} { Duration() #Period_With_Date_Duration_Node | DateTime() #Period_Between_Dates_Node } void DateTime()#DateTime_Node: {} { } /* * ::= "P" | * ::= | | [] * ::= ... "D" * ::= ... "M" [] * ::= ... "Y" [] */ void Duration()#void: {} { #Duration_Date_Node } /* ---------------------------------------- * * End * ---------------------------------------- */ /* ---------------------------------------- * * * ---------------------------------------- */ /* * ::= EXISTS * | DOES-NOT-EXIST */ void ExistencePredicate() #void: {} { #Existence_Predicate_Exists_Node | #Existence_Predicate_DoesNotExist_Node } /* ---------------------------------------- * * end * ---------------------------------------- */ void TextPredicate() #void: {} { LOOKAHEAD(2) CharacterPattern() #Not_Like_Node | CharacterPattern() #Like_Node } void CharacterPattern() #void: {} { StringLiteral() } /* * Cql Extension * * ::= ["NOT"] "BETWEEN" expression "AND" expression */ void BetweenPredicate() #void: {} { LOOKAHEAD(2) Expression() Expression() #Not_Between_Node | Expression() Expression() #Between_Node } /* * cql extension * ::= */ void Expression() #void: {} { BinaryExpression() | GeometryLiteral() } void BinaryExpression() #void: {} { MultiplicativeExpression() ( MultiplicativeExpression() #AddNode | MultiplicativeExpression() #SubtractNode )* } void MultiplicativeExpression() #void : {} { UnaryExpression() ( UnaryExpression() #MulNode | UnaryExpression() #DivNode )* } void UnaryExpression() #void: {} { LOOKAHEAD(2) Expression() | LOOKAHEAD(2) Expression() | LOOKAHEAD(2) Function() | Literal() | Attribute() } void Evaluate() #void: {} { LOOKAHEAD(2) Function() | Attribute() } /* * ::= | }... ] */ void Identifier() #Identifier_Node: {} { IdentifierPart() ( | IdentifierPart() )* } void IdentifierPart() #Identifier_Part_Node: {} { } /* * ::= * * | * * ::= * [{}*] * * ::= */ void Attribute() #void: {} { SimpleAttributeName() AttributeTail() } /* * ::= */ void SimpleAttributeName() #Simple_Attribute_Node: {} { Identifier() } void AttributeTail() #Compound_Attribute_Node: {} { ( SimpleAttributeName() )* } /* * ::= * * | */ void Literal() #void : {} { NumericLiteral() | GeneralLiteral() } void NumericLiteral() #void : {} { (("-") UnsignedNumericLiteral()) #NegativeNumber_Node | UnsignedNumericLiteral() } void UnsignedNumericLiteral() #void : {} { IntegerLiteral() | FloatingLiteral() } /* * ::= * * | * | * | } void FloatingLiteral() #FloatingNode: {} { } void BooleanLiteral() #void : {} { #TrueNode | #FalseNode } void StringLiteral() #StringNode : {} { } /* ---------------------------------------- * * * ---------------------------------------- */ /* * ::= "(" [,]*) */ void Function() #Function_Node: {} { FunctionName() ( FunctionArg() ( FunctionArg() )* )? } void FunctionName() #FunctionName_Node: {} { } /* * ::= * * | * | (*extension: expresion inclue literal and attributes*) */ void FunctionArg() #FunctionArg_Node: {} { Expression() } /* ---------------------------------------- * * end * ---------------------------------------- */ /* * := */ void Point() #Point_Node: {} { NumericLiteral() NumericLiteral() } /* * := EMPTY * | {} ... */ void LineStringText() #LineStringText_Node: {} { ( Point() ( Point() )* )? } void PointTaggedText() #WKTNode: {} { PointText() } /* * := EMPTY | */ void PointText() #PointText_Node: {} { ( Point() )? } void LineStringTaggedText() #WKTNode: {} { LineStringText() } /* * := POLYGON */ void PolygonTaggedText() #WKTNode: {} { PolygonText() } /* * := EMPTY * | {}* */ void PolygonText()#PolygonText_Node: {} { ( LineStringText() ( LineStringText())* )? } /* * ::= MULTIPOINT */ void MultiPointTaggedText() #WKTNode: {} { MultiPointText() } /* * := EMPTY * | ( {, }* ) */ void MultiPointText() #MultiPointText_Node: {} { ( PointText() ( PointText() )* )? } /* * := MULTILINESTRING */ void MultiLineStringTaggedText() #WKTNode: {} { MultiLineStringText() } /* * := * EMPTY * | ( {, < LineString Text > }* ) */ void MultiLineStringText() #MultiLineStringText_Node: {} { ( LineStringText() ( LineStringText())* )? } /* * :: =MULTIPOLYGON */ void MultiPolygonTaggedText() #WKTNode: {} { MultiPolygonText() } /* * := EMPTY * | {}* */ void MultiPolygonText() #MultiPolygonText_Node: {} { ( PolygonText() ( PolygonText() )* )? } void GeometryCollectionTaggedText() #WKTNode: {} { GeometryCollectionText() } /* * := EMPTY * | ( {, }* ) */ void GeometryCollectionText() #GeometryCollectionText_Node: {} { ( GeometryLiteral() ( GeometryLiteral() )* )? } /* * ::= ENVELOPE */ void EnvelopeTaggedText() #EnvelopeTaggedText_Node: {} { jjtThis.token = EnvelopText() } /* * := EMPTY * | * * * * * * := numeric literal * := numeric literal * := numeric literal * := numeric literal */ void EnvelopText() #void: {} { ( NumericLiteral() NumericLiteral() NumericLiteral() NumericLiteral() )? }