parse.y revision 107665
1%{
2/*-
3 * DEVD (Device action daemon)
4 *
5 * Copyright (c) 2002 M. Warner Losh <imp@freebsd.org>.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $FreeBSD: head/sbin/devd/parse.y 107665 2002-12-07 08:04:36Z imp $
30 */
31
32#include "devd.h"
33#include <stdio.h>
34#include <string.h>
35
36%}
37
38%union {
39	char *str;
40	int i;
41	struct eps *eps;	/* EventProcStatement */
42	struct event_proc *eventproc;
43}
44
45%token SEMICOLON BEGINBLOCK ENDBLOCK COMMA
46%token <i> NUMBER
47%token <str> STRING
48%token <str> ID
49%token OPTIONS SET DIRECTORY PID_FILE DEVICE_NAME ACTION MATCH
50%token ATTACH DETACH NOMATCH
51
52%type <eventproc> match_or_action_list
53%type <eps> match_or_action match action
54
55%%
56
57config_file
58	: config_list
59	|
60	;
61
62config_list
63	: config
64	| config_list config
65	;
66
67config
68	: option_block
69	| attach_block
70	| detach_block
71	| nomatch_block
72	;
73
74option_block
75	: OPTIONS BEGINBLOCK options ENDBLOCK SEMICOLON
76	;
77
78options
79	: option
80	| options option
81
82option
83	: directory_option
84	| pid_file_option
85	| set_option
86	;
87
88directory_option
89	: DIRECTORY STRING SEMICOLON { add_directory($2); }
90	;
91
92pid_file_option
93	: PID_FILE STRING SEMICOLON { set_pidfile($2); }
94	;
95
96set_option
97	: SET ID STRING SEMICOLON { set_variable($2, $3); }
98	;
99
100attach_block
101	: ATTACH NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON
102		{ add_attach($2, $4); }
103	;
104
105detach_block
106	: DETACH NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON
107		{ add_detach($2, $4); }
108	;
109
110nomatch_block
111	: NOMATCH NUMBER BEGINBLOCK match_or_action_list ENDBLOCK SEMICOLON
112		{ add_nomatch($2, $4); }
113	;
114
115match_or_action_list
116	: match_or_action { $$ = add_to_event_proc( NULL, $1); }
117	| match_or_action_list match_or_action
118			{ $$ = add_to_event_proc($1, $2); }
119	;
120
121match_or_action
122	: match
123	| action
124	;
125
126match
127	: MATCH STRING STRING SEMICOLON	{ $$ = new_match($2, $3); }
128	| DEVICE_NAME STRING SEMICOLON
129		{ $$ = new_match(strdup("device-name"), $2); }
130	;
131
132action
133	: ACTION STRING SEMICOLON	{ $$ = new_action($2); }
134	;
135
136%%
137