From 7c3e18c7b93bf166f9a8b448e653328df898fc18 Mon Sep 17 00:00:00 2001 From: Clemens Portele Date: Mon, 5 Jul 2021 14:55:10 +0200 Subject: [PATCH] BNF/JSON: update grammar (s/t/a functions, temporal literals, scalar with instants) WIP: updates in text/examples/etc to follow --- extensions/cql/standard/schema/cql.bnf | 48 +++++++++----- extensions/cql/standard/schema/cql.json | 87 +++++++++++++++---------- 2 files changed, 86 insertions(+), 49 deletions(-) diff --git a/extensions/cql/standard/schema/cql.bnf b/extensions/cql/standard/schema/cql.bnf index 8c180f4e..7a6a0207 100644 --- a/extensions/cql/standard/schema/cql.bnf +++ b/extensions/cql/standard/schema/cql.bnf @@ -52,6 +52,7 @@ binaryComparisonPredicate = scalarExpression scalarExpression = characterLiteral | numericLiteral | booleanLiteral + | instantLiteral | propertyName | function | arithmeticExpression; @@ -91,7 +92,7 @@ isInListPredicate = inListOperand ["NOT"] "IN" leftParen inList rightParen; inList = inListOperand [ {comma inListOperand} ]; inListOperand = scalarExpression - | temporalLiteral + | intervalLiteral | spatialLiteral; # IS NULL predicate @@ -130,7 +131,8 @@ geomExpression = spatialLiteral # A temporal predicate evaluates if two temporal expressions satisfy the # specified temporal operator. #=============================================================================# -temporalPredicate = temporalExpression temporalOperator temporalExpression; +temporalPredicate = temporalOperator + leftParen temporalExpression comma temporalExpression rightParen; temporalExpression = temporalLiteral | propertyName @@ -158,7 +160,8 @@ temporalOperator = "T_AFTER" # not equal, less than, greater than, less than or equal, greater than or equal, # superset, subset and overlap operators. #=============================================================================# -arrayPredicate = arrayExpression arrayOperator arrayExpression; +arrayPredicate = arrayOperator + leftParen arrayExpression comma arrayExpression rightParen; # An array expression is a bracket-delimited, comma-separated list of array # elements. An array element is either a character literal, a numeric literal, @@ -182,7 +185,7 @@ arrayElement = characterLiteral arrayOperator = "A_EQUALS" | "A_CONTAINS" - | "A_CONTAINED BY" + | "A_CONTAINEDBY" | "A_OVERLAPS"; #=============================================================================# @@ -511,18 +514,31 @@ maxElev = signedNumericLiteral; # NOTE: Is the fact the time zones are supported too complicated for a # simple CQL? Perhaps the "core" of CQL should just support UTC. #=============================================================================# -temporalLiteral = instant | interval; - -instant = fullDate | fullDate "T" utcTime; - -interval = solidus - | solidus dotdot - | dotdot solidus - | instant solidus - | solidus instant - | instant solidus dotdot - | dotdot solidus instant - | instant solidus instant; +temporalLiteral = instantLiteral | intervalLiteral; + +instantLiteral = dateInstant | timestampInstant; + +dateInstant = "DATE" + leftParen dateInstantString rightParen; + +dateInstantString = quote fullDate quote; + +timestampInstant = "TIMESTAMP" + leftParen timestampInstantString rightParen; + +timestampInstantString = quote fullDate "T" utcTime quote; + +instantLiteral = fullDate | fullDate "T" utcTime; + +intervalLiteral = "INTERVAL" + leftParen instantParameter comma instantParameter rightParen; + +instantParameter = instantLiteral + | dateInstantString + | timestampInstantString + | quote dotdot quote + | propertyName + | function; fullDate = dateYear "-" dateMonth "-" dateDay; diff --git a/extensions/cql/standard/schema/cql.json b/extensions/cql/standard/schema/cql.json index a6a79b98..354d8099 100644 --- a/extensions/cql/standard/schema/cql.json +++ b/extensions/cql/standard/schema/cql.json @@ -179,7 +179,7 @@ "oneOf": [ {"$ref": "#/$defs/scalarExpression"}, {"$ref": "#/$defs/spatialLiteral"}, - {"$ref": "#/$defs/typedTemporalLiteral"} + {"$ref": "#/$defs/intervalLiteral"} ] }, @@ -532,12 +532,12 @@ "type": "array", "items": { "oneOf": [ - {"$ref": "#/$defs/scalarLiteral"}, - {"$ref": "#/$defs/spatialLiteral"}, - {"$ref": "#/$defs/typedTemporalLiteral"}, + { "$ref": "#/$defs/scalarLiteral"}, + { "$ref": "#/$defs/spatialLiteral"}, + { "$ref": "#/$defs/intervalLiteral"}, { "$ref": "#/$defs/propertyRef" }, { "$ref": "#/$defs/functionRef" }, - {"$ref": "#/$defs/arithmeticExpression"}, + { "$ref": "#/$defs/arithmeticExpression"}, { "$ref": "#/$defs/arrayLiteral" } ] } @@ -636,7 +636,7 @@ "oneOf": [ { "$ref": "#/$defs/scalarLiteral" }, { "$ref": "#/$defs/spatialLiteral" }, - { "$ref": "#/$defs/typedTemporalLiteral" }, + { "$ref": "#/$defs/intervalLiteral" }, { "$ref": "#/$defs/propertyRef" }, { "$ref": "#/$defs/functionRef" }, { "$ref": "#/$defs/arithmeticExpression" }, @@ -655,7 +655,8 @@ "oneOf": [ { "type": "string" }, { "type": "number" }, - { "type": "boolean"} + { "type": "boolean"}, + { "$ref": "#/$defs/instantLiteral" } ] }, @@ -885,54 +886,74 @@ "temporalLiteral": { "oneOf": [ - { "$ref": "#/$defs/instantString" }, - { "$ref": "#/$defs/intervalString" } + { "$ref": "#/$defs/instantLiteral" }, + { "$ref": "#/$defs/intervalLiteral" } ] }, - "instantString": { + "instantLiteral": { "oneOf": [ - { "type": "string", "format": "date" }, - { "type": "string", "format": "date-time" } + { "$ref": "#/$defs/dateLiteral" }, + { "$ref": "#/$defs/timestampLiteral" } ] }, - "intervalString": { - "type": "array", - "minItems": 2, - "maxItems": 2, - "items": { - "oneOf": [ - { "$ref": "#/$defs/instantString" }, - { "type": "string", "enum": [".."] } - ] + "dateLiteral": { + "type": "object", + "required": ["date"], + "properties": { + "date": { + "$ref": "#/$defs/dateString" + } + } + }, + + "timestampLiteral": { + "type": "object", + "required": ["timestamp"], + "properties": { + "timestamp": { + "$ref": "#/$defs/timestampString" + } } }, - "typedTemporalLiteral": { + "instantString": { "oneOf": [ - { "$ref": "#/$defs/typedInstantString" }, - { "$ref": "#/$defs/typedIntervalString" } + { "$ref": "#/$defs/dateString" }, + { "$ref": "#/$defs/timestampString" } ] }, - "typedInstantString": { + "dateString": { + "type": "string", + "format": "date" + }, + + "timestampString": { + "type": "string", + "format": "date-time" + }, + + "intervalLiteral": { "type": "object", "required": ["datetime"], "properties": { "datetime": { - "$ref": "#/$defs/instantString" + "$ref": "#/$defs/intervalArray" } } }, - "typedIntervalString": { - "type": "object", - "required": ["datetime"], - "properties": { - "datetime": { - "$ref": "#/$defs/intervalString" - } + "intervalArray": { + "type": "array", + "minItems": 2, + "maxItems": 2, + "items": { + "oneOf": [ + { "$ref": "#/$defs/instantString" }, + { "type": "string", "enum": [".."] } + ] } } }