From b7d05931d916649c0130f81584e74d7d3c7dce80 Mon Sep 17 00:00:00 2001 From: Francesco Faraone Date: Thu, 24 Apr 2025 09:31:57 +0200 Subject: [PATCH] MPT-9363 quoted strings are now supported --- src/requela/grammar.lark | 10 ++++++++-- tests/test_parser.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/requela/grammar.lark b/src/requela/grammar.lark index f25f1da..bc2c293 100644 --- a/src/requela/grammar.lark +++ b/src/requela/grammar.lark @@ -83,6 +83,8 @@ literal: BOOLEAN | DATE | FLOAT | INT + | QUOTED_STRING + | DOUBLE_QUOTED_STRING | UNQUOTED_VAL | UUID @@ -90,7 +92,9 @@ literal: BOOLEAN 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 @@ -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 \ No newline at end of file +%ignore WS diff --git a/tests/test_parser.py b/tests/test_parser.py index 864a789..94ef81c 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -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")