summaryrefslogtreecommitdiffstats
path: root/mmss/config.y
blob: 6eade61b9da638977a624d157d926d7b112d9b91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
  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.
*/


%define api.pure
%define api.push-pull push
%name-prefix "mmss_config_"
%locations
%parse-param {const std::shared_ptr<config_t> &conf}
%parse-param {const char *filename}


%code requires {
	#include <config.hpp>
	#include <context.hpp>

	using namespace MMSS;
}

%union {
	int num;
	bool boolean;
	char *str;
	gmrf_addr_t addr;

	const char *error;
}

%token <num> TOK_INTEGER
%token <str> TOK_STRING
%token <addr> 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


%code {
	void mmss_config_error(YYLTYPE *loc, const std::shared_ptr<config_t> &conf, const char *filename, const char *s);
}


%type <boolean> boolean
%type <boolean> maybe_default
%type <str> maybe_protocol

%%

start:		config
	;

config:		config statement
	|
	;

statement:	TOK_NETWORK network '{' network_config '}'
	|	TOK_PROTOCOL protocol ';'
	|	TOK_NODE node '{' node_config '}'
	;

network:	TOK_STRING {
			if (!conf->add_network($1))
				YYERROR;
		}
	;

network_config:
	;

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;
		}
	;

boolean:	TOK_YES		{ $$ = true; }
	|	TOK_NO		{ $$ = false; }
	;

maybe_default:	TOK_DEFAULT	{ $$ = true; }
	|			{ $$ = false; }
	;

maybe_protocol:	TOK_PROTOCOL TOK_STRING	{ $$ = $2; }
	|			{ $$ = nullptr; }
	;

%%

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);
}