diff options
author | Vern Paxson <vern@ee.lbl.gov> | 1994-12-06 21:08:10 +0000 |
---|---|---|
committer | Vern Paxson <vern@ee.lbl.gov> | 1994-12-06 21:08:10 +0000 |
commit | f6bdfbde672453d307a8bbf97c541273499f7383 (patch) | |
tree | d559965dec2aab6aa6184ef9fe1dc77a8572cc12 /parse.y | |
parent | 00fabdc7f70c97161478e24dba47774044929cad (diff) |
added ccl exprs
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 40 |
1 files changed, 38 insertions, 2 deletions
@@ -3,6 +3,9 @@ %token CHAR NUMBER SECTEND SCDECL XSCDECL NAME PREVCCL EOF_OP %token OPTION_OP OPT_OUTFILE OPT_PREFIX +%token CCE_ALNUM CCE_ALPHA CCE_BLANK CCE_CNTRL CCE_DIGIT CCE_GRAPH +%token CCE_LOWER CCE_PRINT CCE_PUNCT CCE_SPACE CCE_UPPER CCE_XDIGIT + %{ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -68,7 +71,7 @@ char *alloca (); #include "flexdef.h" int pat, scnum, eps, headcnt, trailcnt, anyccl, lastchar, i, rulelen; -int trlcontxt, xcluflg, cclsorted, varlength, variable_trail_rule; +int trlcontxt, xcluflg, currccl, cclsorted, varlength, variable_trail_rule; int *scon_stk; int scon_stk_ptr; @@ -76,6 +79,18 @@ int scon_stk_ptr; static int madeany = false; /* whether we've made the '.' character class */ int previous_continued_action; /* whether the previous rule's action was '|' */ +/* Expand a POSIX character class expression. */ +#define CCL_EXPR(func) \ + { \ + int c; \ + for ( c = 0; c < csize; ++c ) \ + if ( isascii(c) && func(c) ) \ + ccladd( currccl, c ); \ + } + +/* While POSIX defines isblank(), it's not ANSI C. */ +#define IS_BLANK(c) ((c) == ' ' || (c) == '\t') + /* On some over-ambitious machines, such as DEC Alpha's, the default * token type is "long" instead of "int"; this leads to problems with * declaring yylval in flexdef.h. But so far, all the yacc's I've seen @@ -700,14 +715,35 @@ ccl : ccl CHAR '-' CHAR $$ = $1; } + | ccl ccl_expr + { + /* Too hard to properly maintain cclsorted. */ + cclsorted = false; + $$ = $1; + } + | { cclsorted = true; lastchar = 0; - $$ = cclinit(); + currccl = $$ = cclinit(); } ; +ccl_expr: CCE_ALNUM { CCL_EXPR(isalnum) } + | CCE_ALPHA { CCL_EXPR(isalpha) } + | CCE_BLANK { CCL_EXPR(IS_BLANK) } + | CCE_CNTRL { CCL_EXPR(iscntrl) } + | CCE_DIGIT { CCL_EXPR(isdigit) } + | CCE_GRAPH { CCL_EXPR(isgraph) } + | CCE_LOWER { CCL_EXPR(islower) } + | CCE_PRINT { CCL_EXPR(isprint) } + | CCE_PUNCT { CCL_EXPR(ispunct) } + | CCE_SPACE { CCL_EXPR(isspace) } + | CCE_UPPER { CCL_EXPR(isupper) } + | CCE_XDIGIT { CCL_EXPR(isxdigit) } + ; + string : string CHAR { if ( caseins && $2 >= 'A' && $2 <= 'Z' ) |