Reinst* last;
} Node;
-/* max rune ranges per character class is nelem(classp->spans)/2 */
-#define NCCRUNE nelem(classp->spans)
+#define NSTACK 20
-static char* SrcExpr; /* pointer to next character in source expression */
+static char* SrcExpr; /* pointer to next character in source expression */
+static int CurrRune; /* last lex'd rune */
+static int CurrSubExpr; /* id of current subexpression */
+static bool LastWasOperand; /* Last token was operand */
+static jmp_buf LandingPad; /* longjmp() Landing pad for fatal errors */
+static int NParens; /* number of left parentheses seen so far */
+static int NClass; /* number of character classes seen so far */
-#define NSTACK 20
static Node OperandStack[NSTACK]; /* Stack of operands */
static Node* OperandPtr; /* Pointer to the top of the operand stack */
static int OperatorStack[NSTACK]; /* Stack of operators */
static int SubExprStack[NSTACK]; /* parallel to OperatorStack */
static int* SubExprPtr; /* Pointer to the top of the sub-expression stack */
-static int CurrSubExpr; /* id of current subexpression */
-static bool LastWasOperand; /* Last token was operand */
-static jmp_buf LandingPad;
-static int NParens;
-static int NClass;
-
static Reclass* classp;
static Reinst* freep;
-static int yyrune; /* last lex'd rune */
static Reclass* yyclassp; /* last lex'd class */
/* predeclared crap */
}
static int GetToken(int literal, int dot_type) {
- int quoted = NextRune(&yyrune);
+ int quoted = NextRune(&CurrRune);
if (literal || quoted) {
- if (yyrune == 0)
+ if (CurrRune == 0)
return END;
return RUNE;
}
- switch (yyrune) {
+ switch (CurrRune) {
case 0: return END;
case '*': return STAR;
case '?': return QUEST;
/******************************************************************************/
static int BuildClass(void) {
- int r[NCCRUNE];
+ int r[NCLASSSPANS];
int *p, *ep, *np;
int rune;
int quoted;
}
/* parse class into a set of spans */
- while (ep < &r[NCCRUNE-1]) {
+ while (ep < &r[NCLASSSPANS-1]) {
if (rune == 0) {
CompileError("malformed '[]'");
return 0;
}
quoted = NextRune(&rune);
}
- if (ep >= &r[NCCRUNE-1]) {
+ if (ep >= &r[NCLASSSPANS-1]) {
CompileError("char class too large; increase Reclass.spans size");
return 0;
}
if (t == CCLASS || t == NCCLASS)
i->r.cp = yyclassp;
if (t == RUNE)
- i->r.r = yyrune;
+ i->r.r = CurrRune;
PushOperand(i, i);
LastWasOperand = true;
#include "utf.h"
+enum {
+ NCLASSES = 16, /* maximum number of character classes in a regex */
+ NCLASSSPANS = 64, /* maximum number of spans in a character class */
+};
+
/* Sub expression matches */
typedef struct {
union {
/* character class, each pair of rune's defines a range */
typedef struct {
int* end;
- int spans[64];
+ int spans[NCLASSSPANS];
} Reclass;
/* Machine instructions */
typedef struct Reinst Reinst;
struct Reinst {
- int type;
+ int type; /* type of instruction */
union {
Reclass* cp; /* class pointer */
int r; /* character */
int subid; /* sub-expression id for RBRA and LBRA */
Reinst* right; /* right child of OR */
- }r;
+ } r;
union { /* regexp relies on these two being in the same union */
Reinst* left; /* left child of OR */
Reinst* next; /* next instruction for CAT & LBRA */
- }l;
+ } l;
};
-#define NCLASSES 16
-
/* Reprogram definition */
typedef struct {
Reinst* startinst; /* start pc */