diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2011-07-01 14:39:20 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2011-07-01 14:39:20 +0200 |
commit | 4ccdf6ea624c66024bce7cbede53049b5f218fb0 (patch) | |
tree | 9e24e031a28896198bacad9ddb93bff41e13183e | |
parent | 8cd026b1cbb0f22f498963c862136c22d2920a15 (diff) | |
download | rsyslog-4ccdf6ea624c66024bce7cbede53049b5f218fb0.tar.gz rsyslog-4ccdf6ea624c66024bce7cbede53049b5f218fb0.tar.xz rsyslog-4ccdf6ea624c66024bce7cbede53049b5f218fb0.zip |
milestone: lexer now correctly identifies (almost) all constructs
-rw-r--r-- | grammar/debian.new | 32 | ||||
-rw-r--r-- | grammar/rscript.l | 79 |
2 files changed, 107 insertions, 4 deletions
diff --git a/grammar/debian.new b/grammar/debian.new index a6574f62..4d55735c 100644 --- a/grammar/debian.new +++ b/grammar/debian.new @@ -103,5 +103,35 @@ global (dnscache=yes arg1="1 2" arg2 = "1 2" arg3 ="1=2\"3") # samples added to get full "flavor" of what we need to support... :msg, contains, "error" /var/log/somelog action(type=omfile target=/var/log/mail/log) -*.* * # test +*.* /* comment */ * # test *.info :ommysql:, tra, la , la # comment (comment to be part of old style line!) + +# from SUSE: +if ( \ + /* kernel up to warning except of firewall */ \ + ($syslogfacility-text == 'kern') and \ + ($syslogseverity <= 4 /* warning */ ) and not \ + ($msg contains 'IN=' and $msg contains 'OUT=') \ + ) or ( \ + /* up to errors except of facility authpriv */ \ + ($syslogseverity <= 3 /* errors */ ) and not \ + ($syslogfacility-text == 'authpriv') \ + ) \ +then /dev/tty10 +& |/dev/xconsole +# +# slightly modified to not use continuation lines +if ( /* kernel up to warning except of firewall */ + ($syslogfacility-text == 'kern') and + ($syslogseverity <= 4 /* warning */ ) and not + ($msg contains 'IN=' and $msg contains 'OUT=') + ) or ( + /* up to errors except of facility authpriv */ + ($syslogseverity <= 3 /* errors */ ) and not + ($syslogfacility-text == 'authpriv') + ) +then /dev/tty10 +& |/dev/xconsole + +*.* rger # write to user (ugly...) +ruleset name diff --git a/grammar/rscript.l b/grammar/rscript.l index b5d23d7a..10ce1748 100644 --- a/grammar/rscript.l +++ b/grammar/rscript.l @@ -1,14 +1,77 @@ + /* lex file for rsyslog config format v2. + * Please note: this file introduces the new config format, but maintains + * backward compatibility. In order to do so, the grammar is not 100% clean, + * but IMHO still sufficiently easy both to understand for programmers + * maitaining the code as well as users writing the config file. Users are, + * of course, encouraged to use new constructs only. But it needs to be noted + * that some of the legacy constructs (specifically the in-front-of-action + * PRI filter) are very hard to beat in ease of use, at least for simpler + * cases. So while we hope that cfsysline support can be dropped some time in + * the future, we will probably keep these useful constructs. + * + * Copyright (C) 2011 by Rainer Gerhards and Adiscon GmbH + * Released under the GNU GPL v3. For details see LICENSE file. + */ + %option noyywrap nodefault case-insensitive /*%option noyywrap nodefault case-insensitive */ %x INOBJ /* INOBJ is selected if we are inside an object (name/value pairs!) */ +%x COMMENT + /* COMMENT is "the usual trick" to handle C-style comments */ +%x EXPR + /* EXPR is a bit ugly, but we need it to support pre v6-syntax. The problem + * is that cfsysline statement start with $..., the same like variables in + * an expression. However, cfsysline statements can never appear inside an + * expression. So we create a specific expr mode, which is turned on after + * we lexed a keyword that needs to be followed by an expression (using + * knowledge from the upper layer...). In expr mode, we strictly do + * expression-based parsing. Expr mode is stopped when we reach a token + * that can not be part of an expression (currently only "then"). As I + * wrote this ugly, but the price needed to pay in order to remain + * compatible to the previous format. + */ %{ #include <libestr.h> +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"); } +<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>[ \t\n] +<EXPR>. { printf("invalid char in expr: %s\n", yytext); } +"&" { printf("AMPER\n"); } +"ruleset" { printf("RULESET\n"); } + "global"[ \n\t]*"(" { printf("OBJ GLOBAL begin\n"); BEGIN INOBJ; } @@ -23,17 +86,18 @@ } ^[ \t]*:\$?[a-z]+[ ]*,[ ]*!?[a-z]+[ ]*,[ ]*\".*\" { printf("PROP-FILT: '%s'\n", yytext); - /*BEGIN OLDACT;*/ } ^[ \t]*[,\*a-z]+\.[,!=;\.\*a-z]+ { printf("PRI-FILT: '%s'\n", yytext); - /*BEGIN OLDACT;*/ } "*" | -[\|\.\/\-:][^\n]+ { printf("old style action: '%s'\n", yytext); +\/[^*][^\n]* | +[\|\.\-:][^\n]+ { printf("old style action: '%s'\n", yytext); } +[a-z0-9_\-\+]+ { printf("name: '%s'\n", yytext); } + <INOBJ>")" { printf("OBJ end\n"); BEGIN INITIAL; } @@ -46,6 +110,15 @@ printf("INOBJ: value '%s'\n", yytext); BEGIN INOBJ; } +"/*" { 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); } |