Regular expression implementation.

Does not support [\w\D] type character ranges yet.
Has bugs in lookahead captures.
This commit is contained in:
Tor Andersson
2014-02-21 16:30:01 +01:00
parent 2ac601d07e
commit 8898715c83
4 changed files with 1035 additions and 39 deletions
+3
View File
@@ -26,6 +26,9 @@ jsdump.c : astnames.h opnames.h
js: build/main.o build/libjs.a
$(CC) -o $@ $^ -lm
re: regex.c utf.c utftype.c
$(CC) $(CFLAGS) -DTEST -o $@ $^
libjs.c : $(SRCS)
ls $(SRCS) | awk '{print "#include \""$$1"\""}' > $@
+1 -1
View File
@@ -14,7 +14,7 @@ void js_newregexp(js_State *J, const char *pattern, int flags)
obj = jsV_newobject(J, JS_CREGEXP, J->RegExp_prototype);
opts = REG_EXTENDED;
opts = 0;
if (flags & JS_REGEXP_I) opts |= REG_ICASE;
if (flags & JS_REGEXP_M) opts |= REG_NEWLINE;
+1010 -32
View File
File diff suppressed because it is too large Load Diff
+21 -6
View File
@@ -1,16 +1,31 @@
#ifndef regex_h
#define regex_h
#include <regex.h>
#define regcomp js_regcomp
#define regexec js_regexec
#define regfree js_regfree
typedef struct Reprog Reprog;
typedef struct {
typedef struct Resub Resub;
struct Resub {
const char *sp;
const char *ep;
} Resub;
};
Reprog *js_regcomp(const char *pattern, int cflags, const char **errorp);
int js_regexec(Reprog *prog, const char *string, int nmatch, Resub *pmatch, int eflags);
void js_regfree(Reprog *prog);
Reprog *regcomp(const char *pattern, int cflags, const char **errorp);
int regexec(Reprog *prog, const char *string, int nmatch, Resub *pmatch, int eflags);
void regfree(Reprog *prog);
enum {
/* regcomp flags */
REG_ICASE = 1,
REG_NEWLINE = 2
};
enum {
/* regexec flags */
REG_NOTBOL = 1,
REG_NOTEOL = 2
};
#endif