aboutsummaryrefslogtreecommitdiff
path: root/src/build.y
blob: 1424867a213373364f9f2e02eea3edb3e1df3807 (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
%defines
%{
# include <string>
# include "builder.h"
# include "build.tab.h"
void yyerror( YYLTYPE *locp, Builder &bld, char const *msg );
%}

%parse-param { Builder &bld }
%lex-param { Builder &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 ',' ':' '=' '(' ')'

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

%%

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

// Rule interpretation
rule: TOK_RULE STRING {printf("Rule %s:\n", $2 ); } ':' rulecmds
	;

rulecmds: rulecmd
		| rulecmds ',' rulecmd
		;

rulecmd: TOK_MATCHES { printf("    Matches: " ); } func { printf("\n"); }
	   | TOK_PRODUCES STRING { printf("    Produces: %s\n", $2 ); }
	   | TOK_REQUIRES { printf("    Requires:\n"); } list {printf("\n");}
	   | TOK_INPUT TOK_FILTER { printf("    Input Filter: "); } func {printf("\n");}
	   | TOK_PERFORM { printf("    Perform: "); } perf {printf("\n");}
	   ;

// Action interpretation
action: TOK_DEFAULT TOK_ACTION ':' { printf("Default action:\n"); } actioncmds
	  | STRING TOK_ACTION ':' { printf("\"%s\" action:\n", $1 ); } actioncmds
	  ;

actioncmds: actioncmd
		  | actioncmds ',' actioncmd
		  ;

actioncmd: { printf("    "); } actioncmdtype list {printf("\n");}
		 ;

actioncmdtype: TOK_CHECK { printf("check "); }
			 | TOK_CLEAN { printf("clean "); }
			 ;

// Target interpretation
target: list ':' { printf(" are targets:\n"); } targetcmds
	  ;

targetcmds: targetcmd
		  | targetcmds ',' targetcmd
		  ;

targetcmd: TOK_RULE STRING { printf("    Rule %s\n", $2 ); }
		 | TOK_TARGET TOK_PREFIX STRING { printf("    Target prefix: %s\n", $3 ); }
		 | TOK_TARGET TARGETTYPE { printf("    Target Type: %s\n", $2 ); }
		 | TOK_INPUT { printf("    Input: "); } list { printf("\n"); }
		 | TOK_INPUT TOK_FILTER { printf("    Input filter: "); } func  { printf("\n"); }
		 | TOK_REQUIRES { printf("    Requires: "); } list { printf("\n"); }
		 | TOK_SET { printf("    Set: "); } targetset
		 ;

targetset: STRING '=' STRING { printf("%s = %s\n", $1, $3 ); }
		 | STRING TOK_ADDSET STRING { printf("%s += %s\n", $1, $3 ); }
		 ;

// global set
set: TOK_SET { printf("Set: "); } setwhat
   ;

setwhat: STRING '=' STRING { printf("%s = %s\n", $1, $3 ); }
	   | STRING TOK_ADDSET STRING { printf("%s += %s\n", $1, $3 ); }
	   ;

// list goo
list: listitem listfilter
	| '[' { printf("["); } listitems ']' { printf("]"); } listfilter
	;

listfilter:
		  | TOK_FILTER { printf(" filtered by "); } func
		  ;

listitems: listitem
		 | listitems ',' { printf(", "); } listitem
		 ;

listitem: STRING { printf("%s", $1 ); }
		| func
		;

// Function
func: FUNCTION { printf("%s(", $1 ); } '(' funcparams ')' { printf(")"); }
	;

funcparams:
		  | STRING { printf("%s", $1 ); }
		  | funcparams ',' STRING { printf(", %s", $3 ); }
		  ;

// Perform
perf: PERFORM { printf("%s(", $1 ); } '(' perfparams ')' { printf(")"); }
	;

perfparams:
		  | STRING { printf("%s", $1 ); }
		  | perfparams ',' STRING { printf(", %s", $3 ); }
		  ;
%%

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