summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2011-07-02 18:32:35 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2011-07-02 18:32:35 +0200
commit62e95c10ba84871fd5ad97fccd75664b07620013 (patch)
tree805addae179d86fa10507205ebe6887e872b81a1
parent1ee14507b37bd7cb252341e7f6bdb6398407f1fd (diff)
downloadrsyslog-62e95c10ba84871fd5ad97fccd75664b07620013.tar.gz
rsyslog-62e95c10ba84871fd5ad97fccd75664b07620013.tar.xz
rsyslog-62e95c10ba84871fd5ad97fccd75664b07620013.zip
milestone: some support for rules in grammar
-rw-r--r--grammar/rscript.l118
-rw-r--r--grammar/rscript.y33
-rw-r--r--grammar/utils.c12
-rw-r--r--grammar/utils.h3
4 files changed, 85 insertions, 81 deletions
diff --git a/grammar/rscript.l b/grammar/rscript.l
index 73843692..ccc39a2f 100644
--- a/grammar/rscript.l
+++ b/grammar/rscript.l
@@ -43,82 +43,60 @@ static int preCommentState;
%%
/* keywords */
-"if" { printf("IF\n");
- BEGIN EXPR;
- }
-<EXPR>"then" { printf("THEN\n");
- BEGIN INITIAL;
- }
-<EXPR>"or" { printf("OR\n"); }
-<EXPR>"and" { printf("AND\n"); }
-<EXPR>"not" { printf("NOT\n"); }
-<EXPR>"(" { printf("LPAREN\n"); }
-<EXPR>")" { printf("RPAREN\n"); }
-<EXPR>"==" { printf("==\n"); }
-<EXPR>"<=" { printf("<=\n"); }
-<EXPR>">=" { printf(">=\n"); }
+"if" { printf("IF\n"); BEGIN EXPR; }
+<EXPR>"then" { printf("THEN\n"); BEGIN INITIAL; }
+<EXPR>"or" { printf("OR\n"); }
+<EXPR>"and" { printf("AND\n"); }
+<EXPR>"not" { printf("NOT\n"); }
+<EXPR>"(" { printf("LPAREN\n"); }
+<EXPR>")" { printf("RPAREN\n"); }
+<EXPR>"==" { printf("==\n"); }
+<EXPR>"<=" { printf("<=\n"); }
+<EXPR>">=" { printf(">=\n"); }
<EXPR>"!=" |
-<EXPR>"<>" { printf("!=\n"); }
-<EXPR>"<" { printf("<\n"); }
-<EXPR>">" { printf(">\n"); }
-<EXPR>"contains" { printf("CONTAINS\n"); }
-<EXPR>"contains_i" { printf("CONTAINS_I\n"); }
-<EXPR>"startswith" { printf("STARTSWITH\n"); }
-<EXPR>"startswith_i" { printf("STARTSWITH_I\n"); }
-<EXPR>-?0[0-7]+ { printf("NUMBER (oct) %s\n", yytext); }
-<EXPR>-?0x[0-7a-f] { printf("NUMBER (hex) %s\n", yytext); }
-<EXPR>-?([1-9][0-9]*|0) { printf("NUMBER (dec) %s\n", yytext); }
-<EXPR>\$[$!]{0,1}[a-z][a-z0-9\-_\.]* { printf("VARNAME: '%s'\n", yytext); }
-<EXPR>\'([^'\\]|\\['])*\' { printf("EXPR string: -%s-\n", yytext); }
+<EXPR>"<>" { printf("!=\n"); }
+<EXPR>"<" { printf("<\n"); }
+<EXPR>">" { printf(">\n"); }
+<EXPR>"contains" { printf("CONTAINS\n"); }
+<EXPR>"contains_i" { printf("CONTAINS_I\n"); }
+<EXPR>"startswith" { printf("STARTSWITH\n"); }
+<EXPR>"startswith_i" { printf("STARTSWITH_I\n"); }
+<EXPR>-?0[0-7]+ { printf("NUMBER (oct) %s\n", yytext); }
+<EXPR>-?0x[0-7a-f] { printf("NUMBER (hex) %s\n", yytext); }
+<EXPR>-?([1-9][0-9]*|0) { printf("NUMBER (dec) %s\n", yytext); }
+<EXPR>\$[$!]{0,1}[a-z][a-z0-9\-_\.]* { printf("VARNAME: '%s'\n", yytext); }
+<EXPR>\'([^'\\]|\\['])*\' { printf("EXPR string: -%s-\n", yytext); }
<EXPR>[ \t\n]
-<EXPR>. { printf("invalid char in expr: %s\n", yytext); }
-"&" { printf("AMPER\n"); }
-"ruleset" { printf("RULESET\n"); }
+<EXPR>. { printf("invalid char in expr: %s\n", yytext); }
+"&" { return '&'; }
+"ruleset" { printf("RULESET\n"); }
-"global"[ \n\t]*"(" { yylval.objType = CNFOBJ_GLOBAL;
- BEGIN INOBJ; return BEGINOBJ; }
-"input"[ \n\t]*"(" { yylval.objType = CNFOBJ_INPUT;
- BEGIN INOBJ; return BEGINOBJ; }
-"module"[ \n\t]*"(" { yylval.objType = CNFOBJ_MODULE;
- BEGIN INOBJ; return BEGINOBJ; }
-"action"[ \n\t]*"(" { yylval.objType = CNFOBJ_ACTION;
- BEGIN INOBJ; return BEGINOBJ; }
+"global"[ \n\t]*"(" { yylval.objType = CNFOBJ_GLOBAL;
+ BEGIN INOBJ; return BEGINOBJ; }
+"input"[ \n\t]*"(" { yylval.objType = CNFOBJ_INPUT;
+ BEGIN INOBJ; return BEGINOBJ; }
+"module"[ \n\t]*"(" { yylval.objType = CNFOBJ_MODULE;
+ BEGIN INOBJ; return BEGINOBJ; }
+"action"[ \n\t]*"(" { BEGIN INOBJ; return BEGIN_ACTION; }
^[ \t]*:\$?[a-z]+[ ]*,[ ]*!?[a-z]+[ ]*,[ ]*\".*\" {
- printf("PROP-FILT: '%s'\n", yytext);
- }
-
-^[ \t]*[,\*a-z]+\.[,!=;\.\*a-z]+ { printf("PRI-FILT: '%s'\n", yytext);
+ printf("PROP-FILT: '%s'\n", yytext);
}
+^[ \t]*[,\*a-z]+\.[,!=;\.\*a-z]+ { printf("token prifilt '%s'\n", yytext); yylval.s = strdup(yytext); return PRIFILT; }
+
"*" |
\/[^*][^\n]* |
-[\|\.\-:][^\n]+ { printf("old style action: '%s'\n", yytext);
- }
-
+[\|\.\-:][^\n]+ { printf("toke legacy_action '%s'\n", yytext);yylval.s = strdup(yytext); return LEGACY_ACTION; }
[a-z0-9_\-\+]+ { printf("name: '%s'\n", yytext); }
-
-<INOBJ>")" { printf("OBJ end\n");
- BEGIN INITIAL;
- return ENDOBJ;
- }
-<INOBJ>[a-z][a-z0-9_\.]* { printf("INOBJ: name '%s'\n", yytext);
- yylval.estr = es_newStrFromCStr(yytext, yyleng);
- return NAME;
- }
-<INOBJ>"=" { printf("INOBJ: equals (%s)\n", yytext);
- return(yytext[0]);
- }
+<INOBJ>")" { BEGIN INITIAL; return ENDOBJ; }
+<INOBJ>[a-z][a-z0-9_\.]* { yylval.estr = es_newStrFromCStr(yytext, yyleng);
+ return NAME; }
+<INOBJ>"=" { return(yytext[0]); }
<INOBJ>\"([^"\\]|\\['"?\\abfnrtv]|\\[0-7]{1,3})*\" {
- printf("INOBJ: value '%s'\n", yytext);
yylval.estr = es_newStrFromCStr(yytext+1, yyleng-2);
- return VALUE;
- }
-"/*" { preCommentState = YY_START;
- BEGIN COMMENT;
- }
-<EXPR>"/*" { preCommentState = YY_START;
- BEGIN COMMENT;
- }
+ return VALUE; }
+"/*" { preCommentState = YY_START; BEGIN COMMENT; }
+<EXPR>"/*" { preCommentState = YY_START; BEGIN COMMENT; }
<COMMENT>"*/" { BEGIN preCommentState; }
<COMMENT>([^*]|\n)+|.
@@ -127,14 +105,8 @@ static int preCommentState;
<INOBJ>. { printf("INOBJ: invalid char '%s'\n", yytext); }
/* CFSYSLINE is valid in all modes */
-\$[a-z]+.*$ { printf("CFSYSLINE: '%s'\n", yytext);
- yylval.s = yytext;
- return CFSYSLINE;
- }
-<INOBJ>\$[a-z]+.*$ { printf("CFSYSLINE: '%s'\n", yytext);
- yylval.s = yytext;
- return CFSYSLINE;
- }
+\$[a-z]+.*$ { yylval.s = yytext; return CFSYSLINE; }
+<INOBJ>\$[a-z]+.*$ { yylval.s = yytext; return CFSYSLINE; }
\#.*\n /* skip comments in input */
[\n\t ] /* drop whitespace */
diff --git a/grammar/rscript.y b/grammar/rscript.y
index 6954d38d..5bd8f0f9 100644
--- a/grammar/rscript.y
+++ b/grammar/rscript.y
@@ -19,30 +19,47 @@
%token <objType> BEGINOBJ
%token ENDOBJ
%token <s> CFSYSLINE
+%token BEGIN_ACTION
+%token <s> LEGACY_ACTION
+%token <s> PRIFILT
+%token <s> PROPFILT
%type <nvlst> nv nvlst
%type <obj> obj
+%type <s> actlst
+%type <s> act
%%
- /* conf: | conf global | conf action*/
-conf:
+conf: /* empty (to end recursion) */
| obj conf
| cfsysline conf
+ | rule conf
-obj: BEGINOBJ nvlst ENDOBJ { printf("XXXX: global processed\n");
- $$ = cnfobjNew($1, $2);
+obj: BEGINOBJ nvlst ENDOBJ { $$ = cnfobjNew($1, $2);
cnfobjPrint($$);
cnfobjDestruct($$);
}
+obj: BEGIN_ACTION nvlst ENDOBJ { struct cnfobj *t = cnfobjNew(CNFOBJ_ACTION, $2);
+ cnfobjPrint(t);
+ cnfobjDestruct(t);
+ printf("XXXX: this is an new-style action!\n");
+ }
cfsysline: CFSYSLINE { printf("XXXX: processing CFSYSLINE: %s\n", $1);
}
nvlst: { $$ = NULL; }
- | nvlst nv { printf("XXXX: nvlst $1: %p, $2 %p\n", $1,$2);
- $2->next = $1;
- $$ = $2;
- }
+ | nvlst nv { $2->next = $1; $$ = $2; }
nv: NAME '=' VALUE { $$ = nvlstNew($1, $3); }
+rule: PRIFILT actlst { printf("PRIFILT: %s\n", $1); free($1); }
+ | PROPFILT actlst
+
+actlst: act { printf("action (end actlst) %s\n", $1);$$=$1; }
+ | actlst '&' act { printf("in actionlist %s\n", $3); }
+act: BEGIN_ACTION nvlst ENDOBJ { $$ = "obj"; }
+ | LEGACY_ACTION { printf("legacy action: '%s'\n", $1);
+ /*free($1);*/
+ $$ = $1;}
+
%%
int yyerror(char *s)
{
diff --git a/grammar/utils.c b/grammar/utils.c
index ccc9fbc7..a505704f 100644
--- a/grammar/utils.c
+++ b/grammar/utils.c
@@ -118,3 +118,15 @@ cnfobjPrint(struct cnfobj *o)
printf("obj: '%s'\n", cnfobjType2str(o->objType));
nvlstPrint(o->nvlst);
}
+
+/* debug helper */
+void
+cstrPrint(char *text, es_str_t *estr)
+{
+ char *str;
+ printf("in cstrPrint, estr %p\n", estr);
+ str = es_str2cstr(estr, NULL);
+ printf("2: in cstrPrint, estr %p\n", estr);
+ printf("%s%s", text, str);
+ free(str);
+}
diff --git a/grammar/utils.h b/grammar/utils.h
index 45176a50..66b05647 100644
--- a/grammar/utils.h
+++ b/grammar/utils.h
@@ -49,4 +49,7 @@ void nvlstPrint(struct nvlst *lst);
struct cnfobj* cnfobjNew(enum cnfobjType objType, struct nvlst *lst);
void cnfobjDestruct(struct cnfobj *o);
void cnfobjPrint(struct cnfobj *o);
+
+/* debug helper */
+void cstrPrint(char *text, es_str_t *estr);
#endif