changeset 314:a4484c02cba5

add wordMode in regexParser
author mir3636
date Sat, 07 May 2016 18:38:54 +0900
parents 90ccd94906c0
children 66012db6a717
files regexParser/CeriumGrep.cc regexParser/regexParser.cc regexParser/regexParser.h
diffstat 3 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/regexParser/CeriumGrep.cc	Tue Feb 09 11:02:35 2016 +0900
+++ b/regexParser/CeriumGrep.cc	Sat May 07 18:38:54 2016 +0900
@@ -23,6 +23,7 @@
 
     RegexInfo ri;
     ri.stateNumber = 1;
+    ri.wordMode = true;
     for (int i = 1; i < argc; i++) {
         if (strcmp(argv[i],"-regex") == 0) {
             ri.ptr = (unsigned char*)argv[i+1]; i++;
@@ -40,6 +41,8 @@
             s.filename = filename = argv[i+1]; i++;
         } else if (strcmp(argv[i],"-ts") == 0) {
             ts = true;
+        } else if (strcmp(argv[i],"+word") == 0) {
+            ri.wordMode = false;
         }
     }
     if (!ri.ptr) return s;
--- a/regexParser/regexParser.cc	Tue Feb 09 11:02:35 2016 +0900
+++ b/regexParser/regexParser.cc	Sat May 07 18:38:54 2016 +0900
@@ -71,7 +71,16 @@
 static
 NodePtr literal(RegexInfoPtr ri) {
     CharClassPtr cc = createCharClassWord(ri);
-    token(ri);
+    if (ri->wordMode) {
+        unsigned char *word = ri->ptr - 1;
+        while (ri->tokenType == 'a') {
+            token(ri);
+        }
+        cc->cond.w.length = ri->ptr - word;
+        if (cc->cond.w.length > 1)
+            cc->cond.w.word = word;
+    } else 
+        token(ri);
     NodePtr n = createNode(ri,'a',cc,0,0);
     return n;
 }
--- a/regexParser/regexParser.h	Tue Feb 09 11:02:35 2016 +0900
+++ b/regexParser/regexParser.h	Sat May 07 18:38:54 2016 +0900
@@ -154,6 +154,7 @@
     unsigned char tokenType;
     unsigned char *tokenValue;
     int stateNumber;
+    bool wordMode;
 } RegexInfo, *RegexInfoPtr;
 
 typedef struct {