Skip to content

booleanLiteral terminals parsed as attributes in cql2-text #95

Closed
@duckontheweb

Description

@duckontheweb

System Info

Python Version: 3.10

OS: macOS Ventura 13.6.6

pygeofilter Version: 0.2.1 (main branch)

Problem Description

According to the OGC CQL2 documentation, a value of TRUE (case-insensitive) should be interpreted as a booleanLiteral value (see CQL2-Text example 14). So, for example, in the following query we should interpret attr as an attribute and TRUE as a booleanLiteral that we are comparing attr against:

attr = TRUE

However, the current CQL2 Text parser interprets the value of TRUE as an attribute. This leads to errors when we try to translate the AST to a backend like SQLAlchemy.

Steps to Reproduce:

from pygeofilter import ast
from pygeofilter.parsers.cql2_text import parse

result = parse("attr = TRUE")
assert result == ast.Equal(
    ast.Attribute("attr"),
    True,
)
# Assertion fails. The actual object is
# ast.Equal(
#     ast.Attribute("attr"),
#     ast.Attribute("TRUE")
# )

Possible Solution

I will put up a PR shortly with a possible solution that uses Lark's terminal priority to ensure that values of TRUE/true/FALSE/false are parsed as booleanLiteral values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions