145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef re2c_re_h 245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define re2c_re_h 345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include <stdio.h> 545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "tools/re2c/token.h" 645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "tools/re2c/ins.h" 745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct extop { 945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org char op; 1045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int minsize; 1145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int maxsize; 1245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} ExtOp; 1345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 1445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct CharPtn { 1545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned int card; 1645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org struct CharPtn *fix; 1745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org struct CharPtn *nxt; 1845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} CharPtn; 1945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 2045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct CharSet { 2145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org CharPtn *fix; 2245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org CharPtn *freeHead, **freeTail; 2345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org CharPtn *rep[nChars]; 2445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org CharPtn ptn[nChars]; 2545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} CharSet; 2645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 2745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct Range { 2845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org struct Range *next; 2945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned int lb, ub; /* [lb,ub) */ 3045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} Range; 3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic void 3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgRange_init(Range *r, unsigned int l, unsigned int u) 3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->next = NULL; 3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->lb = l; 3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->ub = u; 3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic Range * 4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgRange_new(unsigned int l, unsigned int u) 4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org Range *r = malloc(sizeof(Range)); 4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->next = NULL; 4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->lb = l; 4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->ub = u; 4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return r; 4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic void 5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgRange_copy(Range *ro, const Range *r) 5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ro->next = NULL; 5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ro->lb = r->lb; 5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ro->ub = r->ub; 5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic Range * 5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgRange_new_copy(Range *r) 6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org Range *ro = malloc(sizeof(Range)); 6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ro->next = NULL; 6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ro->lb = r->lb; 6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ro->ub = r->ub; 6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return ro; 6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid Range_out(FILE *, const Range *); 6945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 7045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum { 7145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org NULLOP = 1, 7245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org MATCHOP, 7345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RULEOP, 7445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ALTOP, 7545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org CATOP, 7645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org CLOSEOP, 7745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org CLOSEVOP 7845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} RegExpType; 7945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 8045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct RegExp { 8145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RegExpType type; 8245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned int size; 8345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org union { 8445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* for MatchOp */ 8545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org Range *match; 8645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* for RuleOp */ 8745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org struct { 8845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org struct RegExp *exp; 8945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org struct RegExp *ctx; 9045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org Ins *ins; 9145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned int accept; 9245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org Token *code; 9345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned int line; 9445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } RuleOp; 9545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* for AltOp and CatOp*/ 9645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org struct { 9745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org struct RegExp *exp1, *exp2; 9845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } AltCatOp; 9945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* for CloseOp */ 10045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org struct RegExp *exp; 10145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /* for CloseVOp*/ 10245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org struct { 10345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org struct RegExp *exp; 10445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int min; 10545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int max; 10645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } CloseVOp; 10745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org } d; 10845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} RegExp; 10945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 11045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic RegExp * 11145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgRegExp_isA(RegExp *r, RegExpType t) 11245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 11345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return r->type == t ? r : NULL; 11445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 11545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 11645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid RegExp_split(RegExp*, CharSet*); 11745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid RegExp_calcSize(RegExp*, Char*); 11845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned int RegExp_fixedLength(RegExp*); 11945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid RegExp_compile(RegExp*, Char*, Ins*); 12045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid RegExp_display(RegExp*, FILE *); 12145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 12245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic RegExp * 12345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgRegExp_new_NullOp(void) 12445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 12545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RegExp *r = malloc(sizeof(RegExp)); 12645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->type = NULLOP; 12745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return r; 12845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 12945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 13045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic RegExp * 13145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgRegExp_new_MatchOp(Range *m) 13245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 13345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RegExp *r = malloc(sizeof(RegExp)); 13445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->type = MATCHOP; 13545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->d.match = m; 13645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return r; 13745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 13845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 13945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgRegExp *RegExp_new_RuleOp(RegExp*, RegExp*, Token*, unsigned int); 14045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 14145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic RegExp * 14245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgRegExp_new_AltOp(RegExp *e1, RegExp *e2) 14345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 14445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RegExp *r = malloc(sizeof(RegExp)); 14545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->type = ALTOP; 14645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->d.AltCatOp.exp1 = e1; 14745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->d.AltCatOp.exp2 = e2; 14845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return r; 14945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 15045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 15145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic RegExp * 15245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgRegExp_new_CatOp(RegExp *e1, RegExp *e2) 15345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 15445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RegExp *r = malloc(sizeof(RegExp)); 15545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->type = CATOP; 15645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->d.AltCatOp.exp1 = e1; 15745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->d.AltCatOp.exp2 = e2; 15845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return r; 15945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 16045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 16145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic RegExp * 16245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgRegExp_new_CloseOp(RegExp *e) 16345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 16445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RegExp *r = malloc(sizeof(RegExp)); 16545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->type = CLOSEOP; 16645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->d.exp = e; 16745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return r; 16845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 16945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 17045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstatic RegExp * 17145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgRegExp_new_CloseVOp(RegExp *e, int lb, int ub) 17245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{ 17345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org RegExp *r = malloc(sizeof(RegExp)); 17445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->type = CLOSEVOP; 17545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->d.CloseVOp.exp = e; 17645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->d.CloseVOp.min = lb; 17745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org r->d.CloseVOp.max = ub; 17845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org return r; 17945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} 18045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 18145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgextern void genCode(FILE *, RegExp*); 18245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgextern RegExp *mkDiff(RegExp*, RegExp*); 18345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgextern RegExp *mkDot(void); 18445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgextern RegExp *strToRE(SubStr); 18545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgextern RegExp *strToCaseInsensitiveRE(SubStr); 18645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgextern RegExp *ranToRE(SubStr); 18745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgextern RegExp *invToRE(SubStr); 18845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 18945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgextern RegExp *mkAlt(RegExp*, RegExp*); 19045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 19145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif 192