2013-03-18 01:03:43 +01:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013, Matthias Schiffer <mschiffer@universe-factory.net>
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2013-07-26 14:22:18 +02:00
|
|
|
%define api.pure
|
|
|
|
%define api.push-pull push
|
|
|
|
%name-prefix "mmss_config_"
|
|
|
|
%locations
|
2013-07-28 19:33:40 +02:00
|
|
|
%parse-param {const std::shared_ptr<config_t> &conf}
|
2013-07-26 14:22:18 +02:00
|
|
|
%parse-param {const char *filename}
|
2013-03-18 01:03:43 +01:00
|
|
|
|
|
|
|
|
2013-07-26 14:22:18 +02:00
|
|
|
%code requires {
|
2013-07-27 22:28:34 +02:00
|
|
|
#include <config.hpp>
|
|
|
|
#include <context.hpp>
|
2013-03-18 01:03:43 +01:00
|
|
|
|
2013-07-27 22:28:34 +02:00
|
|
|
using namespace MMSS;
|
2013-07-26 14:22:18 +02:00
|
|
|
}
|
2013-03-18 01:03:43 +01:00
|
|
|
|
2013-07-26 14:22:18 +02:00
|
|
|
%union {
|
2014-03-17 19:21:24 +01:00
|
|
|
uint64_t uint64;
|
2013-07-29 21:00:11 +02:00
|
|
|
float fnum;
|
2013-07-26 14:22:18 +02:00
|
|
|
bool boolean;
|
2013-07-26 17:45:15 +02:00
|
|
|
char *str;
|
2013-07-28 22:12:35 +02:00
|
|
|
gmrf_addr_t addr;
|
2013-03-18 01:03:43 +01:00
|
|
|
|
2013-07-26 14:22:18 +02:00
|
|
|
const char *error;
|
|
|
|
}
|
2013-03-18 01:03:43 +01:00
|
|
|
|
2014-03-17 19:21:24 +01:00
|
|
|
%token <uint64> TOK_UINT
|
2013-07-29 21:00:11 +02:00
|
|
|
%token <fnum> TOK_FLOAT
|
2013-07-26 14:22:18 +02:00
|
|
|
%token <str> TOK_STRING
|
2013-07-28 22:12:35 +02:00
|
|
|
%token <addr> TOK_GMRF_ADDRESS
|
2013-03-18 01:03:43 +01:00
|
|
|
|
2013-07-26 14:22:18 +02:00
|
|
|
%token TOK_YES
|
|
|
|
%token TOK_NO
|
2013-07-28 22:12:35 +02:00
|
|
|
%token TOK_NETWORK
|
|
|
|
%token TOK_PROTOCOL
|
|
|
|
%token TOK_NODE
|
|
|
|
%token TOK_LOAD
|
|
|
|
%token TOK_DEFAULT
|
|
|
|
%token TOK_INTERFACE
|
|
|
|
%token TOK_ADDRESS
|
2013-07-29 21:00:11 +02:00
|
|
|
%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
|
2013-03-18 01:03:43 +01:00
|
|
|
|
|
|
|
|
2013-07-26 14:22:18 +02:00
|
|
|
%code {
|
2013-07-28 19:33:40 +02:00
|
|
|
void mmss_config_error(YYLTYPE *loc, const std::shared_ptr<config_t> &conf, const char *filename, const char *s);
|
2013-03-18 01:03:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-26 14:22:18 +02:00
|
|
|
%type <boolean> boolean
|
2013-07-28 22:12:35 +02:00
|
|
|
%type <boolean> maybe_default
|
|
|
|
%type <str> maybe_protocol
|
2013-07-30 04:01:37 +02:00
|
|
|
%type <fnum> time
|
2013-07-29 21:00:11 +02:00
|
|
|
%type <fnum> float
|
2013-03-18 01:03:43 +01:00
|
|
|
|
2013-07-26 14:22:18 +02:00
|
|
|
%%
|
2013-03-18 01:03:43 +01:00
|
|
|
|
2013-07-26 14:22:18 +02:00
|
|
|
start: config
|
|
|
|
;
|
|
|
|
|
|
|
|
config: config statement
|
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
statement: TOK_NETWORK network '{' network_config '}'
|
2013-07-28 22:12:35 +02:00
|
|
|
| TOK_PROTOCOL protocol ';'
|
|
|
|
| TOK_NODE node '{' node_config '}'
|
2013-07-26 14:22:18 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
network: TOK_STRING {
|
2013-07-28 22:12:35 +02:00
|
|
|
if (!conf->add_network($1))
|
|
|
|
YYERROR;
|
2013-07-26 14:22:18 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2013-07-29 21:00:11 +02:00
|
|
|
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;
|
|
|
|
}
|
2013-07-26 14:22:18 +02:00
|
|
|
;
|
2013-03-18 01:03:43 +01:00
|
|
|
|
2013-07-28 22:12:35 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2013-07-29 21:00:11 +02:00
|
|
|
float: TOK_FLOAT { $$ = $1; }
|
2014-03-17 19:21:24 +01:00
|
|
|
| TOK_UINT { $$ = $1; }
|
2013-07-29 21:00:11 +02:00
|
|
|
;
|
|
|
|
|
2013-07-26 14:22:18 +02:00
|
|
|
boolean: TOK_YES { $$ = true; }
|
|
|
|
| TOK_NO { $$ = false; }
|
|
|
|
;
|
2013-03-18 01:03:43 +01:00
|
|
|
|
2013-07-28 22:12:35 +02:00
|
|
|
maybe_default: TOK_DEFAULT { $$ = true; }
|
|
|
|
| { $$ = false; }
|
|
|
|
;
|
|
|
|
|
2013-07-29 21:00:11 +02:00
|
|
|
maybe_protocol: TOK_PROTOCOL TOK_STRING { $$ = $2; }
|
2013-07-28 22:12:35 +02:00
|
|
|
| { $$ = nullptr; }
|
|
|
|
;
|
|
|
|
|
2013-07-30 04:01:37 +02:00
|
|
|
time: float TOK_DAYS { $$ = $1*86400; }
|
|
|
|
| float TOK_H { $$ = $1*3600; }
|
|
|
|
| float TOK_M { $$ = $1*60; }
|
|
|
|
| float TOK_S { $$ = $1; }
|
|
|
|
| float { $$ = $1; }
|
2013-07-29 21:00:11 +02:00
|
|
|
;
|
|
|
|
|
2013-07-26 14:22:18 +02:00
|
|
|
%%
|
2013-03-18 01:03:43 +01:00
|
|
|
|
2013-07-28 19:33:40 +02:00
|
|
|
void mmss_config_error(YYLTYPE *loc, const std::shared_ptr<config_t> &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);
|
2013-03-18 01:03:43 +01:00
|
|
|
}
|