summaryrefslogtreecommitdiffstats
path: root/grammar
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2011-07-02 12:39:53 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2011-07-02 12:39:53 +0200
commit1ee14507b37bd7cb252341e7f6bdb6398407f1fd (patch)
treeb47951c56b97bb5e47ef1fa8c4ddeb126228c6c7 /grammar
parentaff06b40a68eeb88fb37a0ef67ab7be1b4aaf701 (diff)
downloadrsyslog-1ee14507b37bd7cb252341e7f6bdb6398407f1fd.tar.gz
rsyslog-1ee14507b37bd7cb252341e7f6bdb6398407f1fd.tar.xz
rsyslog-1ee14507b37bd7cb252341e7f6bdb6398407f1fd.zip
milestone: grammar for objects and cfsysline created
Diffstat (limited to 'grammar')
-rw-r--r--grammar/makefile11
-rw-r--r--grammar/rscript.l88
-rw-r--r--grammar/rscript.y57
-rw-r--r--grammar/utils.c77
-rw-r--r--grammar/utils.h52
5 files changed, 242 insertions, 43 deletions
diff --git a/grammar/makefile b/grammar/makefile
index 520d836b..29aab217 100644
--- a/grammar/makefile
+++ b/grammar/makefile
@@ -1,8 +1,11 @@
-rscript: lex.yy.c utils.o
- gcc -o rscript lex.yy.c utils.o -lestr -lfl
+rscript: lex.yy.c utils.o rscript.tab.h utils.h
+ gcc -o rscript lex.yy.c rscript.tab.c utils.o -lestr
-lex.yy.c: rscript.l
+lex.yy.c: rscript.l rscript.tab.h
flex rscript.l
-utils.o: utils.c
+rscript.tab.h: rscript.y
+ bison -d rscript.y
+
+utils.o: utils.c utils.h
gcc -c utils.c
diff --git a/grammar/rscript.l b/grammar/rscript.l
index f94ad43a..73843692 100644
--- a/grammar/rscript.l
+++ b/grammar/rscript.l
@@ -33,7 +33,10 @@
* compatible to the previous format.
*/
%{
+#include <ctype.h>
#include <libestr.h>
+#include "utils.h"
+#include "rscript.tab.h"
static int preCommentState;
%}
@@ -72,68 +75,76 @@ static int preCommentState;
"&" { printf("AMPER\n"); }
"ruleset" { printf("RULESET\n"); }
-"global"[ \n\t]*"(" { printf("OBJ GLOBAL begin\n");
- BEGIN INOBJ;
- }
-"input"[ \n\t]*"(" { printf("OBJ INPUT begin\n");
- BEGIN INOBJ;
- }
-"module"[ \n\t]*"(" { printf("OBJ MODULE begin\n");
- BEGIN INOBJ;
- }
-"action"[ \n\t]*"(" { printf("OBJ ACTION begin\n");
- BEGIN INOBJ;
- }
+"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; }
^[ \t]*:\$?[a-z]+[ ]*,[ ]*!?[a-z]+[ ]*,[ ]*\".*\" {
printf("PROP-FILT: '%s'\n", yytext);
}
-^[ \t]*[,\*a-z]+\.[,!=;\.\*a-z]+ { printf("PRI-FILT: '%s'\n", yytext);
- }
+^[ \t]*[,\*a-z]+\.[,!=;\.\*a-z]+ { printf("PRI-FILT: '%s'\n", yytext);
+ }
"*" |
\/[^*][^\n]* |
-[\|\.\-:][^\n]+ { printf("old style action: '%s'\n", yytext);
- }
+[\|\.\-:][^\n]+ { printf("old style action: '%s'\n", yytext);
+ }
-[a-z0-9_\-\+]+ { printf("name: '%s'\n", yytext); }
+[a-z0-9_\-\+]+ { printf("name: '%s'\n", yytext); }
-<INOBJ>")" { printf("OBJ end\n");
- BEGIN INITIAL;
- }
+<INOBJ>")" { printf("OBJ end\n");
+ BEGIN INITIAL;
+ return ENDOBJ;
+ }
<INOBJ>[a-z][a-z0-9_\.]* { printf("INOBJ: name '%s'\n", yytext);
- }
-<INOBJ>"=" { printf("INOBJ: equals\n");
- }
+ yylval.estr = es_newStrFromCStr(yytext, yyleng);
+ return NAME;
+ }
+<INOBJ>"=" { printf("INOBJ: equals (%s)\n", yytext);
+ return(yytext[0]);
+ }
<INOBJ>\"([^"\\]|\\['"?\\abfnrtv]|\\[0-7]{1,3})*\" {
- printf("INOBJ: value '%s'\n", yytext);
- BEGIN INOBJ;
- }
-"/*" { preCommentState = YY_START;
- BEGIN COMMENT;
- }
-<EXPR>"/*" { preCommentState = YY_START;
- BEGIN COMMENT;
- }
-<COMMENT>"*/" { BEGIN preCommentState; }
+ 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;
+ }
+<COMMENT>"*/" { BEGIN preCommentState; }
<COMMENT>([^*]|\n)+|.
<INOBJ>#.*\n /* skip comments in input */
<INOBJ>[ \n\t]
-<INOBJ>. { printf("INOBJ: invalid char '%s'\n", yytext); }
+<INOBJ>. { printf("INOBJ: invalid char '%s'\n", yytext); }
/* CFSYSLINE is valid in all modes */
-\$[a-z]+.*$ { printf("CFSYSLINE: '%s'\n", yytext); }
-<INOBJ>\$[a-z]+.*$ { printf("CFSYSLINE: '%s'\n", yytext); }
+\$[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;
+ }
\#.*\n /* skip comments in input */
[\n\t ] /* drop whitespace */
-. { printf("invalid char: %s\n", yytext);
- }
+. { printf("invalid char: %s\n", yytext);
+ }
/*<<EOF>> { printf("EOF reached\n"); }*/
%%
+ /*
int
main(int argc, char *argv[])
{
@@ -147,3 +158,4 @@ main(int argc, char *argv[])
//yy_switch_to_buffer(bp);
yylex();
}
+*/
diff --git a/grammar/rscript.y b/grammar/rscript.y
new file mode 100644
index 00000000..6954d38d
--- /dev/null
+++ b/grammar/rscript.y
@@ -0,0 +1,57 @@
+
+%{
+#include <stdio.h>
+#include <libestr.h>
+#include "utils.h"
+#define YYDEBUG 1
+%}
+
+%union {
+ char *s;
+ es_str_t *estr;
+ enum cnfobjType objType;
+ struct cnfobj *obj;
+ struct nvlst *nvlst;
+}
+
+%token <estr> NAME
+%token <estr> VALUE
+%token <objType> BEGINOBJ
+%token ENDOBJ
+%token <s> CFSYSLINE
+
+%type <nvlst> nv nvlst
+%type <obj> obj
+
+%%
+ /* conf: | conf global | conf action*/
+conf:
+ | obj conf
+ | cfsysline conf
+
+obj: BEGINOBJ nvlst ENDOBJ { printf("XXXX: global processed\n");
+ $$ = cnfobjNew($1, $2);
+ cnfobjPrint($$);
+ cnfobjDestruct($$);
+ }
+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;
+ }
+nv: NAME '=' VALUE { $$ = nvlstNew($1, $3); }
+
+%%
+int yyerror(char *s)
+{
+ printf("yyerror called: %s\n", s);
+}
+
+int main()
+{
+ yydebug = 0;
+ return yyparse();
+}
+
diff --git a/grammar/utils.c b/grammar/utils.c
index f9c50bc9..ccc9fbc7 100644
--- a/grammar/utils.c
+++ b/grammar/utils.c
@@ -1,7 +1,9 @@
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <ctype.h>
-#include "libestr.h"
+#include <libestr.h>
+#include "utils.h"
void
readConfFile(FILE *fp, es_str_t **str)
@@ -43,3 +45,76 @@ readConfFile(FILE *fp, es_str_t **str)
es_addChar(str, '\0');
es_addChar(str, '\0');
}
+
+struct nvlst*
+nvlstNew(es_str_t *name, es_str_t *value)
+{
+ struct nvlst *lst;
+
+ if((lst = malloc(sizeof(struct nvlst))) != NULL) {
+ lst->next = NULL;
+ lst->name = name;
+ lst->value = value;
+ }
+
+ return lst;
+}
+
+void
+nvlstDestruct(struct nvlst *lst)
+{
+ struct nvlst *toDel;
+
+ while(lst != NULL) {
+ toDel = lst;
+ lst = lst->next;
+ es_deleteStr(toDel->name);
+ es_deleteStr(toDel->value);
+ free(toDel);
+ }
+}
+
+
+void
+nvlstPrint(struct nvlst *lst)
+{
+ char *name, *value;
+ printf("nvlst %p:\n", lst);
+ while(lst != NULL) {
+ name = es_str2cstr(lst->name, NULL);
+ value = es_str2cstr(lst->value, NULL);
+ printf("\tname: '%s', value '%s'\n", name, value);
+ free(name);
+ free(value);
+ lst = lst->next;
+ }
+}
+
+struct cnfobj*
+cnfobjNew(enum cnfobjType objType, struct nvlst *lst)
+{
+ struct cnfobj *o;
+
+ if((o = malloc(sizeof(struct nvlst))) != NULL) {
+ o->objType = objType;
+ o->nvlst = lst;
+ }
+
+ return o;
+}
+
+void
+cnfobjDestruct(struct cnfobj *o)
+{
+ if(o != NULL) {
+ nvlstDestruct(o->nvlst);
+ free(o);
+ }
+}
+
+void
+cnfobjPrint(struct cnfobj *o)
+{
+ printf("obj: '%s'\n", cnfobjType2str(o->objType));
+ nvlstPrint(o->nvlst);
+}
diff --git a/grammar/utils.h b/grammar/utils.h
new file mode 100644
index 00000000..45176a50
--- /dev/null
+++ b/grammar/utils.h
@@ -0,0 +1,52 @@
+#ifndef INC_UTILS_H
+#define INC_UTILS_H
+#include <libestr.h>
+
+enum cnfobjType {
+ CNFOBJ_ACTION,
+ CNFOBJ_GLOBAL,
+ CNFOBJ_INPUT,
+ CNFOBJ_MODULE,
+ CNFOBJ_INVALID = 0
+};
+
+static inline char*
+cnfobjType2str(enum cnfobjType ot)
+{
+ switch(ot) {
+ case CNFOBJ_ACTION:
+ return "action";
+ break;
+ case CNFOBJ_GLOBAL:
+ return "global";
+ break;
+ case CNFOBJ_INPUT:
+ return "input";
+ break;
+ case CNFOBJ_MODULE:
+ return "module";
+ break;
+ default:return "error: invalid cnfobjType";
+ }
+}
+
+struct cnfobj {
+ enum cnfobjType objType;
+ struct nvlst *nvlst;
+};
+
+struct nvlst {
+ struct nvlst *next;
+ es_str_t *name;
+ es_str_t *value;
+};
+
+
+void readConfFile(FILE *fp, es_str_t **str);
+struct nvlst* nvlstNew(es_str_t *name, es_str_t *value);
+void nvlstDestruct(struct nvlst *lst);
+void nvlstPrint(struct nvlst *lst);
+struct cnfobj* cnfobjNew(enum cnfobjType objType, struct nvlst *lst);
+void cnfobjDestruct(struct cnfobj *o);
+void cnfobjPrint(struct cnfobj *o);
+#endif