From dace4443fa45dbe6c89eb82da993eb56469bd23f Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 8 Oct 2025 12:00:48 +0200 Subject: [PATCH] allow ESCAPE in the core language --- spec/src/antlr/JQL-core.g4 | 9 ++++++++- spec/src/antlr/JQL-full.g4 | 6 +++++- .../src/main/asciidoc/chapters/language/expressions.adoc | 7 ++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/spec/src/antlr/JQL-core.g4 b/spec/src/antlr/JQL-core.g4 index e54bcbe..65eee2f 100644 --- a/spec/src/antlr/JQL-core.g4 +++ b/spec/src/antlr/JQL-core.g4 @@ -53,7 +53,7 @@ conditional_expression comparison_expression : scalar_expression comparison_operator scalar_expression; between_expression : scalar_expression 'NOT'? 'BETWEEN' scalar_expression 'AND' scalar_expression; -like_expression : scalar_expression 'NOT'? 'LIKE' literal_pattern; +like_expression : scalar_expression 'NOT'? 'LIKE' escaped_pattern; comparison_operator : '=' @@ -64,6 +64,11 @@ comparison_operator | '<>' ; +escaped_pattern + : literal_pattern + ('ESCAPE' escape_character)? + ; + in_expression : simple_path_expression 'NOT'? 'IN' in_item_list; in_item_list : '(' in_item (',' in_item)* ')' ; in_item : literal | enum_literal | input_parameter; @@ -135,3 +140,5 @@ string_literal : STRING; literal_pattern : STRING; +escape_character : CHARACTER; + diff --git a/spec/src/antlr/JQL-full.g4 b/spec/src/antlr/JQL-full.g4 index 55cdf51..3f00c01 100644 --- a/spec/src/antlr/JQL-full.g4 +++ b/spec/src/antlr/JQL-full.g4 @@ -384,7 +384,11 @@ in_item like_expression : string_expression - 'NOT'? 'LIKE' pattern_value + 'NOT'? 'LIKE' escaped_pattern + ; + +escaped_pattern + : pattern_value ('ESCAPE' escape_character)? ; diff --git a/spec/src/main/asciidoc/chapters/language/expressions.adoc b/spec/src/main/asciidoc/chapters/language/expressions.adoc index 9166d44..df2222d 100644 --- a/spec/src/main/asciidoc/chapters/language/expressions.adoc +++ b/spec/src/main/asciidoc/chapters/language/expressions.adoc @@ -453,7 +453,7 @@ A `like` expression has syntax given by `like_expression`. - Its left operand must be an expression assigned some atomic type representing character strings. - Its right operand must be a pattern given as a literal string, with syntax `literal_pattern`, or, in the extended language, a <>. - +- Optionally, its right operand may specify an `escape_character` as a literal single character. If an implementation of Jakarta Query targets clients written in Java, it must allow expressions assigned the type `java.lang.String` as the left operand of a `like` expression. @@ -463,20 +463,17 @@ The expression is satisfied when its left operand evaluates to a non-null value - the `not` keyword occurs, and the value does not match the pattern. Matching is lexicographic. -Within the pattern, the characters `_` and `%` are interpreted as wildcards: +Within the pattern, the character bigram `''` is interpreted as a literal `'`, and the characters `_` and `%` are interpreted as wildcards: - `_` matches any single character, and - `%` matches any contiguous sequence of (zero or more) characters. Any other character occurring in the pattern is interpreted literally and matches only itself. -In the extended language, a `like_expression` may specify an `#escape_character#`. An escape character may be used to suppress the interpretation as a wildcard of a particular `_` or `%` character in the pattern. That is, if the escape character is `c`, then the character bigram `c_` is interpreted literally as the character `_`, the bigram `c%` as the character `%`, and the bigram `cc` as the character `c`. -**TODO** add the escape character to the core language because it is needed by Jakarta Data's Like constraint - [[equality-and-inequality]] ==== Equality and inequality operators