Skip to content

A_CONTAINS with cql2_text throws error #2363

@ka7eh

Description

@ka7eh

Description

I noticed A_CONTAINS doesn't work with cql2_text, though cql2_json can parse it.

Steps to Reproduce
Steps to reproduce the behavior:

> from pygeofilter.parsers.cql2_text.parser import parse
> parse("A_CONTAINS('values', ('a', 'b', 'c'))")
Traceback (most recent call last):
  File "~/pygeofilter/.venv/lib/python3.12/site-packages/lark/parsers/lalr_parser_state.py", line 77, in feed_token
    action, arg = states[state][token.type]
                  ~~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: 'COMMA'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/pygeofilter/pygeofilter/parsers/cql2_text/parser.py", line 212, in parse
    return parser.parse(cql_text)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "~/pygeofilter/.venv/lib/python3.12/site-packages/lark/lark.py", line 677, in parse
    return self.parser.parse(text, start=start, on_error=on_error)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/pygeofilter/.venv/lib/python3.12/site-packages/lark/parser_frontends.py", line 131, in parse
    return self.parser.parse(stream, chosen_start, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/pygeofilter/.venv/lib/python3.12/site-packages/lark/parsers/lalr_parser.py", line 42, in parse
    return self.parser.parse(lexer, start)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/pygeofilter/.venv/lib/python3.12/site-packages/lark/parsers/lalr_parser.py", line 88, in parse
    return self.parse_from_state(parser_state)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/pygeofilter/.venv/lib/python3.12/site-packages/lark/parsers/lalr_parser.py", line 111, in parse_from_state
    raise e
  File "~/pygeofilter/.venv/lib/python3.12/site-packages/lark/parsers/lalr_parser.py", line 102, in parse_from_state
    state.feed_token(token)
  File "~/pygeofilter/.venv/lib/python3.12/site-packages/lark/parsers/lalr_parser_state.py", line 80, in feed_token
    raise UnexpectedToken(token, expected, state=self, interactive_parser=None)
lark.exceptions.UnexpectedToken: Unexpected token Token('COMMA', ',') at line 1, column 26.
Expected one of: 
        * RPAR

Expected behavior

It should output this (per output of cql2_json for the same statement as json):

> from pygeofilter.parsers.cql2_text.parser import parse
> parse({"op": "a_contains", "args": [{"property": "values"}, ['a', 'b', 'c']]})
ArrayContains(lhs=ATTRIBUTE values, rhs=['a', 'b', 'c'])

Screenshots/Tracebacks
If applicable, add screenshots to help explain your problem.

Environment

  • OS: OSX (Tahoe 26)
  • Python version: 3.12
  • pygeoapi version: 0.4.0 on master (commit 6c8ebac75100cddf7df7a38c305964116ffac527)

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions