a3
[idzebra-moved-to-github.git] / dfa / dfa.c
index 368d275..0a61093 100644 (file)
--- a/dfa/dfa.c
+++ b/dfa/dfa.c
@@ -4,7 +4,13 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: dfa.c,v $
- * Revision 1.7  1995-11-27 09:23:02  adam
+ * Revision 1.9  1995-12-06 12:24:58  adam
+ * Removed verbatim mode code.
+ *
+ * Revision 1.8  1995/12/06  09:09:58  adam
+ * Work on left and right anchors.
+ *
+ * Revision 1.7  1995/11/27  09:23:02  adam
  * New berbatim hook in regular expressions. "[]n ..".
  *
  * Revision 1.6  1995/10/16  09:31:25  adam
@@ -78,7 +84,6 @@ static struct DFA_parse *parse_info = NULL;
 static int err_code;
 static int inside_string;
 static const unsigned char *expr_ptr;
-static int expr_verbatim;
 static unsigned short *ctrl_chars;
 static struct Tnode **posar;
 
@@ -97,7 +102,6 @@ static void
     add_follow     (Set lastpos, Set firstpos),
     dfa_trav       (struct Tnode *n),
     init_followpos (void),
-    mk_dfa_tran    (struct DFA_states *dfas),
     pr_tran        (struct DFA_states *dfas),
     pr_verbose     (struct DFA_states *dfas),
     pr_followpos   (void),
@@ -232,7 +236,7 @@ static struct Tnode *expr_4 (void)
         break;
     case L_CHAR:
         t1 = mk_Tnode();
-        t1->pos = ++(parse_info->position);
+        t1->pos = ++parse_info->position;
         t1->u.ch[1] = t1->u.ch[0] = look_ch;
         lex ();
         break;
@@ -263,14 +267,12 @@ static struct Tnode *expr_4 (void)
     return t1;
 }
 
-static void do_parse (dfap, s, cc, tnp)
-struct DFA_parse *dfap;
-char **s;
-const unsigned short *cc;
-struct Tnode **tnp;
+static void do_parse (struct DFA_parse *dfap, char **s,
+                     const unsigned short *cc, struct Tnode **tnp)
 {
     int i;
-    struct Tnode *t1, *t2;
+    int anchor_flag = 0;
+    struct Tnode *t1, *t2, *tn;
 
     for (i=0; cc[i]; i +=2)
         ;
@@ -320,16 +322,47 @@ struct Tnode **tnp;
     parse_info = dfap;
     err_code = 0;
     expr_ptr = (unsigned char *) *s;
-    expr_verbatim = 0;
 
     inside_string = 0;
     lex ();
+    if (lookahead == L_START)
+    {
+        t2 = mk_Tnode ();
+        t2->pos = ++parse_info->position;
+        t2->u.ch[1] = t2->u.ch[0] = '\n';
+        anchor_flag = 1;
+        lex ();
+    }
     t1 = expr_1 ();
-    if (t1 && lookahead == 0)
+    if (anchor_flag)
+    {
+        tn = mk_Tnode ();
+        tn->pos = CAT;
+        tn->u.p[0] = t2;
+        tn->u.p[1] = t1;
+        t1 = tn;
+    }
+    if (lookahead == L_END && t1)
+    {
+        t2 = mk_Tnode ();
+        t2->pos = ++parse_info->position;
+        t2->u.ch[1] = t2->u.ch[0] = '\n';
+
+        tn = mk_Tnode ();
+        tn->pos = CAT;
+        tn->u.p[0] = t1;
+        tn->u.p[1] = t2;
+        t1 = tn;
+        
+        anchor_flag |= 2;
+        lex ();
+    }
+    if (lookahead == 0 && t1)
     {
         t2 = mk_Tnode();
         t2->pos = ++parse_info->position;
         t2->u.ch[0] = -(++parse_info->rule);
+        t2->u.ch[1] = anchor_flag;
         
         *tnp = mk_Tnode();
         (*tnp)->pos = CAT;
@@ -357,38 +390,18 @@ static int nextchar (int *esc)
     *esc = 0;
     if (*expr_ptr == '\0' || isspace(*expr_ptr))
         return 0;
-    else if (*expr_ptr != '\\' || expr_verbatim)
-    {
-        if (*expr_ptr == '[' && expr_ptr[1] == ']' && !expr_verbatim)
-        {
-            int i = 2;
-            int val = 0;
-            while (expr_ptr[i] >= '0' && expr_ptr[i] <= '9')
-                val = val*10 + expr_ptr[i++]-'0';
-            if (i > 2)
-            {
-                if (expr_ptr[i] == ' ')
-                    i++;
-                expr_verbatim = val;
-                expr_ptr += i;
-            }
-        }
-        if (expr_verbatim)
-        {
-            assert (expr_verbatim > 0);
-            *esc = 1;
-            --expr_verbatim;
-        }
+    else if (*expr_ptr != '\\')
         return *expr_ptr++;
-    }
     *esc = 1;
     switch (*++expr_ptr)
     {
     case '\r':
     case '\n':
-    case '\t':
     case '\0':
         return '\\';
+    case '\t':
+        ++expr_ptr;
+        return ' ';
     case 'n':
         ++expr_ptr;
         return '\n';