diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-03-25 14:21:47 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-03-25 14:21:47 +0200 |
commit | 59a5b833216b62f28c816df7c9129bf0954993e0 (patch) | |
tree | 64c35f8ddcc8eafa9e12663b8eb12ba836ea1886 /src/config.l | |
parent | 6ce20e2bb6660694e995d890f2846fc26c96c8f7 (diff) | |
download | fastd-59a5b833216b62f28c816df7c9129bf0954993e0.tar fastd-59a5b833216b62f28c816df7c9129bf0954993e0.zip |
Change parse to push API, fix some parser bugs
Diffstat (limited to 'src/config.l')
-rw-r--r-- | src/config.l | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/src/config.l b/src/config.l index 1173d44..54d3447 100644 --- a/src/config.l +++ b/src/config.l @@ -1,4 +1,4 @@ -%option prefix="fastd_config_" +%option prefix="fastd_config_yy" %option noyywrap %option bison-bridge %option reentrant @@ -7,10 +7,11 @@ #include <config.yy.h> } -%x STRING -%x ADDR6 +%s STRING +%s ADDR6 %% +<INITIAL>{ [0-9]+ { yylval->num = atoi(yytext); return TOK_INTEGER; } interface { yylval->str = yytext; return TOK_INTERFACE; } @@ -26,7 +27,7 @@ key { yylval->str = yytext; return TOK_KEY; } [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} { if (!inet_pton(AF_INET, yytext, &yylval->addr)) { yylval->str = "invalid address"; - return TOK_ERROR; + return -1; } return TOK_ADDR; @@ -38,27 +39,33 @@ tun { yylval->str = yytext; return TOK_TUN; } [A-Za-z_][A-Za-z0-9_]* { yylval->str = yytext; return TOK_IDENTIFIER; } -[;:\{\}] { return *yytext; } +[;:\{\}] { return yytext[0]; } [ \t\n] ; +} -\" BEGIN(STRING); +<INITIAL>\"\" { yylval->str = ""; return TOK_STRING; } +<INITIAL>\" BEGIN(STRING); <STRING>[^"]* { yylval->str = yytext; return TOK_STRING; } <STRING>\" BEGIN(INITIAL); -\[ BEGIN(ADDR6); -<ADDR6>[^\]]+ { - if (!inet_pton(AF_INET6, yytext, &yylval->addr6)) { - yylval->str = "invalid address"; - return TOK_ERROR; - } - - return TOK_ADDR6; +<INITIAL>\[ BEGIN(ADDR6); +<ADDR6>[^\]]+ { + if (!inet_pton(AF_INET6, yytext, &yylval->addr6)) { + yylval->str = "invalid address"; + return -1; } -<ADDR6>\] BEGIN(INITIAL); -<INITIAL,STRING,ADDR6>. { - yylval->str = "invalid character"; - return TOK_ERROR; - } + return TOK_ADDR6; + } +<ADDR6>\] BEGIN(INITIAL); + +. { + yylval->str = "invalid character"; + return -1; + } + +<INITIAL><<EOF>> { return 0; } +<STRING><<EOF>> { yylval->str = "unterminated string"; return -1; } +<ADDR6><<EOF>> { yylval->str = "unterminated address"; return -1; } %% |