This page is used to generate the BNF grammar for the new proposed TXT format (an extension of CQL).
To generate a stable BNF we are going to do the following:
- some examples (this is going to be the a user document), to reduce the work
we could add only, examples of cql changes and new (no presents in cql). - for each example we will write a grammar rule in BNF (important: maintain
reference example -> BNF rule). - If we have complete grammar, we could begin to: eliminate left recursions,
ambiguous rules analysis, etc. - programming: unit test (from cql and 1 ); write the javacc input (from 3);
refactor cql to reuse the builders.
This page is being used to record the notes for step 1 through 3...
Related
Contents
Examples of Modified Rules
Basically we are going to replace the use of attribute_name with expression except where it does not make sense:
- exists check is only valid for attribute_name
Comparisons
CQL Example:
CQL Rule:
<comparison predicate> ::=
<attribute_name> <comp op> <literal>
| <attribute_name> <comp op> <expression>
TXT Examples:
TXT Rule:
<comparison predicate> ::= <expression> <comp op> <expression>
Between
CQL Examples:
CQL Rule:
<between predicate> ::= <attribute-name> [ NOT ] BETWEEN <literal> AND <literal>
TXT Examples:
TXT Rule:
<between predicate> ::= <expression> [ "NOT" ] "BETWEEN" <expression> "AND" <expression>
LIKE Text Pattern
CQL Example:
foo LIKE 'John%'
CQL Rule:
<text predicate> ::= <attribute name> [ "NOT" ] "LIKE" <character pattern>
TXT Example:
strconcat("John", "Oliver") LIKE 'John%'
TXT Rule:
<like text predicate> ::= <expression> [ "NOT" ] "LIKE" <character pattern>
Id Predicate
CQL Example: n/a
TXT Examples:
ID IN 'river.43' ID IN 'road.1', 'road.2', 'road.47'
TXT Rule:
<id predicate> ::= "ID" ["NOT"] "IN" "(" <id> {"," <id> } ")"
<id> ::=
IN predicate
CQL Example: n/a
TXT Examples:
huc_8 IN (4100001,4100011,4100012) huc_8 NOT IN (4100001,4100011,4100012)
TXT Rule:
<in predicate> ::= <attribute-name> [ "NOT" ] "IN" <in predicate value>
<in predicate value> ::= "(" <in value list> ")"
Null
CQL Examples:
ATTR1 IS NULL ATTR2 IS NOT NULL
CQL Rule:
<null predicate> ::= <attribute name> "IS" [ "NOT" ] "NULL"
TXT Examples:
ATTR1 IS NULL ATTR2 IS NOT NULL centroid( the_geom ) IS NOT NULL
TXT Rule:
<null predicate> ::= <expression> "IS" [ "NOT" ] "NULL"
Spatial Predicates Functions
The spatial predicates are expressed in CQL with function syntax as the following examples.
CQL Example:
CONTAINS(the_geom POINT(12 30)) BBOX(ATTR1, 10,20,30,40)
CQL Rule:
<routine invocation> ::=
<geoop name><georoutine argument list>
| <relgeoop name><relgeoop argument list>
| <routine name><argument list>
| "BBOX" <bbox argument list>
This extension allows the composition of functions
TXT Example:
CONTAINS(the_geom, POINT(12 30)) BBOX(ATTR1, 10,20,30,40) CROSSES(centroid( the_geom ), BUFFER(LINESTRING (15 15, 20 20),10)) BBOX( buffer( the_geom , 10), 10,20,30,40 ) BBOX( buffer( the_geom , 10), buffer( POINT( 15,15), 10) )
TXT Rule:
The name of spatial relations were adjusted to Implementation Specification for Geographic Information - Simple Feature Access ( OGC 05-134 v1.1.0 ).
<geometry predicate> ::= <geoop name><georoutine argument list>
| <expression><relgeoop name><relgeoop argument list>
| BBOX <bbox argument list>
<geoop name> ::= EQUALS | DISJOINT | INTERSECTS | TOUCHES | CROSSES | WITHIN | CONTAINS |OVERLAPS | RELATE
<georoutine argument list> ::= <expression> | <geometry literal>
<relgeoop name> ::= "DWITHIN" | "BEYOND"
<relgeoop argument list> ::= <expression> <tolerance>
| <geometry literal> <tolerance>
bbox argument list> ::= "(" <attribute>,<min X> ,<min Y> ,<max X>,<max Y> ["," <crs>] ")"
| "(" <expression>,<min X> ,<min Y> ,<max X>,<max Y> ["," <crs>] ")"
| "(" <expression>, <expression> ")"
Spatial Relation Predicate
Thinking to improve the legibility and achieve a language near to "natural language" in this section is proposed an alternative syntax to the "Spatial Predicates Functions".
CQL Example: see "Spatial Geometry Predicates" section
TXT Example:
geom1 INTERSECTS geom2 geom1 TOUCHES geom2 geom1 EQUALS geom2 geom1 DISJOINTS geom2 geom1 CROSSES geom2 geom1 WITHIN geom2 geom1 CONTAINS geom2 geom1 OVERLAPS geom2 geom1 RELATES geom2 LIKE 'T**F*****' geom1 DWITHIN geom2 DISTANCE 10.0 km geom1 BEYOND geom2 DISTANCE 10.0 km
TXT Rule:
<spatial-relation predicate> ::=
<geom-expression> <spatial-relation> <geom-expression>
|<geom-expression> <distance-relation> <geom-expression> DISTANCE <number> <units>
|<geom-expression> "RELATES" <geom-expression> [ "NOT" ] "LIKE" <relate pattern>
<spatial-relation> ::= EQUALS | DISJOINTS | INTERSECTS | TOUCHES
| CROSSES | WITHIN | CONTAINS |OVERLAPS | RELATES
<distance-relation> ::= DWITHIN | BEYOND
<relate pattern> ::= <quote>
<relate flag><relate flag><relate flag><relate flag>
<relate flag><relate flag><relate flag><relate flag>
<relate flag>
<quote>
<relate flag> ::= "T" | "F" | "*" | "0" | "1" | "2"
TXT Grammar
We provide a new TXT grammar which includes the described syntax rules in the following link:TXT BNF Design