From f0064f4a24265653935e196ff147580259b278b7 Mon Sep 17 00:00:00 2001 From: SimY4 Date: Wed, 13 Nov 2024 14:56:37 +1000 Subject: [PATCH] Support for \S metachar. --- .../simy4/coregex/core/CoregexParser.java | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/com/github/simy4/coregex/core/CoregexParser.java b/core/src/main/java/com/github/simy4/coregex/core/CoregexParser.java index 2595155..915c4c8 100644 --- a/core/src/main/java/com/github/simy4/coregex/core/CoregexParser.java +++ b/core/src/main/java/com/github/simy4/coregex/core/CoregexParser.java @@ -165,8 +165,7 @@ private Coregex basicRE(Context ctx) { */ private Coregex elementaryRE(Context ctx) { Coregex elementaryRE; - char ch = ctx.peek(); - switch (ch) { + switch (ctx.peek()) { case '.': ctx.match('.'); elementaryRE = Coregex.any(ctx.flags); @@ -187,8 +186,24 @@ private Coregex elementaryRE(Context ctx) { break; case '\\': ctx.match('\\'); - ch = ctx.peek(); - elementaryRE = 'Q' == ch ? quoted(ctx) : new Coregex.Set(metachar(ctx)); + char ch = ctx.peek(); + switch (ch) { + case 'Q': + elementaryRE = quoted(ctx); + break; + case 'b': + case 'B': + case 'A': + case 'G': + case 'Z': + case 'z': + case 'k': + elementaryRE = ctx.unsupported("metacharacter \\" + ch + " is not supported"); + break; + default: + elementaryRE = new Coregex.Set(metachar(ctx)); + break; + } break; default: elementaryRE = literal(ctx); @@ -391,7 +406,7 @@ private Coregex group(Context ctx) { /* *
{@code
-   * falgs ::= 'd' | 'i' | 'm' | 's' | 'u' | 'U' | 'x'
+   * flags ::= 'd' | 'i' | 'm' | 's' | 'u' | 'U' | 'x'
    * }
*/ private int flags(Context ctx) { @@ -475,6 +490,10 @@ private Set metachar(Context ctx) { ctx.match('s'); metachar.set(' ', '\t'); break; + case 'S': + ctx.match('S'); + metachar.set('\r', '\n', '\t', '\f', ' ').negate(); + break; case 'p': ctx.match('p'); ctx.match('{'); @@ -535,16 +554,6 @@ private Set metachar(Context ctx) { metachar.single(quoted); } break; - case 'S': - case 'b': - case 'B': - case 'A': - case 'G': - case 'Z': - case 'z': - case 'k': - ctx.unsupported("metacharacter \\" + ch + " is not supported"); - break; default: if (isDigit(ch)) { ctx.unsupported("metacharacter \\" + ch + " is not supported");