From 4ffc28ecd6d914f9c1e5aaf5d5921ee4827bb289 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 24 Mar 2012 20:55:27 +0100 Subject: Partial implementation of a config files parser --- src/config.y | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/config.y (limited to 'src/config.y') diff --git a/src/config.y b/src/config.y new file mode 100644 index 0000000..08c5050 --- /dev/null +++ b/src/config.y @@ -0,0 +1,106 @@ +%define api.pure +%name-prefix "fastd_config_" +%lex-param {fastd_context *ctx} +%lex-param {yyscan_t scanner} +%parse-param {fastd_context *ctx} +%parse-param {fastd_config *config} +%parse-param {yyscan_t scanner} + +%code requires { + #include +} + +%union { + int num; + char* str; + struct in_addr addr; + struct in6_addr addr6; +} + +%token TOK_INTEGER +%token TOK_STRING +%token TOK_IDENTIFIER + +%token TOK_INTERFACE +%token TOK_BIND +%token TOK_MTU +%token TOK_MODE +%token TOK_PROTOCOL +%token TOK_PEER + +%token TOK_ADDR +%token TOK_ADDR6 + +%token TOK_ANY +%token TOK_FLOAT +%token TOK_TAP +%token TOK_TUN + +/* %code top { + #define YY_DECL int fastd_config_lex(YYSTYPE *yylval_param, fastd_context *ctx, yyscan_t yyscanner) +}*/ + + +%code { + #include + YY_DECL; + + void fastd_config_error(fastd_context *ctx, fastd_config *config, void *scanner, char *s); +} + +%code provides { + #include + int fastd_config_parse (fastd_context *ctx, fastd_config *config, void *scanner); +} + +%% +config: config statement + | + ; + +statement: TOK_INTERFACE interface ';' + | TOK_BIND bind ';' + | TOK_MTU mtu ';' + | TOK_MODE mode ';' + | TOK_PROTOCOL protocol ';' + | TOK_PEER peer '{' peer_config '}' + ; + +interface: TOK_STRING { config->ifname = strdup($1); } + ; + +bind: TOK_ADDR + | TOK_ADDR ':' port + | TOK_ADDR6 + | TOK_ADDR6 ':' port + | TOK_ANY + | TOK_ANY ':' port + ; + +mtu: TOK_INTEGER { config->mtu = $1; } + ; + +mode: TOK_TAP { config->mode = MODE_TAP; } + | TOK_TUN { config->mode = MODE_TUN; } + ; + +protocol: TOK_STRING + ; + +peer: TOK_STRING + | + ; + +peer_config: peer_config peer_statement + | + ; + +peer_statement: ':' + ; + +port: TOK_INTEGER + ; +%% +void fastd_config_error(fastd_context *ctx, fastd_config *config, yyscan_t scanner, char *s) { + exit_error(ctx, "config error: %s", s); +} -- cgit v1.2.3