Fixed handling of escape symbols in regex (issue 21)
Change-Id: Id78caf2071422183e29f8eb44686e6c5f4b55b0c
diff --git a/src/main/antlr/poliqarpplus/PoliqarpPlusLexer.g4 b/src/main/antlr/poliqarpplus/PoliqarpPlusLexer.g4
index 8648d87..b3bedb1 100644
--- a/src/main/antlr/poliqarpplus/PoliqarpPlusLexer.g4
+++ b/src/main/antlr/poliqarpplus/PoliqarpPlusLexer.g4
@@ -86,9 +86,13 @@
EMPTYREL : '@';
/* Regular expressions and Regex queries */
-fragment RE_char : ~('*' | '?' | '+' | '{' | '}' | '[' | ']'
- | '(' | ')' | '|' | '"' | ':' | '\'' | '\\');
+fragment RE_symbol : ~('*' | '?' | '+' | '{' | '}' | '[' | ']'
+ | '(' | ')' | '|' | '\\' | '"' | ':' | '\'');
+fragment RE_esc : '\\' ('.' | '*' | '?' | '+' | '{' | '}' | '[' | ']'
+ | '(' | ')' | '|' | '\\' | '"' | ':' | '\'');
+fragment RE_char : (RE_symbol | RE_esc );
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 ')')) '?';
diff --git a/src/main/antlr/poliqarpplus/PoliqarpPlusParser.g4 b/src/main/antlr/poliqarpplus/PoliqarpPlusParser.g4
index 1907773..571cf12 100644
--- a/src/main/antlr/poliqarpplus/PoliqarpPlusParser.g4
+++ b/src/main/antlr/poliqarpplus/PoliqarpPlusParser.g4
@@ -43,9 +43,9 @@
;
key
-: WORD
+: (WORD
| regex
-| NUMBER
+| NUMBER)
;
foundry
@@ -149,7 +149,7 @@
;
alignment
-: segment? (CARET segment)* CARET?
+: segment? ( (CARET segment)+ | CARET)
;
disjunction