Line data Source code
1 : %{
2 : /*-------------------------------------------------------------------------
3 : *
4 : * specparse.y
5 : * bison grammar for the isolation test file format
6 : *
7 : * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
8 : * Portions Copyright (c) 1994, Regents of the University of California
9 : *
10 : *-------------------------------------------------------------------------
11 : */
12 :
13 : #include "postgres_fe.h"
14 :
15 : #include "isolationtester.h"
16 : #include "specparse.h"
17 :
18 : /* silence -Wmissing-variable-declarations */
19 : extern int spec_yychar;
20 : extern int spec_yynerrs;
21 :
22 : TestSpec parseresult; /* result of parsing is left here */
23 :
24 : %}
25 :
26 : %expect 0
27 : %name-prefix="spec_yy"
28 :
29 : %union
30 : {
31 : char *str;
32 : int integer;
33 : Session *session;
34 : Step *step;
35 : Permutation *permutation;
36 : PermutationStep *permutationstep;
37 : PermutationStepBlocker *blocker;
38 : struct
39 : {
40 : void **elements;
41 : int nelements;
42 : } ptr_list;
43 : }
44 :
45 : %type <ptr_list> setup_list
46 : %type <str> opt_setup opt_teardown
47 : %type <str> setup
48 : %type <ptr_list> step_list session_list permutation_list opt_permutation_list
49 : %type <ptr_list> permutation_step_list blocker_list
50 : %type <session> session
51 : %type <step> step
52 : %type <permutation> permutation
53 : %type <permutationstep> permutation_step
54 : %type <blocker> blocker
55 :
56 : %token <str> sqlblock identifier
57 : %token <integer> INTEGER
58 : %token NOTICES PERMUTATION SESSION SETUP STEP TEARDOWN TEST
59 :
60 : %%
61 :
62 : TestSpec:
63 : setup_list
64 : opt_teardown
65 : session_list
66 : opt_permutation_list
67 : {
68 152 : parseresult.setupsqls = (char **) $1.elements;
69 152 : parseresult.nsetupsqls = $1.nelements;
70 152 : parseresult.teardownsql = $2;
71 152 : parseresult.sessions = (Session **) $3.elements;
72 152 : parseresult.nsessions = $3.nelements;
73 152 : parseresult.permutations = (Permutation **) $4.elements;
74 152 : parseresult.npermutations = $4.nelements;
75 : }
76 : ;
77 :
78 : setup_list:
79 : /* EMPTY */
80 : {
81 152 : $$.elements = NULL;
82 152 : $$.nelements = 0;
83 : }
84 : | setup_list setup
85 : {
86 160 : $$.elements = pg_realloc_array($1.elements, void *,
87 : $1.nelements + 1);
88 160 : $$.elements[$1.nelements] = $2;
89 160 : $$.nelements = $1.nelements + 1;
90 : }
91 : ;
92 :
93 : opt_setup:
94 151 : /* EMPTY */ { $$ = NULL; }
95 224 : | setup { $$ = $1; }
96 : ;
97 :
98 : setup:
99 384 : SETUP sqlblock { $$ = $2; }
100 : ;
101 :
102 : opt_teardown:
103 360 : /* EMPTY */ { $$ = NULL; }
104 167 : | TEARDOWN sqlblock { $$ = $2; }
105 : ;
106 :
107 : session_list:
108 : session_list session
109 : {
110 223 : $$.elements = pg_realloc_array($1.elements, void *,
111 : $1.nelements + 1);
112 223 : $$.elements[$1.nelements] = $2;
113 223 : $$.nelements = $1.nelements + 1;
114 : }
115 : | session
116 : {
117 152 : $$.nelements = 1;
118 152 : $$.elements = pg_malloc_object(void *);
119 152 : $$.elements[0] = $1;
120 : }
121 : ;
122 :
123 : session:
124 : SESSION identifier opt_setup step_list opt_teardown
125 : {
126 375 : $$ = pg_malloc_object(Session);
127 375 : $$->name = $2;
128 375 : $$->setupsql = $3;
129 375 : $$->steps = (Step **) $4.elements;
130 375 : $$->nsteps = $4.nelements;
131 375 : $$->teardownsql = $5;
132 : }
133 : ;
134 :
135 : step_list:
136 : step_list step
137 : {
138 1217 : $$.elements = pg_realloc_array($1.elements, void *,
139 : $1.nelements + 1);
140 1217 : $$.elements[$1.nelements] = $2;
141 1217 : $$.nelements = $1.nelements + 1;
142 : }
143 : | step
144 : {
145 375 : $$.nelements = 1;
146 375 : $$.elements = pg_malloc_object(void *);
147 375 : $$.elements[0] = $1;
148 : }
149 : ;
150 :
151 :
152 : step:
153 : STEP identifier sqlblock
154 : {
155 1592 : $$ = pg_malloc_object(Step);
156 1592 : $$->name = $2;
157 1592 : $$->sql = $3;
158 1592 : $$->session = -1; /* until filled */
159 1592 : $$->used = false;
160 : }
161 : ;
162 :
163 :
164 : opt_permutation_list:
165 : permutation_list
166 : {
167 138 : $$ = $1;
168 : }
169 : | /* EMPTY */
170 : {
171 14 : $$.elements = NULL;
172 14 : $$.nelements = 0;
173 : }
174 :
175 : permutation_list:
176 : permutation_list permutation
177 : {
178 1160 : $$.elements = pg_realloc_array($1.elements, void *,
179 : $1.nelements + 1);
180 1160 : $$.elements[$1.nelements] = $2;
181 1160 : $$.nelements = $1.nelements + 1;
182 : }
183 : | permutation
184 : {
185 138 : $$.nelements = 1;
186 138 : $$.elements = pg_malloc_object(void *);
187 138 : $$.elements[0] = $1;
188 : }
189 : ;
190 :
191 :
192 : permutation:
193 : PERMUTATION permutation_step_list
194 : {
195 1298 : $$ = pg_malloc_object(Permutation);
196 1298 : $$->nsteps = $2.nelements;
197 1298 : $$->steps = (PermutationStep **) $2.elements;
198 : }
199 : ;
200 :
201 : permutation_step_list:
202 : permutation_step_list permutation_step
203 : {
204 8322 : $$.elements = pg_realloc_array($1.elements, void *,
205 : $1.nelements + 1);
206 8322 : $$.elements[$1.nelements] = $2;
207 8322 : $$.nelements = $1.nelements + 1;
208 : }
209 : | permutation_step
210 : {
211 1298 : $$.nelements = 1;
212 1298 : $$.elements = pg_malloc_object(void *);
213 1298 : $$.elements[0] = $1;
214 : }
215 : ;
216 :
217 : permutation_step:
218 : identifier
219 : {
220 9545 : $$ = pg_malloc_object(PermutationStep);
221 9545 : $$->name = $1;
222 9545 : $$->blockers = NULL;
223 9545 : $$->nblockers = 0;
224 9545 : $$->step = NULL;
225 : }
226 : | identifier '(' blocker_list ')'
227 : {
228 75 : $$ = pg_malloc_object(PermutationStep);
229 75 : $$->name = $1;
230 75 : $$->blockers = (PermutationStepBlocker **) $3.elements;
231 75 : $$->nblockers = $3.nelements;
232 75 : $$->step = NULL;
233 : }
234 : ;
235 :
236 : blocker_list:
237 : blocker_list ',' blocker
238 : {
239 0 : $$.elements = pg_realloc_array($1.elements, void *,
240 : $1.nelements + 1);
241 0 : $$.elements[$1.nelements] = $3;
242 0 : $$.nelements = $1.nelements + 1;
243 : }
244 : | blocker
245 : {
246 75 : $$.nelements = 1;
247 75 : $$.elements = pg_malloc_object(void *);
248 75 : $$.elements[0] = $1;
249 : }
250 : ;
251 :
252 : blocker:
253 : identifier
254 : {
255 62 : $$ = pg_malloc_object(PermutationStepBlocker);
256 62 : $$->stepname = $1;
257 62 : $$->blocktype = PSB_OTHER_STEP;
258 62 : $$->num_notices = -1;
259 62 : $$->step = NULL;
260 62 : $$->target_notices = -1;
261 : }
262 : | identifier NOTICES INTEGER
263 : {
264 1 : $$ = pg_malloc_object(PermutationStepBlocker);
265 1 : $$->stepname = $1;
266 1 : $$->blocktype = PSB_NUM_NOTICES;
267 1 : $$->num_notices = $3;
268 1 : $$->step = NULL;
269 1 : $$->target_notices = -1;
270 : }
271 : | '*'
272 : {
273 12 : $$ = pg_malloc_object(PermutationStepBlocker);
274 12 : $$->stepname = NULL;
275 12 : $$->blocktype = PSB_ONCE;
276 12 : $$->num_notices = -1;
277 12 : $$->step = NULL;
278 12 : $$->target_notices = -1;
279 : }
280 : ;
281 :
282 : %%
|