]> granicus.if.org Git - re2c/commitdiff
- Make -bc work
authorhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 29 Apr 2007 22:23:29 +0000 (22:23 +0000)
committerhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 29 Apr 2007 22:23:29 +0000 (22:23 +0000)
re2c/bootstrap/scanner.cc
re2c/code.cc
re2c/test/condition_07.cbi.c [new file with mode: 0755]
re2c/test/condition_07.cbi.re [new file with mode: 0755]

index d93b4e873c28af89e2fffb0701d317f53a1b42d5..cdafd0d94ae5e21151e7a48d5c32da6ad35e9719 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.13.0.dev on Sat Apr 28 15:49:28 2007 */
+/* Generated by re2c 0.13.0.dev on Sun Apr 29 23:44:31 2007 */
 #line 1 "scanner.re"
 /* $Id$ */
 #include <stdlib.h>
index d01c2b302e2fa4b2b303316734a2bb6ee9a68dba..08a5428a9e58822f093827eeb8cdd0321a6a56f8 100644 (file)
@@ -1600,7 +1600,7 @@ void DFA::emit(std::ostream &o, uint& ind, const RegExpMap* specMap, const std::
                        o << "\n";
                }
        }
-       if (bFlag)
+       if (bFlag && !cFlag)
        {
                BitMap::gen(o, ind, lbChar, ubChar <= 256 ? ubChar : 256);
        }
@@ -1611,11 +1611,19 @@ void DFA::emit(std::ostream &o, uint& ind, const RegExpMap* specMap, const std::
                genCondGoto(o, ind, *specMap);
        }
 
-       if (cFlag && (bFlag || !condName.empty()))
+       if (cFlag)
        {
-               // TODO: Drop marker
-               o << "/* *********************************** */\n";
-               o << condPrefix << condName << ":\n";
+               if (!condName.empty())
+               {
+                       // TODO: Drop marker
+                       o << "/* *********************************** */\n";
+                       o << condPrefix << condName << ":\n";
+               }
+               if (bFlag && BitMap::first)
+               {
+                       o << indent(ind++) << "{\n";
+                       BitMap::gen(o, ind, lbChar, ubChar <= 256 ? ubChar : 256);
+               }
        }
 
        // TODO: Shouldn't labels 0 and 1 be variable?
@@ -1633,6 +1641,10 @@ void DFA::emit(std::ostream &o, uint& ind, const RegExpMap* specMap, const std::
                s->go.genGoto(o, ind, s, s->next, readCh);
        }
 
+       if (cFlag && bFlag && BitMap::first)
+       {
+               o << indent(--ind) << "}\n";
+       }
        // Generate epilog
        if (!cFlag || isLastCond)
        {
diff --git a/re2c/test/condition_07.cbi.c b/re2c/test/condition_07.cbi.c
new file mode 100755 (executable)
index 0000000..90b404f
--- /dev/null
@@ -0,0 +1,255 @@
+/* Generated by re2c */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define        BSIZE   8192
+
+typedef struct Scanner
+{
+       FILE                    *fp;
+       unsigned char   *cur, *tok, *lim, *eof;
+       unsigned char   buffer[BSIZE];
+} Scanner;
+
+int fill(Scanner *s, int len)
+{
+       if (!len)
+       {
+               s->cur = s->tok = s->lim = s->buffer;
+               s->eof = 0;
+       }
+       if (!s->eof)
+       {
+               int got, cnt = s->tok - s->buffer;
+
+               if (cnt > 0)
+               {
+                       memcpy(s->buffer, s->tok, s->lim - s->tok);
+                       s->tok -= cnt;
+                       s->cur -= cnt;
+                       s->lim -= cnt;
+               }
+               cnt = BSIZE - cnt;
+               if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt)
+               {
+                       s->eof = &s->lim[got];
+               }
+               s->lim += got;
+       }
+       else if (s->cur + len > s->eof)
+       {
+               return 0; /* not enough input data */
+       }
+       return -1;
+}
+
+void fputl(const char *s, size_t len, FILE *stream)
+{
+       while(len-- > 0)
+       {
+               fputc(*s++, stream);
+       }
+}
+
+
+enum YYCONDTYPE {
+       EStateR1,
+       EStateR2,
+};
+
+
+void scan(Scanner *s)
+{
+       int state = EStateR1;
+       
+       fill(s, 0);
+
+       for(;;)
+       {
+               s->tok = s->cur;
+
+               {
+                       unsigned char yych;
+                       if (state < 1) {
+                               goto yyc_R1;
+                       } else {
+                               goto yyc_R2;
+                       }
+/* *********************************** */
+yyc_R1:
+                       {
+                               static const unsigned char yybm[] = {
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                       128, 128, 128, 128, 128, 128, 128, 128, 
+                                       128, 128,   0,   0,   0,   0,   0,   0, 
+                                         0, 128, 128, 128, 128, 128, 128, 128, 
+                                       128, 128, 128, 128, 128, 128, 128, 128, 
+                                       128, 128, 128, 128, 128, 128, 128, 128, 
+                                       128, 128, 128,   0,   0,   0,   0,   0, 
+                                         0, 128, 128, 128, 128, 128, 128, 128, 
+                                       128, 128, 128, 128, 128, 128, 128, 128, 
+                                       128, 128, 128, 128, 128, 128, 128, 128, 
+                                       128, 128, 128,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                               };
+
+                               if((s->lim - s->cur) < 2) { if(fill(s, 2) >= 0) break; };
+                               yych = *s->cur;
+                               if(yych <= '@') {
+                                       if(yych <= '/') goto yy4;
+                                       if(yych >= ':') goto yy4;
+                               } else {
+                                       if(yych <= 'Z') goto yy2;
+                                       if(yych <= '`') goto yy4;
+                                       if(yych >= '{') goto yy4;
+                               }
+yy2:
+                               ++s->cur;
+                               yych = *s->cur;
+                               goto yy7;
+yy3:
+                               {
+                                       continue;
+                               }
+yy4:
+                               ++s->cur;
+                               {
+                                       continue;
+                               }
+yy6:
+                               ++s->cur;
+                               if(s->lim == s->cur) { if(fill(s, 1) >= 0) break; };
+                               yych = *s->cur;
+yy7:
+                               if(yybm[0+yych] & 128) {
+                                       goto yy6;
+                               }
+                               goto yy3;
+                       }
+/* *********************************** */
+yyc_R2:
+                       {
+                               static const unsigned char yybm[] = {
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                       128, 128, 128, 128, 128, 128, 128, 128, 
+                                       128, 128,   0,   0,   0,   0,   0,   0, 
+                                         0, 128, 128, 128, 128, 128, 128, 128, 
+                                       128, 128, 128, 128, 128, 128, 128, 128, 
+                                       128, 128, 128, 128, 128, 128, 128, 128, 
+                                       128, 128, 128,   0,   0,   0,   0,   0, 
+                                         0, 128, 128, 128, 128, 128, 128, 128, 
+                                       128, 128, 128, 128, 128, 128, 128, 128, 
+                                       128, 128, 128, 128, 128, 128, 128, 128, 
+                                       128, 128, 128,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                                         0,   0,   0,   0,   0,   0,   0,   0, 
+                               };
+                               if((s->lim - s->cur) < 2) { if(fill(s, 2) >= 0) break; };
+                               yych = *s->cur;
+                               if(yych <= '@') {
+                                       if(yych <= '/') goto yy12;
+                                       if(yych >= ':') goto yy12;
+                               } else {
+                                       if(yych <= 'Z') goto yy10;
+                                       if(yych <= '`') goto yy12;
+                                       if(yych >= '{') goto yy12;
+                               }
+yy10:
+                               ++s->cur;
+                               yych = *s->cur;
+                               goto yy15;
+yy11:
+                               {
+                                       continue;
+                               }
+yy12:
+                               ++s->cur;
+                               {
+                                       continue;
+                               }
+yy14:
+                               ++s->cur;
+                               if(s->lim == s->cur) { if(fill(s, 1) >= 0) break; };
+                               yych = *s->cur;
+yy15:
+                               if(yybm[0+yych] & 128) {
+                                       goto yy14;
+                               }
+                               goto yy11;
+                       }
+               }
+
+       }
+}
+
+int main(int argc, char **argv)
+{
+       Scanner in;
+       char c;
+
+       if (argc != 2)
+       {
+               fprintf(stderr, "%s <file>\n", argv[0]);
+               return 1;;
+       }
+
+       memset((char*) &in, 0, sizeof(in));
+
+       if (!strcmp(argv[1], "-"))
+       {
+               in.fp = stdin;
+       }
+       else if ((in.fp = fopen(argv[1], "r")) == NULL)
+       {
+               fprintf(stderr, "Cannot open file '%s'\n", argv[1]);
+               return 1;
+       }
+
+       scan(&in);
+
+       if (in.fp != stdin)
+       {
+               fclose(in.fp);
+       }
+       return 0;
+}
diff --git a/re2c/test/condition_07.cbi.re b/re2c/test/condition_07.cbi.re
new file mode 100755 (executable)
index 0000000..35f6250
--- /dev/null
@@ -0,0 +1,133 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define        BSIZE   8192
+
+typedef struct Scanner
+{
+       FILE                    *fp;
+       unsigned char   *cur, *tok, *lim, *eof;
+       unsigned char   buffer[BSIZE];
+} Scanner;
+
+int fill(Scanner *s, int len)
+{
+       if (!len)
+       {
+               s->cur = s->tok = s->lim = s->buffer;
+               s->eof = 0;
+       }
+       if (!s->eof)
+       {
+               int got, cnt = s->tok - s->buffer;
+
+               if (cnt > 0)
+               {
+                       memcpy(s->buffer, s->tok, s->lim - s->tok);
+                       s->tok -= cnt;
+                       s->cur -= cnt;
+                       s->lim -= cnt;
+               }
+               cnt = BSIZE - cnt;
+               if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt)
+               {
+                       s->eof = &s->lim[got];
+               }
+               s->lim += got;
+       }
+       else if (s->cur + len > s->eof)
+       {
+               return 0; /* not enough input data */
+       }
+       return -1;
+}
+
+void fputl(const char *s, size_t len, FILE *stream)
+{
+       while(len-- > 0)
+       {
+               fputc(*s++, stream);
+       }
+}
+
+/*!types:re2c */
+
+void scan(Scanner *s)
+{
+       int state = EStateR1;
+       
+       fill(s, 0);
+
+       for(;;)
+       {
+               s->tok = s->cur;
+/*!re2c
+
+re2c:define:YYCTYPE     = "unsigned char";
+re2c:define:YYCURSOR    = s->cur;
+re2c:define:YYLIMIT     = s->lim;
+re2c:define:YYMARKER    = s->tok;
+re2c:define:YYFILL:len  = #;
+re2c:define:YYFILL      = "{ if(fill(s, #) >= 0) break; }";
+re2c:define:YYCONDITION = state;
+re2c:yyfill:parameter   = 0;
+re2c:indent:top         = 2;
+re2c:condenumprefix     = EState;
+
+NUM            = [0-9];
+ALNUM  = NUM|[a-zA-Z];
+ANY            = [^];
+
+<R1>   ALNUM+
+                               {
+                                       continue;
+                               }
+<R1>   ANY
+                               {
+                                       continue;
+                               } 
+
+<R2>   ALNUM+
+                               {
+                                       continue;
+                               }
+<R2>   ANY
+                               {
+                                       continue;
+                               } 
+*/
+       }
+}
+
+int main(int argc, char **argv)
+{
+       Scanner in;
+       char c;
+
+       if (argc != 2)
+       {
+               fprintf(stderr, "%s <file>\n", argv[0]);
+               return 1;;
+       }
+
+       memset((char*) &in, 0, sizeof(in));
+
+       if (!strcmp(argv[1], "-"))
+       {
+               in.fp = stdin;
+       }
+       else if ((in.fp = fopen(argv[1], "r")) == NULL)
+       {
+               fprintf(stderr, "Cannot open file '%s'\n", argv[1]);
+               return 1;
+       }
+
+       scan(&in);
+
+       if (in.fp != stdin)
+       {
+               fclose(in.fp);
+       }
+       return 0;
+}