/* Copyright (c) 2013-2014, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ %define api.pure %define api.push-pull push %name-prefix "mmss_config_" %locations %parse-param {const std::shared_ptr &conf} %parse-param {const char *filename} %code requires { #include #include using namespace MMSS; } %union { uint64_t uint64; float fnum; bool boolean; char *str; gmrf_addr_t addr; const char *error; } %token TOK_UINT %token TOK_FLOAT %token TOK_STRING %token TOK_GMRF_ADDRESS %token TOK_YES %token TOK_NO %token TOK_NETWORK %token TOK_PROTOCOL %token TOK_NODE %token TOK_LOAD %token TOK_DEFAULT %token TOK_INTERFACE %token TOK_ADDRESS %token TOK_ETX %token TOK_CONST %token TOK_MIN %token TOK_MAX %token TOK_SINE %token TOK_PERIOD %token TOK_PHASE %token TOK_S %token TOK_M %token TOK_H %token TOK_DAYS %code { void mmss_config_error(YYLTYPE *loc, const std::shared_ptr &conf, const char *filename, const char *s); } %type boolean %type maybe_default %type maybe_protocol %type time %type float %% start: config ; config: config statement | ; statement: TOK_NETWORK network network_tail | TOK_PROTOCOL protocol ';' | TOK_NODE node '{' node_config '}' ; network: TOK_STRING { if (!conf->add_network($1)) YYERROR; } ; network_tail: '{' network_config '}' | ';' network_config: network_config network_statement | ; network_statement: TOK_ETX network_etx ';' ; network_etx: TOK_CONST float { if (!conf->set_packet_loss($2)) YYERROR; } | TOK_MIN float TOK_MAX float TOK_SINE TOK_PERIOD time { if (!conf->set_packet_loss($2, $4, $7, 0)) YYERROR; } | TOK_MIN float TOK_MAX float TOK_SINE TOK_PERIOD time TOK_PHASE time { if (!conf->set_packet_loss($2, $4, $7, $9)) YYERROR; } ; protocol: TOK_STRING TOK_LOAD TOK_STRING maybe_default { if (!conf->load_proto($1, $3, $4)) YYERROR; } ; node: TOK_STRING maybe_protocol { if (!conf->add_node($1, $2)) YYERROR; } ; node_config: node_config node_statement | ; node_statement: TOK_INTERFACE node_interface ';' ; node_interface: TOK_STRING TOK_NETWORK TOK_STRING TOK_ADDRESS TOK_GMRF_ADDRESS { if (!conf->add_iface($1, $3, &$5)) YYERROR; } ; float: TOK_FLOAT { $$ = $1; } | TOK_UINT { $$ = $1; } ; boolean: TOK_YES { $$ = true; } | TOK_NO { $$ = false; } ; maybe_default: TOK_DEFAULT { $$ = true; } | { $$ = false; } ; maybe_protocol: TOK_PROTOCOL TOK_STRING { $$ = $2; } | { $$ = nullptr; } ; time: float TOK_DAYS { $$ = $1*86400; } | float TOK_H { $$ = $1*3600; } | float TOK_M { $$ = $1*60; } | float TOK_S { $$ = $1; } | float { $$ = $1; } ; %% void mmss_config_error(YYLTYPE *loc, const std::shared_ptr &conf, const char *filename, const char *s) { conf->get_context()->logf(LOG_ERR, "config error: %s at %s:%i:%i", s, filename, loc->first_line, loc->first_column); }