Improve quantifiers in regex
Change-Id: Ibc078b01673348416bd41a9a9dd2b5afc8cb2a43
Reviewed-on: https://korap.ids-mannheim.de/gerrit/c/KorAP/Koral/+/6024
Reviewed-by: Nils Diewald <nils@diewald-online.de>
diff --git a/Changes b/Changes
index dc38dac..7523e71 100644
--- a/Changes
+++ b/Changes
@@ -1,8 +1,9 @@
-0.38.2 2022-08-31
+0.38.2 2022-10-05
- [feature] Improve regex treatment of negative
character classes (diewald)
+ - [bugfix] Improve quantifiers in Regex (diewald)
-0.38.1 2022-10-05
+0.38.1 2022-01-07
- [security] Updated log4j (diewald)
- Fixed Annis OR group (resolved #96)
- [security] Updated jackson (diewald)
diff --git a/src/main/antlr/poliqarpplus/PoliqarpPlusLexer.g4 b/src/main/antlr/poliqarpplus/PoliqarpPlusLexer.g4
index 2189657..8871e98 100644
--- a/src/main/antlr/poliqarpplus/PoliqarpPlusLexer.g4
+++ b/src/main/antlr/poliqarpplus/PoliqarpPlusLexer.g4
@@ -101,13 +101,9 @@
fragment RE_alter : ((RE_char | ('(' RE_expr ')') | RE_chgroup) '|' RE_expr )+;
fragment RE_chgroup : '[' '^'? RE_char+ ']';
-fragment RE_quant : (RE_star | RE_plus | RE_occ) QMARK?;
-fragment RE_opt : (RE_char | RE_chgroup | ( '(' RE_expr ')')) '?';
-fragment RE_star : (RE_char | RE_chgroup | ( '(' RE_expr ')')) '*';
-fragment RE_plus : (RE_char | RE_chgroup | ( '(' RE_expr ')')) '+';
-fragment RE_occ : (RE_char | RE_chgroup | ( '(' RE_expr ')')) FOCC;
+fragment RE_quant : ('.' | RE_char | RE_chgroup | ( '(' RE_expr ')')) ('?' | '*' | '+' | FOCC) QMARK?;
fragment RE_group : '(' RE_expr ')';
-fragment RE_expr : ('.' | RE_char | RE_alter | RE_chgroup | RE_opt | RE_quant | RE_group | '^' )+;
+fragment RE_expr : ('.' | RE_char | RE_alter | RE_chgroup | RE_quant | RE_group | '^' )+;
fragment RE_dquote : ('"'|'„'|'“') (RE_expr | '\'' | ':' )* ('"'|'“'|'”');
REGEX : RE_dquote;
diff --git a/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/PoliqarpPlusQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/PoliqarpPlusQueryProcessorTest.java
index 675debc..c13c7f4 100644
--- a/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/PoliqarpPlusQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/PoliqarpPlusQueryProcessorTest.java
@@ -273,6 +273,12 @@
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
assertEquals("302", res.at("/errors/0/0").asText());
+
+ query = "\"?\"";
+ qs.setQuery(query, "poliqarpplus");
+ res = mapper.readTree(qs.toJSON());
+ System.err.println(qs.toJSON());
+ assertEquals(302, res.at("/errors/0/0").asInt());
}
@Test