acme, sam: fix regexp code for bigger Runemax

R=r
http://codereview.appspot.com/1765042
This commit is contained in:
Russ Cox 2010-07-14 11:10:59 -07:00
parent 75a851e927
commit 36d9b90c56
2 changed files with 50 additions and 46 deletions

View file

@ -20,7 +20,7 @@ Rune *lastregexp;
typedef struct Inst Inst; typedef struct Inst Inst;
struct Inst struct Inst
{ {
uint type; /* < 0x10000 ==> literal, otherwise action */ uint type; /* < OPERATOR ==> literal, otherwise action */
union { union {
int sid; int sid;
int subid; int subid;
@ -58,28 +58,30 @@ static Rangeset sempty;
/* /*
* Actions and Tokens * Actions and Tokens
* *
* 0x100xx are operators, value == precedence * 0x10000xx are operators, value == precedence
* 0x200xx are tokens, i.e. operands for operators * 0x20000xx are tokens, i.e. operands for operators
*/ */
#define OPERATOR 0x10000 /* Bitmask of all operators */ #define OPERATOR 0x1000000 /* Bit set in all operators */
#define START 0x10000 /* Start, used for marker on stack */ #define START (OPERATOR+0) /* Start, used for marker on stack */
#define RBRA 0x10001 /* Right bracket, ) */ #define RBRA (OPERATOR+1) /* Right bracket, ) */
#define LBRA 0x10002 /* Left bracket, ( */ #define LBRA (OPERATOR+2) /* Left bracket, ( */
#define OR 0x10003 /* Alternation, | */ #define OR (OPERATOR+3) /* Alternation, | */
#define CAT 0x10004 /* Concatentation, implicit operator */ #define CAT (OPERATOR+4) /* Concatentation, implicit operator */
#define STAR 0x10005 /* Closure, * */ #define STAR (OPERATOR+5) /* Closure, * */
#define PLUS 0x10006 /* a+ == aa* */ #define PLUS (OPERATOR+6) /* a+ == aa* */
#define QUEST 0x10007 /* a? == a|nothing, i.e. 0 or 1 a's */ #define QUEST (OPERATOR+7) /* a? == a|nothing, i.e. 0 or 1 a's */
#define ANY 0x20000 /* Any character but newline, . */ #define ANY 0x2000000 /* Any character but newline, . */
#define NOP 0x20001 /* No operation, internal use only */ #define NOP (ANY+1) /* No operation, internal use only */
#define BOL 0x20002 /* Beginning of line, ^ */ #define BOL (ANY+2) /* Beginning of line, ^ */
#define EOL 0x20003 /* End of line, $ */ #define EOL (ANY+3) /* End of line, $ */
#define CCLASS 0x20004 /* Character class, [] */ #define CCLASS (ANY+4) /* Character class, [] */
#define NCCLASS 0x20005 /* Negated character class, [^] */ #define NCCLASS (ANY+5) /* Negated character class, [^] */
#define END 0x20077 /* Terminate: match found */ #define END (ANY+0x77) /* Terminate: match found */
#define ISATOR 0x10000 #define ISATOR OPERATOR
#define ISAND 0x20000 #define ISAND ANY
#define QUOTED 0x4000000 /* Bit set for \-ed lex characters */
/* /*
* Parser Information * Parser Information
@ -453,7 +455,7 @@ nextrec(void)
exprp++; exprp++;
return '\n'; return '\n';
} }
return *exprp++|0x10000; return *exprp++|QUOTED;
} }
return *exprp++; return *exprp++;
} }
@ -493,7 +495,7 @@ bldcclass(void)
classp[n+2] = c2; classp[n+2] = c2;
n += 3; n += 3;
}else }else
classp[n++] = c1; classp[n++] = c1 & ~QUOTED;
} }
classp[n] = 0; classp[n] = 0;
if(nclass == Nclass){ if(nclass == Nclass){

View file

@ -9,7 +9,7 @@ typedef struct Inst Inst;
struct Inst struct Inst
{ {
long type; /* < 0x10000 ==> literal, otherwise action */ long type; /* < OPERATOR ==> literal, otherwise action */
union { union {
int rsid; int rsid;
int rsubid; int rsubid;
@ -53,28 +53,30 @@ static Rangeset sempty;
/* /*
* Actions and Tokens * Actions and Tokens
* *
* 0x100xx are operators, value == precedence * 0x10000xx are operators, value == precedence
* 0x200xx are tokens, i.e. operands for operators * 0x20000xx are tokens, i.e. operands for operators
*/ */
#define OPERATOR 0x10000 /* Bitmask of all operators */ #define OPERATOR 0x1000000 /* Bit set in all operators */
#define START 0x10000 /* Start, used for marker on stack */ #define START (OPERATOR+0) /* Start, used for marker on stack */
#define RBRA 0x10001 /* Right bracket, ) */ #define RBRA (OPERATOR+1) /* Right bracket, ) */
#define LBRA 0x10002 /* Left bracket, ( */ #define LBRA (OPERATOR+2) /* Left bracket, ( */
#define OR 0x10003 /* Alternation, | */ #define OR (OPERATOR+3) /* Alternation, | */
#define CAT 0x10004 /* Concatentation, implicit operator */ #define CAT (OPERATOR+4) /* Concatentation, implicit operator */
#define STAR 0x10005 /* Closure, * */ #define STAR (OPERATOR+5) /* Closure, * */
#define PLUS 0x10006 /* a+ == aa* */ #define PLUS (OPERATOR+6) /* a+ == aa* */
#define QUEST 0x10007 /* a? == a|nothing, i.e. 0 or 1 a's */ #define QUEST (OPERATOR+7) /* a? == a|nothing, i.e. 0 or 1 a's */
#define ANY 0x20000 /* Any character but newline, . */ #define ANY 0x2000000 /* Any character but newline, . */
#define NOP 0x20001 /* No operation, internal use only */ #define NOP (ANY+1) /* No operation, internal use only */
#define BOL 0x20002 /* Beginning of line, ^ */ #define BOL (ANY+2) /* Beginning of line, ^ */
#define EOL 0x20003 /* End of line, $ */ #define EOL (ANY+3) /* End of line, $ */
#define CCLASS 0x20004 /* Character class, [] */ #define CCLASS (ANY+4) /* Character class, [] */
#define NCCLASS 0x20005 /* Negated character class, [^] */ #define NCCLASS (ANY+5) /* Negated character class, [^] */
#define END 0x20077 /* Terminate: match found */ #define END (ANY+0x77) /* Terminate: match found */
#define ISATOR 0x10000 #define ISATOR OPERATOR
#define ISAND 0x20000 #define ISAND ANY
#define QUOTED 0x4000000 /* Bit set for \-ed lex characters */
/* /*
* Parser Information * Parser Information
@ -459,7 +461,7 @@ nextrec(void){
exprp++; exprp++;
return '\n'; return '\n';
} }
return *exprp++|0x10000; return *exprp++|QUOTED;
} }
return *exprp++; return *exprp++;
} }
@ -499,7 +501,7 @@ bldcclass(void)
classp[n+2] = c2; classp[n+2] = c2;
n += 3; n += 3;
}else }else
classp[n++] = c1; classp[n++] = c1 & ~QUOTED;
} }
classp[n] = 0; classp[n] = 0;
if(nclass == Nclass){ if(nclass == Nclass){