misc + remove useless escaping in bracket

This commit is contained in:
Kyryl Melekhin
2021-08-10 11:02:35 +00:00
parent 6a3be3927e
commit 83f0a4d6f9
3 changed files with 7 additions and 12 deletions

1
README
View File

@@ -29,7 +29,6 @@ to that.
* Matcher does not take size of string as param, it checks for '\0' instead, * Matcher does not take size of string as param, it checks for '\0' instead,
so that the user does not need to waste time taking strlen() so that the user does not need to waste time taking strlen()
* Highly optimized source code, probably 2x faster than re1.5 * Highly optimized source code, probably 2x faster than re1.5
* Support for named character classes: \d \D \s \S \w \W was dropped cause it's redundant.
* Support for quoted chars in regex. * Support for quoted chars in regex.
* Support for ^, $ assertions in regex. * Support for ^, $ assertions in regex.
* Support for repetition operator {n} and {n,m}. * Support for repetition operator {n} and {n,m}.

12
pike.c
View File

@@ -86,8 +86,7 @@ enum
enum { enum {
RE_SUCCESS = 0, RE_SUCCESS = 0,
RE_SYNTAX_ERROR = -2, RE_SYNTAX_ERROR = -2,
RE_UNSUPPORTED_ESCAPE = -3, RE_UNSUPPORTED_SYNTAX = -3,
RE_UNSUPPORTED_SYNTAX = -4,
}; };
typedef struct rsub rsub; typedef struct rsub rsub;
@@ -229,12 +228,6 @@ static int _compilecode(const char **re_loc, rcode *prog, int sizecode)
prog->len++; prog->len++;
for (cnt = 0; *re != ']'; cnt++) { for (cnt = 0; *re != ']'; cnt++) {
if (!*re) goto syntax_error; if (!*re) goto syntax_error;
if (*re == '\\') {
re++;
if (!*re) goto syntax_error;
if (*re != '\\' && *re != ']')
goto unsupported_escape;
}
uc_code(c, re) EMIT(PC++, c); uc_code(c, re) EMIT(PC++, c);
uc_len(c, re) uc_len(c, re)
if (re[c] == '-' && re[c+1] != ']') if (re[c] == '-' && re[c+1] != ']')
@@ -398,9 +391,6 @@ static int _compilecode(const char **re_loc, rcode *prog, int sizecode)
syntax_error: syntax_error:
*re_loc = re; *re_loc = re;
return RE_SYNTAX_ERROR; return RE_SYNTAX_ERROR;
unsupported_escape:
*re_loc = re;
return RE_UNSUPPORTED_ESCAPE;
} }
int re_sizecode(const char *re) int re_sizecode(const char *re)

View File

@@ -103,6 +103,8 @@ qwerty.*$
(a|aa)* (a|aa)*
(a|aa)* (a|aa)*
(aaaa|aaa|a){3,4} (aaaa|aaa|a){3,4}
(a)(a)
(a){2}
" "
input="\ input="\
abcdef abcdef
@@ -207,6 +209,8 @@ aaaa
aaaaa aaaaa
aaaaaa aaaaaa
aaaaaaaaaa aaaaaaaaaa
aaaa
aaaa
" "
expect="\ expect="\
(0,3) (0,3)
@@ -311,6 +315,8 @@ expect="\
(0,5)(4,5) (0,5)(4,5)
(0,6)(5,6) (0,6)(5,6)
(0,10)(9,10) (0,10)(9,10)
(0,2)(0,1)(1,2)
(0,2)(1,2)
(0,0) (0,0)
" "