mirror of
https://github.com/ccxvii/mujs.git
synced 2026-09-22 15:13:35 +08:00
Regular expression implementation.
Does not support [\w\D] type character ranges yet. Has bugs in lookahead captures.
This commit is contained in:
@@ -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
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user