Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/requela/grammar.lark
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,18 @@ literal: BOOLEAN
| DATE
| FLOAT
| INT
| QUOTED_STRING
| DOUBLE_QUOTED_STRING
| UNQUOTED_VAL
| UUID

# Tuple of values for IN operations: (value1, value2, ...)
tuple: "(" literal ("," literal)* ")"

# Terminal definitions
# Date and datetime terminals with higher priority
# Quoted strings, date, datetime and uuids terminals with higher priority
QUOTED_STRING.3: /'[^']*'/
DOUBLE_QUOTED_STRING.3: /"[^"]*"/
DATETIME.3: /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})/
DATE.3: /\d{4}-\d{2}-\d{2}/
UUID.3: /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/ # increase priority to ensure that UUIDs are matched before generic PROP
Expand All @@ -114,6 +118,8 @@ PROP: /[a-zA-Z_][\w\-\.]*/ # Property names: letters, numbers, underscore, dash
# Unquoted value that can contain spaces, wildcards, and other special chars
UNQUOTED_VAL: /[^(),]+/



# Import and ignore whitespace
%import common.WS
%ignore WS
%ignore WS
10 changes: 10 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ def test_parser():
assert ast is not None


def test_parser_with_quoted_string():
ast = parse("eq(id,'000000-0d68-4494-a62e-2d4b6973bd37')")
assert ast is not None


def test_parser_with_double_quoted_string():
ast = parse('eq(name,"John Doe")')
assert ast is not None


def test_parser_invalid():
with pytest.raises(ValueError, match="Invalid RQL query: Unexpected token"):
parse("eq(name,John")
Loading