Skip to content

Commit

Permalink
Handle boolean in ecql like cql_text
Browse files Browse the repository at this point in the history
For the moment

```python
    assert parse("attr = true") == ast.Equal(
        ast.Attribute("attr"),
        ast.Attribute("true"),
    )
```
like #96, use lark terminal
priority to ensure boolean are parsed as such and not as attribute.
  • Loading branch information
antoine-de committed Aug 29, 2024
1 parent e9b6757 commit 885ea29
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pygeofilter/parsers/ecql/grammar.lark
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ period: DATETIME "/" DATETIME

envelope: "ENVELOPE" "(" number number number number ")"

BOOLEAN: ( "TRUE" | "FALSE" )
BOOLEAN.2: ( "TRUE"i | "FALSE"i )

DOUBLE_QUOTED: "\"" /.*?/ "\""
SINGLE_QUOTED: "'" /.*?/ "'"
Expand Down
2 changes: 1 addition & 1 deletion pygeofilter/parsers/ecql/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def FLOAT(self, value):
return float(value)

def BOOLEAN(self, value):
return value == "TRUE"
return value.lower() == "true"

def DOUBLE_QUOTED(self, token):
return token[1:-1]
Expand Down
34 changes: 34 additions & 0 deletions tests/parsers/ecql/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ def test_namespace_attribute_eq_literal():
"A",
)


def test_prefixed_attribute_eq_literal():
result = parse("properties.ns:attr = 'A'")
assert result == ast.Equal(
ast.Attribute("properties.ns:attr"),
"A",
)


def test_attribute_eq_literal():
result = parse("attr = 'A'")
assert result == ast.Equal(
Expand Down Expand Up @@ -595,3 +597,35 @@ def test_function_attr_string_arg():
],
),
)


def test_attribute_eq_true_uppercase():
result = parse("attr = TRUE")
assert result == ast.Equal(
ast.Attribute("attr"),
True,
)


def test_attribute_eq_true_lowercase():
result = parse("attr = true")
assert result == ast.Equal(
ast.Attribute("attr"),
True,
)


def test_attribute_eq_false_uppercase():
result = parse("attr = FALSE")
assert result == ast.Equal(
ast.Attribute("attr"),
False,
)


def test_attribute_eq_false_lowercase():
result = parse("attr = false")
assert result == ast.Equal(
ast.Attribute("attr"),
False,
)

0 comments on commit 885ea29

Please sign in to comment.