Skip to content

Commit

Permalink
Support for \S metachar.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimY4 committed Nov 13, 2024
1 parent 44f1c24 commit f0064f4
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions core/src/main/java/com/github/simy4/coregex/core/CoregexParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -391,7 +406,7 @@ private Coregex group(Context ctx) {

/*
* <pre>{@code
* falgs ::= 'd' | 'i' | 'm' | 's' | 'u' | 'U' | 'x'
* flags ::= 'd' | 'i' | 'm' | 's' | 'u' | 'U' | 'x'
* }</pre>
*/
private int flags(Context ctx) {
Expand Down Expand Up @@ -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('{');
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit f0064f4

Please sign in to comment.