libregexp: miscellaneous little cleanups

front
spew 2017-04-30 15:08:36 -05:00
parent c00c60d327
commit ff8ae67b70
3 changed files with 23 additions and 27 deletions

View File

@ -210,6 +210,8 @@ if
is not matched. is not matched.
.SH BUGS .SH BUGS
There is no way to specify or match a NUL character; NULs terminate patterns and strings. There is no way to specify or match a NUL character; NULs terminate patterns and strings.
The size of a character class and the number of sub-expression matches are hard-coded
limits. The library uses the worst-case space estimate for allocating VM runtime threads.
.SH HISTORY .SH HISTORY
.IR Regexp (2) .IR Regexp (2)
first appeared in Plan 9 from Bell Labs. This implementation was written from first appeared in Plan 9 from Bell Labs. This implementation was written from

View File

@ -308,7 +308,7 @@ getnextr(Parselex *l)
{ {
l->literal = 0; l->literal = 0;
if(l->done) { if(l->done) {
l->rune = 0; l->rune = L'\0';
return; return;
} }
l->rawexp += chartorune(&l->rune, l->rawexp); l->rawexp += chartorune(&l->rune, l->rawexp);
@ -327,7 +327,7 @@ getnextrlit(Parselex *l)
l->literal = 1; l->literal = 1;
if(l->done) { if(l->done) {
l->literal = 0; l->literal = 0;
l->rune = 0; l->rune = L'\0';
return; return;
} }
l->rawexp += chartorune(&l->rune, l->rawexp); l->rawexp += chartorune(&l->rune, l->rawexp);
@ -347,7 +347,7 @@ lex(Parselex *l)
if(l->literal) if(l->literal)
return l->peeklex = LRUNE; return l->peeklex = LRUNE;
switch(l->rune){ switch(l->rune){
case 0: case L'\0':
return l->peeklex = LEND; return l->peeklex = LEND;
case L'*': case L'*':
case L'?': case L'?':
@ -375,16 +375,20 @@ lex(Parselex *l)
static int static int
pcmp(void *va, void *vb) pcmp(void *va, void *vb)
{ {
vlong n;
Rune *a, *b; Rune *a, *b;
a = va; a = va;
b = vb; b = vb;
n = (vlong)b[0] - (vlong)a[0]; if(a[0] < b[0])
if(n) return 1;
return n; if(a[0] > b[0])
return (vlong)b[1] - (vlong)a[1]; return -1;
if(a[1] < b[1])
return 1;
if(a[1] > b[1])
return -1;
return 0;
} }
static void static void
@ -460,7 +464,7 @@ getclass(Parselex *l)
q[2] = 0; q[2] = 0;
} }
/* classes are in descending order */ /* classes are in descending order see pcmp */
static Renode* static Renode*
buildclassn(Parselex *l) buildclassn(Parselex *l)
{ {

View File

@ -23,7 +23,7 @@ enum {
TSTAR, TSTAR,
TSUB, TSUB,
NSUBEXPM = 32 NSUBEXPM = 32,
}; };
typedef struct Parselex Parselex; typedef struct Parselex Parselex;
@ -31,30 +31,22 @@ typedef struct Renode Renode;
struct Parselex { struct Parselex {
/* Parse */ /* Parse */
Renode *next; Renode *next, *nodes;
Renode *nodes; int sub, instrs;
int sub;
int instrs;
jmp_buf exitenv; jmp_buf exitenv;
/* Lex */ /* Lex */
void (*getnextr)(Parselex*); void (*getnextr)(Parselex*);
char *rawexp; char *rawexp, *orig;
char *orig;
Rune rune; Rune rune;
Rune peek; int peek, peeklex, done, literal, nc;
int peeklex;
int done;
int literal;
Rune cpairs[400+2]; Rune cpairs[400+2];
int nc;
}; };
struct Renode { struct Renode {
int op; int op;
Renode *left; Renode *left;
Rune r; Rune r;
union union {
{
Rune r1; Rune r1;
int sub; int sub;
Renode *right; Renode *right;
@ -73,13 +65,11 @@ struct Reinst {
char op; char op;
int gen; int gen;
Reinst *a; Reinst *a;
union union {
{
Rune r; Rune r;
int sub; int sub;
}; };
union union {
{
Rune r1; Rune r1;
Reinst *b; Reinst *b;
}; };