diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2011-07-04 09:36:12 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2011-07-04 09:36:12 +0200 |
commit | 25cd9f59ad3a0daa2662e44b2e844116ad487450 (patch) | |
tree | 07dc9e1f4df3e8fe6d6d7a0d647e4c80e938fcd8 /grammar | |
parent | 71003f146cc2dacfa8fc7c084404f3399812b64a (diff) | |
download | rsyslog-25cd9f59ad3a0daa2662e44b2e844116ad487450.tar.gz rsyslog-25cd9f59ad3a0daa2662e44b2e844116ad487450.tar.xz rsyslog-25cd9f59ad3a0daa2662e44b2e844116ad487450.zip |
milestone: added comparison ops, prepring for flex include processing
Diffstat (limited to 'grammar')
-rw-r--r-- | grammar/mini.samp | 2 | ||||
-rw-r--r-- | grammar/parserif.h | 6 | ||||
-rw-r--r-- | grammar/rscript.l | 38 | ||||
-rw-r--r-- | grammar/rscript.y | 16 | ||||
-rw-r--r-- | grammar/utils.c | 40 |
5 files changed, 83 insertions, 19 deletions
diff --git a/grammar/mini.samp b/grammar/mini.samp index 8e00917f..71cfbb69 100644 --- a/grammar/mini.samp +++ b/grammar/mini.samp @@ -24,7 +24,7 @@ if 1 then { /var/log/log3 @@fwd rger } -if not 1==0 and 2*4/-5--(10-3)>7/*pri("*.*")*/ then { +if not (1==0) and 2*4/-5--(10-3)>7/*pri("*.*")*/ then { action(type="omfile" taget="/var/log/log5") action(type="omfile" taget="/var/log/log6") action(type="omfwd" taget="10.0.0.1" port="514") diff --git a/grammar/parserif.h b/grammar/parserif.h new file mode 100644 index 00000000..e22b7d34 --- /dev/null +++ b/grammar/parserif.h @@ -0,0 +1,6 @@ +#ifndef PARSERIF_H_DEFINED +#define PARSERIF_H_DEFINED +extern int cnfSetLexFile(char*); +extern int yyparse(); +extern int yydebug; +#endif diff --git a/grammar/rscript.l b/grammar/rscript.l index 596becaf..b7c3e521 100644 --- a/grammar/rscript.l +++ b/grammar/rscript.l @@ -62,10 +62,10 @@ static int preCommentState; <EXPR>"<>" { return CMP_NE; } <EXPR>"<" { return CMP_LT; } <EXPR>">" { return CMP_GT; } -<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>"contains" { return CMP_CONTAINS; } +<EXPR>"contains_i" { return CMP_CONTAINSI; } +<EXPR>"startswith" { return CMP_STARTSWITH; } +<EXPR>"startswith_i" { return CMP_STARTSWITHI; } <EXPR>0[0-7]+ | /* octal number */ <EXPR>0x[0-7a-f] | /* hex number, following rule is dec; strtoll handles all! */ <EXPR>([1-9][0-9]*|0) { yylval.n = strtoll(yytext, NULL, 0); return NUMBER; } @@ -100,7 +100,7 @@ static int preCommentState; return NAME; } <INOBJ>"=" { return(yytext[0]); } <INOBJ>\"([^"\\]|\\['"?\\abfnrtv]|\\[0-7]{1,3})*\" { - yylval.estr = es_newStrFromCStr(yytext+1, yyleng-2); + yylval.estr = es_newStrFromBuf(yytext+1, yyleng-2); return VALUE; } "/*" { preCommentState = YY_START; BEGIN COMMENT; } <EXPR>"/*" { preCommentState = YY_START; BEGIN COMMENT; } @@ -122,18 +122,28 @@ static int preCommentState; /*<<EOF>> { printf("EOF reached\n"); }*/ %% - /* -int -main(int argc, char *argv[]) +/* set a new buffers. Returns 0 on success, something else otherwise. */ +int cnfSetLexFile(char *fname) { es_str_t *str; YY_BUFFER_STATE bp; - char ln[10240]; + FILE *fp; + int r = 0; - readConfFile(stdin, &str); - //printf("buffer: %s\n", es_getBufAddr(str)); + if(fname == NULL) { + fp = stdin; + } else { + if((fp = fopen(fname, "r")) == NULL) { + r = 1; + goto done; + } + } + readConfFile(fp, &str); + if(fp != stdin) + fclose(fp); bp = yy_scan_buffer(es_getBufAddr(str), es_strlen(str)); - //yy_switch_to_buffer(bp); - yylex(); + yylineno = 1; + +done: + return r; } -*/ diff --git a/grammar/rscript.y b/grammar/rscript.y index 3652eec2..8bf0e55a 100644 --- a/grammar/rscript.y +++ b/grammar/rscript.y @@ -40,6 +40,10 @@ %token CMP_GE %token CMP_LT %token CMP_GT +%token CMP_CONTAINS +%token CMP_CONTAINSI +%token CMP_STARTSWITH +%token CMP_STARTSWITHI %type <nvlst> nv nvlst %type <obj> obj @@ -50,7 +54,7 @@ %type <expr> expr %left AND OR -%left CMP_EQ CMP_NE CMP_LE CMP_GE CMP_LT CMP_GT +%left CMP_EQ CMP_NE CMP_LE CMP_GE CMP_LT CMP_GT CMP_CONTAINS CMP_CONTAINSI CMP_STARTSWITH CMP_STARTSWITHI %left '+' '-' %left '*' '/' '%' %nonassoc UMINUS NOT @@ -127,6 +131,10 @@ expr: expr AND expr { $$ = cnfexprNew(AND, $1, $3); } | expr CMP_GE expr { $$ = cnfexprNew(CMP_GE, $1, $3); } | expr CMP_LT expr { $$ = cnfexprNew(CMP_LT, $1, $3); } | expr CMP_GT expr { $$ = cnfexprNew(CMP_GT, $1, $3); } + | expr CMP_CONTAINS expr { $$ = cnfexprNew(CMP_CONTAINS, $1, $3); } + | expr CMP_CONTAINSI expr { $$ = cnfexprNew(CMP_CONTAINSI, $1, $3); } + | expr CMP_STARTSWITH expr { $$ = cnfexprNew(CMP_STARTSWITH, $1, $3); } + | expr CMP_STARTSWITHI expr { $$ = cnfexprNew(CMP_STARTSWITHI, $1, $3); } | expr '+' expr { $$ = cnfexprNew('+', $1, $3); } | expr '-' expr { $$ = cnfexprNew('-', $1, $3); } | expr '*' expr { $$ = cnfexprNew('*', $1, $3); } @@ -134,8 +142,8 @@ expr: expr AND expr { $$ = cnfexprNew(AND, $1, $3); } | expr '%' expr { $$ = cnfexprNew('%', $1, $3); } | '(' expr ')' { $$ = $2; printf("( expr)\n"); } | '-' expr %prec UMINUS { printf("uminus\n"); $$ = cnfexprNew('M', NULL, $2); } - | NUMBER { $$ = cnfnumvalNew($1); } - | STRING { $$ = cnfstringvalNew($1); } + | NUMBER { $$ = (struct cnfexpr*) cnfnumvalNew($1); } + | STRING { $$ = (struct cnfexpr*) cnfstringvalNew($1); } | VAR { printf("variables not yet implemented!\n"); } %% @@ -144,9 +152,11 @@ 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 4087bd81..d09a34a9 100644 --- a/grammar/utils.c +++ b/grammar/utils.c @@ -4,6 +4,7 @@ #include <ctype.h> #include <libestr.h> #include "utils.h" +#include "parserif.h" #include "rscript.tab.h" void @@ -345,7 +346,7 @@ cnfexprEval(struct cnfexpr *expr, struct exprret *ret) case NOT: cnfexprEval(expr->r, &r); ret->datatype = 'N'; - ret->d.n = !exprret2Number(&l); + ret->d.n = !exprret2Number(&r); break; case 'N': ret->datatype = 'N'; @@ -428,6 +429,30 @@ cnfexprPrint(struct cnfexpr *expr, int indent) printf(">\n"); cnfexprPrint(expr->r, indent+1); break; + case CMP_CONTAINS: + cnfexprPrint(expr->l, indent+1); + doIndent(indent); + printf("CONTAINS\n"); + cnfexprPrint(expr->r, indent+1); + break; + case CMP_CONTAINSI: + cnfexprPrint(expr->l, indent+1); + doIndent(indent); + printf("CONTAINS_I\n"); + cnfexprPrint(expr->r, indent+1); + break; + case CMP_STARTSWITH: + cnfexprPrint(expr->l, indent+1); + doIndent(indent); + printf("STARTSWITH\n"); + cnfexprPrint(expr->r, indent+1); + break; + case CMP_STARTSWITHI: + cnfexprPrint(expr->l, indent+1); + doIndent(indent); + printf("STARTSWITH_I\n"); + cnfexprPrint(expr->r, indent+1); + break; case OR: cnfexprPrint(expr->l, indent+1); doIndent(indent); @@ -500,3 +525,16 @@ cstrPrint(char *text, es_str_t *estr) free(str); } + +int +main(int argc, char *argv[]) +{ + int r; + + cnfSetLexFile(argc == 1 ? NULL : argv[1]); + yydebug = 0; + r = yyparse(); + printf("yyparse() returned %d\n", r); + return r; +} + |