Skip to content

Commit

Permalink
Merge pull request #96 from duckontheweb/fix-cql2-text-booleanliteral
Browse files Browse the repository at this point in the history
Fix parsing of booleanLiterals in cql2-text
  • Loading branch information
constantinius authored Jul 8, 2024
2 parents 90f4aaa + 2a51990 commit d51dbb0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pygeofilter/parsers/cql2_text/grammar.lark
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func.2: attribute "(" expression ("," expression)* ")" -> function

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

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

DOUBLE_QUOTED: "\"" /.*?/ "\""
SINGLE_QUOTED: "'" /.*?/ "'"
Expand Down
4 changes: 2 additions & 2 deletions pygeofilter/parsers/cql2_text/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ def INT(self, value):
def FLOAT(self, value):
return float(value)

def boolean(self, value):
return value in ("TRUE", "true", "T", "t", "1")
def BOOLEAN(self, value):
return value.lower() == "true"

def DOUBLE_QUOTED(self, token):
return token[1:-1]
Expand Down
33 changes: 33 additions & 0 deletions tests/parsers/cql2_text/test_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from pygeofilter import ast
from pygeofilter.parsers.cql2_text import parse


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 d51dbb0

Please sign in to comment.