summaryrefslogtreecommitdiffstats
path: root/contrib/dma/aliases_parse.y
blob: 46728e6f205dd3db4b79fcd2b87ee4765d62794c (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
%{

#include <err.h>
#include <string.h>
#include <syslog.h>
#include "dma.h"

extern int yylineno;
static void yyerror(const char *);

static void
yyerror(const char *msg)
{
	/**
	 * Because we do error '\n' below, we need to report the error
	 * one line above of what yylineno points to.
	 */
	syslog(LOG_CRIT, "aliases line %d: %s", yylineno - 1, msg);
	fprintf(stderr, "aliases line %d: %s\n", yylineno - 1, msg);
}

int
yywrap(void)
{
	return (1);
}

%}

%union {
	char *ident;
	struct stritem *strit;
	struct alias *alias;
}

%token <ident> T_IDENT
%token T_ERROR
%token T_EOF 0

%type <strit> dests
%type <alias> alias aliases

%%

start	: aliases T_EOF
		{
			LIST_FIRST(&aliases) = $1;
		}

aliases	: /* EMPTY */
		{
			$$ = NULL;
		}
	| alias aliases
		{
			if ($2 != NULL && $1 != NULL)
				LIST_INSERT_AFTER($2, $1, next);
			else if ($2 == NULL)
				$2 = $1;
			$$ = $2;
		}
       	;

alias	: T_IDENT ':' dests '\n'
		{
			struct alias *al;

			if ($1 == NULL)
				YYABORT;
			al = calloc(1, sizeof(*al));
			if (al == NULL)
				YYABORT;
			al->alias = $1;
			SLIST_FIRST(&al->dests) = $3;
			$$ = al;
		}
	| error '\n'
		{
			YYABORT;
		}
     	;

dests	: T_IDENT
		{
			struct stritem *it;

			if ($1 == NULL)
				YYABORT;
			it = calloc(1, sizeof(*it));
			if (it == NULL)
				YYABORT;
			it->str = $1;
			$$ = it;
		}
	| T_IDENT ',' dests
		{
			struct stritem *it;

			if ($1 == NULL)
				YYABORT;
			it = calloc(1, sizeof(*it));
			if (it == NULL)
				YYABORT;
			it->str = $1;
			SLIST_NEXT(it, next) = $3;
			$$ = it;
		}
	;

%%
OpenPOWER on IntegriCloud