OSSP CVS Repository

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

Check-in Number: 1286
Date: 2001-Nov-08 22:58:00 (local)
2001-Nov-08 21:58:00 (UTC)
User:rse
Branch:
Comment: Enhance the specification parser to be more smart in parsing parameter values in order to remove the burden on the user to provide massive syntactic sugar.

One now can name=value or name="value" or even name=va"lu"e, i.e., do not require quotation marks. But if they are present they can be used to introduce spaces or special characters with \xXX notation.

Tickets:
Inspections:
Files:
ossp-pkg/l2/Makefile.in      1.35 -> 1.36     1 inserted, 1 deleted
ossp-pkg/l2/l2_spec_parse.y      1.3 -> 1.4     8 inserted, 3 deleted
ossp-pkg/l2/l2_spec_scan.l      1.4 -> 1.5     78 inserted, 35 deleted
ossp-pkg/l2/l2_test.c      1.45 -> 1.46     6 inserted, 6 deleted

ossp-pkg/l2/Makefile.in 1.35 -> 1.36

--- Makefile.in  2001/11/08 20:28:22     1.35
+++ Makefile.in  2001/11/08 21:58:00     1.36
@@ -158,7 +158,7 @@
 l2_spec.c: l2_spec.h l2_spec_parse.h
 l2_spec_scan.lo: l2_spec_scan.c l2_spec_parse.h
 @M@l2_spec_scan.c: l2_spec_scan.l
-@M@     $(FLEX) -f -Pl2_spec_ -s -8 -B -ol2_spec_scan.c l2_spec_scan.l
+@M@     $(FLEX) -Pl2_spec_ -s -8 -B -ol2_spec_scan.c l2_spec_scan.l
 @M@l2_spec_parse.c l2_spec_parse.h: l2_spec_parse.y
 @M@     $(BISON) -d -k -pl2_spec_ -ol2_spec_parse.c l2_spec_parse.y
 


ossp-pkg/l2/l2_spec_parse.y 1.3 -> 1.4

--- l2_spec_parse.y      2001/11/08 09:28:35     1.3
+++ l2_spec_parse.y      2001/11/08 21:58:00     1.4
@@ -51,6 +51,10 @@
     do { l2_env_errorinfo(CTX->env, L2_ERR_ARG, "%s", msg); \
          CTX->rv = L2_ERR_ARG; } while (0)
 #define YYERROR_VERBOSE
+
+/* scanner state transition */
+extern void l2_spec_scan_push(l2_spec_ctx_t *, const char *state);
+extern void l2_spec_scan_pop(l2_spec_ctx_t *);
 %}
 
 /* parser options */
@@ -75,6 +79,7 @@
 
 /* list of scanner tokens */
 %token <cpValue>  T_ID
+%token <cpValue>  T_PARAM
 %token <cpValue>  T_STRING
 %token            T_OP_ARROW
 
@@ -221,9 +226,9 @@
         
 /* channel parameter */
 channel_param  
-    : T_ID '=' T_STRING { 
-          if ((CTX->rv = l2_channel_configure(CTX->chTmp, "%s=\"%s\"", $1, $3)) != L2_OK) {
-              l2_env_errorinfo(CTX->env, CTX->rv, "failed to configure channel with '%s=\"%s\"'", $1, $3);
+    : T_ID '=' { l2_spec_scan_push(CTX, "SS_PARAM"); } T_PARAM { l2_spec_scan_pop(CTX); } { 
+          if ((CTX->rv = l2_channel_configure(CTX->chTmp, "%s=\"%s\"", $1, $4)) != L2_OK) {
+              l2_env_errorinfo(CTX->env, CTX->rv, "failed to configure channel with '%s=\"%s\"'", $1, $4);
               YYERROR;
           }
       }


ossp-pkg/l2/l2_spec_scan.l 1.4 -> 1.5

--- l2_spec_scan.l       2001/11/08 09:33:37     1.4
+++ l2_spec_scan.l       2001/11/08 21:58:00     1.5
@@ -46,68 +46,98 @@
 
 /* scanner options */
 %pointer
+%option stack
 %option reentrant-bison
 %option never-interactive
 %option noyywrap
 
 /* scanner states */
-%x str
+%x SS_PARAM
+%x SS_PARAM_Q
 
 %%
 
     /* local variables */
-    char  caStr[2048];
-    char *cpStr = NULL;
+    char  caParam[2048];
+    char *cpParam = NULL;
 
-    /* whitespaces */
-[ \t\n]+ {
-    /* NOOP */
+    /* parameter value */
+<SS_PARAM>\" {
+    if (cpParam == NULL)
+        cpParam = caParam;
+    BEGIN(SS_PARAM_Q);
+}
+<SS_PARAM>\\. {
+    if (cpParam == NULL)
+        cpParam = caParam;
+    *cpParam++ = yytext[1];
 }
-
-    /* C-style strings ("...") */
-\" {
-    cpStr = caStr;
-    BEGIN(str);
-}   
-<str>\" {
-    BEGIN(INITIAL);
-    *cpStr = '\0';
-    yylval->cpValue = strdup(caStr);
-    return T_STRING;
-}   
-<str>\n {
+<SS_PARAM>[^ \t\r\n\\,)"]+ {
+    char *cp = yytext;
+    if (cpParam == NULL)
+        cpParam = caParam;
+    while (*cp != '\0')
+        *cpParam++ = *cp++;
+}
+<SS_PARAM>(.|\n) {
+    if (cpParam == NULL)
+        cpParam = caParam;
+    *cpParam = '\0';
+    yylval->cpValue = strdup(caParam);
+    cpParam = NULL;
+    yyless(0);
+    return T_PARAM;
+}
+<SS_PARAM_Q>\" {
+    BEGIN(SS_PARAM);
+}
+<SS_PARAM_Q>\n {
     l2_env_errorinfo(CTX->env, L2_ERR_ARG, "%s", "Unterminated string");
     CTX->rv = L2_ERR_ARG;
+    return 0;
 }   
-<str>\\[0-7]{1,3} {
+<SS_PARAM_Q>\\[0-7]{1,3} {
     unsigned int result;
     (void)sscanf(yytext+1, "%o", &result);
     if (result > 0xff) {
         l2_env_errorinfo(CTX->env, L2_ERR_ARG, "%s", "Escape sequence out of bound");
         CTX->rv = L2_ERR_ARG;
+        return 0;
     }
     else
-        *cpStr++ = result;
+        *cpParam++ = result;
 }
-<str>\\[0-9]+ {
-    l2_env_errorinfo(CTX->env, L2_ERR_ARG, "%s", "Bad escape sequence");
-    CTX->rv = L2_ERR_ARG;
+<SS_PARAM_Q>\\x[0-9a-fA-F]{2} {
+    unsigned int result;
+    (void)sscanf(yytext+1, "%x", &result);
+    if (result > 0xff) {
+        l2_env_errorinfo(CTX->env, L2_ERR_ARG, "%s", "Escape sequence out of bound");
+        CTX->rv = L2_ERR_ARG;
+        return 0;
+    }
+    else
+        *cpParam++ = result;
 }
-<str>\\n { *cpStr++ = '\n'; }
-<str>\\r { *cpStr++ = '\r'; }
-<str>\\t { *cpStr++ = '\t'; }
-<str>\\b { *cpStr++ = '\b'; }
-<str>\\f { *cpStr++ = '\f'; }
-<str>\\(.|\n) {
-    *cpStr++ = yytext[1];
+<SS_PARAM_Q>\\n { *cpParam++ = '\n'; }
+<SS_PARAM_Q>\\r { *cpParam++ = '\r'; }
+<SS_PARAM_Q>\\t { *cpParam++ = '\t'; }
+<SS_PARAM_Q>\\b { *cpParam++ = '\b'; }
+<SS_PARAM_Q>\\f { *cpParam++ = '\f'; }
+<SS_PARAM_Q>\\(.|\n) {
+    *cpParam++ = yytext[1];
 }
-<str>[^\\\n\"]+ {
+<SS_PARAM_Q>[^\\\"]+ {
     char *cp = yytext;
     while (*cp != '\0')
-        *cpStr++ = *cp++;
+        *cpParam++ = *cp++;
+}
+<SS_PARAM_Q>(.|\n) {
+    *cpParam++ = yytext[0];
 }
-<str>. {
-    *cpStr++ = yytext[1];
+
+    /* whitespaces */
+[ \t\n]+ {
+    /* NOOP */
 }
 
    /* operators */
@@ -128,6 +158,19 @@
 
 %%
 
+/* external scanner state transitions */
+void l2_spec_scan_push(l2_spec_ctx_t *ctx, const char *state);
+void l2_spec_scan_push(l2_spec_ctx_t *ctx, const char *state)
+{
+    if (strcmp(state, "SS_PARAM") == 0)
+        yy_push_state(SS_PARAM, ctx->yyscan);
+}
+void l2_spec_scan_pop(l2_spec_ctx_t *ctx);
+void l2_spec_scan_pop(l2_spec_ctx_t *ctx)
+{
+    yy_pop_state(ctx->yyscan);
+}
+
 /* buffer-based input routine */
 static int yyinput(l2_spec_ctx_t *ctx, char *buf, int max_size)
 {


ossp-pkg/l2/l2_test.c 1.45 -> 1.46

--- l2_test.c    2001/11/08 10:03:47     1.45
+++ l2_test.c    2001/11/08 21:58:00     1.46
@@ -83,12 +83,12 @@
 
 #if 1
     spec = "noop -> {"
-           "  filter(regex=\"hecking\", negate=\"0\")"
-           "  -> prefix(prefix=\"[%d-%m-%Y/%H:%M:%S] %L test[%P]: \", timezone=\"local\")"
-           "     -> buffer(size=\"800\")"
-           "        -> file(path=\"l2_test.log\",append=\"1\",perm=\"420\") ;"
-           "  syslog(ident=\"L2-Test\", facility=\"user\", "
-           "         remotehost=\"en1\", logpid=\"1\", target=\"remote\")"
+           "  filter(regex=hecking, negate=0)"
+           "  -> prefix(prefix=\"[%d-%m-%Y/%H:%M:%S] %L test[%P]: \", timezone=local)"
+           "     -> buffer(size=800)"
+           "        -> file(path=l2_test.log, append=1, perm=420) ;"
+           "  syslog(ident=L2-Test, facility=user, "
+           "         remotehost=en1, logpid=1, target=remote)"
            "}";
     fprintf(stderr, "configuring: %s\n", spec);
     if ((rv = l2_spec(&ch, env, spec)) != L2_OK)

CVSTrac 2.0.1