gws.lib.cql.parser

CQL2-Text parser.

Source code: gws.lib.cql.parser

Module Contents

class gws.lib.cql.parser.C

Operator, keyword and function sets of the parser.

ADDITIVE_OPERATORS

Additive operators, also used as unary signs.

ARRAY_FUNCTIONS

Functions whose parenthesized arguments are array literals.

COMPARISON_OPERATORS

Comparison operators.

FUNCTIONS

Standard functions and their number of arguments.

KEYWORDS

Reserved keywords.

LITERALS

Literal node types.

MULTIPLICATIVE_OPERATORS

Multiplicative operators.

NOT_EQUAL_OPERATORS

Not-equal operators, emitted as <>.

OPERATORS

All operators.

PATTERN_FUNCTIONS

Functions allowed as a LIKE pattern.

POWER_OPERATORS

Power operators.

PREDICATE_KEYWORDS

Keywords that can follow an operand in a predicate.

WKT_KEYWORDS

Geometry types that start a WKT literal.

class gws.lib.cql.parser.Node

Node types of the parse tree.

AND = 'AND'
ARRAY = 'ARRAY'
BETWEEN = 'BETWEEN'
BOOL = 'BOOL'
FLOAT = 'FLOAT'
FUNCTION = 'FUNCTION'
IN = 'IN'
INT = 'INT'
IS_NULL = 'IS_NULL'
LIKE = 'LIKE'
NAME = 'NAME'
NEG = 'NEG'
NOT = 'NOT'
NOT_BETWEEN = 'NOT_BETWEEN'
NOT_IN = 'NOT_IN'
NOT_LIKE = 'NOT_LIKE'
NOT_NULL = 'NOT_NULL'
OR = 'OR'
STRING = 'STRING'
USER_FUNCTION = 'USER_FUNCTION'
WKT = 'WKT'
gws.lib.cql.parser.parse(s: str)

Parse a CQL2-Text expression.

Parameters:

s – CQL2-Text expression.

Returns:

A parse tree of nested lists, see the package documentation.

Raises:

ParseError – If the expression is invalid.

gws.lib.cql.parser.parse_date(s: str) → gws.lib.datetimex.dt.date

Parse a date string.

Parameters:

s – A date in the form 2021-06-15.

Returns:

A date.

Raises:

ParseError – If the string is not a valid date.

gws.lib.cql.parser.parse_datetime(s: str, tz: str = '') → gws.lib.datetimex.dt.date

Parse a date or a timestamp string.

Parameters:
  • s – A date (2021-06-15) or an ISO timestamp, the zone is optional.

  • tz – Time zone for a timestamp without a zone, as in dtx.time_zone.

Returns:

A date if the string has no time part, an aware datetime otherwise.

Raises:

ParseError – If the string is invalid.

gws.lib.cql.parser.parse_timestamp(s: str, tz: str = '') → gws.lib.datetimex.dt.datetime

Parse an ISO timestamp string.

Parameters:
  • s – A timestamp, the zone is optional.

  • tz – Time zone for a timestamp without a zone, as in dtx.time_zone.

Returns:

An aware datetime.

Raises:

ParseError – If the string is invalid.

exception gws.lib.cql.parser.ParseError

Bases: Exception

A CQL2-Text expression or a date/timestamp string is invalid. The message contains the error position, if any.

gws.lib.cql.parser.RE_DATE = '^\\d{4}-\\d{2}-\\d{2}$'