summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authorJohn Millaway <john43@users.sourceforge.net>2006-03-22 16:04:19 +0000
committerJohn Millaway <john43@users.sourceforge.net>2006-03-22 16:04:19 +0000
commitba6cb02a7bd77eced9d15a59bdf0e1ff1d8dee50 (patch)
tree7ea1a7ae8854be5e43c461387b1bb4ba79eba17b /parse.y
parenta6b8c36a85314758aae83a910b4e3cfea8560376 (diff)
Added negated character class expressions.
Documented negated character class expressions. Added regression test for negated character class expressions.
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y39
1 files changed, 37 insertions, 2 deletions
diff --git a/parse.y b/parse.y
index 0f56e04..e7c79cf 100644
--- a/parse.y
+++ b/parse.y
@@ -7,6 +7,8 @@
%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
+%token CCE_NEG_ALNUM CCE_NEG_ALPHA CCE_NEG_BLANK CCE_NEG_CNTRL CCE_NEG_DIGIT CCE_NEG_GRAPH
+%token CCE_NEG_LOWER CCE_NEG_PRINT CCE_NEG_PUNCT CCE_NEG_SPACE CCE_NEG_UPPER CCE_NEG_XDIGIT
/*
*POSIX and AT&T lex place the
* precedence of the repeat operator, {}, below that of concatenation.
@@ -125,6 +127,15 @@ int previous_continued_action; /* whether the previous rule's action was '|' */
ccladd( currccl, c ); \
}while(0)
+/* negated class */
+#define CCL_NEG_EXPR(func) \
+ do{ \
+ int c; \
+ for ( c = 0; c < csize; ++c ) \
+ if ( !func(c) ) \
+ ccladd( currccl, c ); \
+ }while(0)
+
/* While POSIX defines isblank(), it's not ANSI C. */
#define IS_BLANK(c) ((c) == ' ' || (c) == '\t')
@@ -872,7 +883,8 @@ ccl : ccl CHAR '-' CHAR
}
;
-ccl_expr: CCE_ALNUM { CCL_EXPR(isalnum); }
+ccl_expr:
+ CCE_ALNUM { CCL_EXPR(isalnum); }
| CCE_ALPHA { CCL_EXPR(isalpha); }
| CCE_BLANK { CCL_EXPR(IS_BLANK); }
| CCE_CNTRL { CCL_EXPR(iscntrl); }
@@ -882,13 +894,36 @@ ccl_expr: CCE_ALNUM { CCL_EXPR(isalnum); }
| CCE_PRINT { CCL_EXPR(isprint); }
| CCE_PUNCT { CCL_EXPR(ispunct); }
| CCE_SPACE { CCL_EXPR(isspace); }
+ | CCE_XDIGIT { CCL_EXPR(isxdigit); }
| CCE_UPPER {
if ( caseins )
CCL_EXPR(islower);
else
CCL_EXPR(isupper);
}
- | CCE_XDIGIT { CCL_EXPR(isxdigit); }
+
+ | CCE_NEG_ALNUM { CCL_NEG_EXPR(isalnum); }
+ | CCE_NEG_ALPHA { CCL_NEG_EXPR(isalpha); }
+ | CCE_NEG_BLANK { CCL_NEG_EXPR(IS_BLANK); }
+ | CCE_NEG_CNTRL { CCL_NEG_EXPR(iscntrl); }
+ | CCE_NEG_DIGIT { CCL_NEG_EXPR(isdigit); }
+ | CCE_NEG_GRAPH { CCL_NEG_EXPR(isgraph); }
+ | CCE_NEG_PRINT { CCL_NEG_EXPR(isprint); }
+ | CCE_NEG_PUNCT { CCL_NEG_EXPR(ispunct); }
+ | CCE_NEG_SPACE { CCL_NEG_EXPR(isspace); }
+ | CCE_NEG_XDIGIT { CCL_NEG_EXPR(isxdigit); }
+ | CCE_NEG_LOWER {
+ if ( caseins )
+ warn(_("[:^lower:] is ambiguous in case insensitive scanner"));
+ else
+ CCL_NEG_EXPR(islower);
+ }
+ | CCE_NEG_UPPER {
+ if ( caseins )
+ warn(_("[:^upper:] ambiguous in case insensitive scanner"));
+ else
+ CCL_NEG_EXPR(isupper);
+ }
;
string : string CHAR