summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authorvern <vern>1994-12-06 21:08:10 +0000
committervern <vern>1994-12-06 21:08:10 +0000
commitc648f2ee5f4b2bc68ce4ef63e9b8208465c09411 (patch)
treeb979e158ea6540806bcd23b206d16ad7397a119f /parse.y
parent57a946bc692683d157d468970288172ce163fda6 (diff)
downloadflex-c648f2ee5f4b2bc68ce4ef63e9b8208465c09411.tar.gz
added ccl exprs
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y42
1 files changed, 39 insertions, 3 deletions
diff --git a/parse.y b/parse.y
index 16a2ffd..b2e94d1 100644
--- a/parse.y
+++ b/parse.y
@@ -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.
@@ -30,7 +33,7 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-/* $Header: /cvsroot/flex/flex/parse.y,v 2.23 1994/11/24 16:43:31 vern Exp $ */
+/* $Header: /cvsroot/flex/flex/parse.y,v 2.24 1994/12/06 21:08:10 vern Exp $ */
/* Some versions of bison are broken in that they use alloca() but don't
@@ -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' )