aboutsummaryrefslogtreecommitdiff
path: root/src/build.y
blob: bfda4b4b16ecf7eb2359ee42b4f9c0956af1cd61 (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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
%defines
%{
# include <string>
# include "buildparser.h"
# include "build.tab.h"
# include "action.h"
void yyerror( YYLTYPE *locp, BuildParser &bld, char const *msg );
%}

%parse-param { BuildParser &bld }
%lex-param { BuildParser &bld }
%pure-parser

%locations

%debug
%error-verbose
%union {
	char *strval;
}

%token <strval>		STRING		"string literal"
%token <strval>		TARGETTYPE	"target type"
%token <strval>		FUNCTION	"function name"
%token <strval>		PERFORM		"perform name"

%token TOK_ADDSET				"+="
%token TOK_DEFAULT				"default"
%token TOK_ACTION				"action"
%token TOK_CHECK				"check"
%token TOK_CLEAN				"clean"
%token TOK_RULE					"rule"
%token TOK_TARGET				"target"
%token TOK_SET					"set"
%token TOK_INPUT				"input"
%token TOK_FILTER				"filter"
%token TOK_PREFIX				"prefix"
%token TOK_REQUIRES				"requires"
%token TOK_MATCHES				"matches"
%token TOK_PERFORM				"perform"
%token TOK_PRODUCES				"produces"
%token TOK_AGGREGATE			"aggregate"
%token TOK_GROUP				"group"

%token ',' ':' '=' '(' ')'

%destructor { delete[] $$; } STRING FUNCTION

%%

// General input format
input:
	 | input rule
	 | input action
	 | input target
	 | input set
	 ;

// Rule interpretation
rule: TOK_RULE STRING ':'
	{
		bld.addRule( $2 );
	}
	  rulecmds
	;

rulecmds: rulecmd
		| rulecmds ',' rulecmd
		;

rulecmd: TOK_MATCHES func
	   {
		   bld.addRuleMatches();
	   }
	   | TOK_PRODUCES list
	   {
		   bld.addRuleProduces();
	   }
	   | TOK_REQUIRES list
	   {
		   bld.addRuleRequires();
	   }
	   | TOK_INPUT TOK_FILTER func
	   {
		   bld.addRuleInputFilter();
	   }
	   | TOK_PERFORM perf
	   {
		   bld.addRulePerform();
	   }
	   | TOK_AGGREGATE func
	   {
		   bld.setRuleAggregate();
	   }
	   ;

// Action interpretation
action: TOK_DEFAULT TOK_ACTION ':'
	  {
		  bld.addAction();
	  }
	    actioncmds
	  | STRING TOK_ACTION ':'
	  {
		  if( $1[0] == '\0' )
			  bld.error(
			  	&yylloc,
				"You cannot use an empty string as the name of an action."
				);
		  bld.addAction( $1 );
	  }
	    actioncmds
	  ;

actioncmds: actioncmd
		  | actioncmds ',' actioncmd
		  ;

actioncmd: TOK_CHECK list
		 {
			 bld.addCommand( Action::actCheck );
		 }
		 | TOK_CLEAN list
		 {
			 bld.addCommand( Action::actClean );
		 }
		 | TOK_CHECK TOK_GROUP STRING
		 | TOK_CLEAN TOK_GROUP STRING
		 ;

// Target interpretation
target: list ':'
	  {
		  bld.newTarget();
	  }
	    targetcmds
	  ;

targetcmds: targetcmd
		  | targetcmds ',' targetcmd
		  ;

targetcmd: TOK_RULE STRING
		 {
			 bld.setTargetRule( $2 );
		 }
		 | TOK_TARGET TOK_PREFIX STRING
		 {
			 bld.setTargetPrefix( $3 );
		 }
		 | TOK_TARGET TARGETTYPE
		 {
			 bld.setTargetType( $2 );
		 }
		 | TOK_INPUT list
		 {
			 bld.addTargetInput();
		 }
		 | TOK_REQUIRES list
		 {
			 bld.addTargetRequires();
		 }
		 | TOK_SET targetset
		 | TOK_GROUP STRING
		 {
			 bld.addTargetGroup( $2 );
		 }
		 ;

targetset: STRING '=' STRING
		 {
			 bld.addTargetSet( $1, $3, setSet );
		 }
		 | STRING TOK_ADDSET STRING
		 {
			 bld.addTargetSet( $1, $3, setAdd );
		 }
		 ;

// global set
set: TOK_SET setwhat
   ;

setwhat: STRING '=' STRING
	   {
		   bld.addGlobalSet( $1, $3, setSet );
	   }
	   | STRING TOK_ADDSET STRING
	   {
		   bld.addGlobalSet( $1, $3, setAdd );
	   }
	   ;

// list goo
list: singlelistitem listfilter
	| '['
	{
		bld.newList();
	}
	  listitems ']' listfilter
	;

listfilter:
		  | TOK_FILTER func
		  {
			  bld.filterList();
		  }
		  ;

listitems: listitem
		 | listitems ',' listitem
		 ;

listitem: STRING
		{
			bld.addListString( $1 );
		}
		| func
		{
			bld.addListFunc();
		}
		;

singlelistitem: STRING
			  {
				  bld.newList();
				  bld.addListString( $1 );
			  }
			  | func
			  {
				  bld.newList();
				  bld.addListFunc();
			  }
			  ;

// Function
func: FUNCTION
	{
		bld.newFunctionCall( $1 );
	}
	  '(' funcparams ')'
	;

funcparams:
		  | STRING { bld.addFunctionParam( $1 ); }
		  | funcparams ',' STRING { bld.addFunctionParam( $3 ); }
		  ;

// Perform
perf: PERFORM
	{
		bld.newPerform( $1 );
	}
	  '(' perfparams ')'
	;

perfparams:
		  | STRING
		  {
			  bld.addPerformParam( $1 );
		  }
		  | perfparams ',' STRING
		  {
			  bld.addPerformParam( $3 );
		  }
		  ;
%%

void yyerror( YYLTYPE *locp, BuildParser &bld, char const *msg )
{
	bld.error( locp, msg );
}