OSSP CVS Repository

ossp - Check-in [2241]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2241
Date: 2002-Jul-05 16:33:10 (local)
2002-Jul-05 14:33:10 (UTC)
User:rse
Branch:
Comment: Add support for Perl-like q(.)[^\1]\1 style quotations which allow one to place arbitrary stuff into a single syntax token. This is especially useful if you think about complex OSSP l2 or OSSP pcbe expressions which else had to be escaped into double- or single-quoted strings in order to be placed into a OSSP cfg syntax.
Tickets:
Inspections:
Files:
ossp-pkg/cfg/00TODO      1.1 -> 1.2     15 inserted, 2 deleted
ossp-pkg/cfg/cfg_syn.c      1.2 -> 1.3     2 inserted, 2 deleted
ossp-pkg/cfg/cfg_syn_scan.l      1.1 -> 1.2     88 inserted, 9 deleted
ossp-pkg/cfg/sample2.cfg      1.1 -> 1.2     1 inserted, 1 deleted

ossp-pkg/cfg/00TODO 1.1 -> 1.2

--- 00TODO       2002/07/03 13:25:34     1.1
+++ 00TODO       2002/07/05 14:33:10     1.2
@@ -1,4 +1,17 @@
+- newline in error message
+$ ./cfg_test sample2.cfg 
+ERROR: <line 7, column 1: `1b;
+<}> quu'>
+
+
+cfg_test in free(): warning: modified (chunk-) pointer
+
 - cfg_t
-- cfg_data.c
-- cfg_node_dump()
 - cfg_node_destroy() for whole tree
+
+rewrite-uri <regex> <subst> { <rewrite-cond> }
+
+rewrite-uri ^/(.*) /path/$1 --redirect=permanent "{
+    %{SOURCE} != "x" 
+}";
+


ossp-pkg/cfg/cfg_syn.c 1.2 -> 1.3

--- cfg_syn.c    2002/07/04 14:51:21     1.2
+++ cfg_syn.c    2002/07/05 14:33:10     1.3
@@ -144,8 +144,8 @@
     *cp++ = '\0';
 
     /* remember parsing error: part I (context part) */
-    cfg_fmt_sprintf(ctx->err_buf, sizeof(ctx->err_len), 
-                    "line %d, column %d: `%s'; %s",
+    cfg_fmt_sprintf(ctx->err_buf, ctx->err_len, 
+                    "line %d, column %d: `%s'",
                     line, column, cpBuf);
     free(cpBuf);
 


ossp-pkg/cfg/cfg_syn_scan.l 1.1 -> 1.2

--- cfg_syn_scan.l       2002/07/03 13:25:34     1.1
+++ cfg_syn_scan.l       2002/07/05 14:33:10     1.2
@@ -57,6 +57,8 @@
     yylloc->last += yyleng;
 #define YY_USER_ACTION_ROLLBACK \
     yylloc->last = yylloc->first
+
+static char closing_brace(char open);
 %}
 
 /* scanner options */
@@ -69,6 +71,8 @@
 /* scanner states */
 %x SS_DQ
 %x SS_SQ
+%x SS_FQ
+%x SS_PT
 %x SS_CO_C
 
 %%
@@ -76,6 +80,9 @@
     /* local variables */
     char  caStr[1024];
     char *cpStr = NULL;
+    int   nQuoteOpen;
+    char  cQuoteOpen;
+    char  cQuoteClose;
 
     /* whitespaces */
 [ \t\n]+ {
@@ -172,20 +179,70 @@
     *cpStr++ = yytext[1];
 }
 
-    /* plain text word */
-[^ \t\n;{}"']+ {
-    yylval->cpString = strdup(yytext);
-    return T_STRING;
+    /* flexible-quoted word (q(.)[^\1]\1)
+       the delimiting character has to one a special character c, i.e.,
+       one of !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ or in C code:
+       isprint(c) && !isspace(c) && !iscntrl(c) && !isalpha(i) && !isdigit(i)
+       */
+"q"[\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~] {
+    cpStr = caStr;
+    nQuoteOpen = 1;
+    cQuoteOpen = yytext[1];
+    cQuoteClose = closing_brace(yytext[1]);
+    BEGIN(SS_FQ);
+}
+<SS_FQ>\\[\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~] {
+    if (yytext[1] == cQuoteOpen || yytext[1] == cQuoteClose) {
+        *cpStr++ = yytext[1];
+    }
+    else {
+        *cpStr++ = yytext[0];
+        *cpStr++ = yytext[1];
+    }
+}
+<SS_FQ>[^\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~] {
+    char *cp = yytext;
+    while (*cp != '\0')
+        *cpStr++ = *cp++;
+}
+<SS_FQ>(.|\n) {
+    if (yytext[0] == cQuoteOpen)
+        nQuoteOpen++;
+    else if (yytext[0] == cQuoteClose)
+        nQuoteOpen--;
+    if (yytext[0] == cQuoteClose && nQuoteOpen == 0) {
+        *cpStr = '\0';
+        yylval->cpString = strdup(caStr);
+        BEGIN(INITIAL);
+        return T_STRING;
+    }
+    else {
+        *cpStr++ = yytext[0];
+    }
 }
 
    /* special tokens */
-";" { return T_SEP; }
-"{" { return T_OPEN; }
+";" { return T_SEP;   }
+"{" { return T_OPEN;  }
 "}" { return T_CLOSE; }
 
-   /* anything else is returned as is... */
-.|\n {
-    return yytext[0];
+    /* plain text word */
+(.|\n) {
+    cpStr = caStr;
+    *cpStr++ = yytext[0];
+    BEGIN(SS_PT);
+}
+<SS_PT>[^ \t\n;{}"']+ {
+    char *cp = yytext;
+    while (*cp != '\0')
+        *cpStr++ = *cp++;
+}
+<SS_PT>(.|\n) {
+    *cpStr = '\0';
+    yylval->cpString = strdup(caStr);
+    yyless(0);
+    BEGIN(INITIAL);
+    return T_STRING;
 }
 
 %%
@@ -218,3 +275,25 @@
     return n;
 }
 
+/* closing brace */
+static char closing_brace(char open)
+{
+    static struct {
+        char open;
+        char close;
+    } openclose[] = {
+        { '(', ')' },
+        { '{', '}' },
+        { '{', ']' },
+        { '<', '>' },
+        { '`', '\'' },
+    };
+    int i;
+
+    for (i = 0; i < sizeof(openclose)/sizeof(openclose[0]); i++) {
+        if (openclose[i].open == open)
+            return (char)openclose[i].close;
+    }
+    return open;
+}
+


ossp-pkg/cfg/sample2.cfg 1.1 -> 1.2

--- sample2.cfg  2002/07/04 14:51:21     1.1
+++ sample2.cfg  2002/07/05 14:33:10     1.2
@@ -1,6 +1,6 @@
 
 foo;
-bar1 "bar2 bar2b";
+bar1 q{ f{o}o } 'foo;' "bar2 bar2b";
 quux1 { 
     quux1a; 
     quux1b;

CVSTrac 2.0.1