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 179 : parseresult.setupsqls = (char **) $1.elements;
69 179 : parseresult.nsetupsqls = $1.nelements;
70 179 : parseresult.teardownsql = $2;
71 179 : parseresult.sessions = (Session **) $3.elements;
72 179 : parseresult.nsessions = $3.nelements;
73 179 : parseresult.permutations = (Permutation **) $4.elements;
74 179 : parseresult.npermutations = $4.nelements;
75 : }
76 : ;
77 :
78 : setup_list:
79 : /* EMPTY */
80 : {
81 179 : $$.elements = NULL;
82 179 : $$.nelements = 0;
83 : }
84 : | setup_list setup
85 : {
86 190 : $$.elements = pg_realloc_array($1.elements, void *,
87 : $1.nelements + 1);
88 190 : $$.elements[$1.nelements] = $2;
89 190 : $$.nelements = $1.nelements + 1;
90 : }
91 : ;
92 :
93 : opt_setup:
94 190 : /* EMPTY */ { $$ = NULL; }
95 253 : | setup { $$ = $1; }
96 : ;
97 :
98 : setup:
99 443 : SETUP sqlblock { $$ = $2; }
100 : ;
101 :
102 : opt_teardown:
103 421 : /* EMPTY */ { $$ = NULL; }
104 201 : | TEARDOWN sqlblock { $$ = $2; }
105 : ;
106 :
107 : session_list:
108 : session_list session
109 : {
110 264 : $$.elements = pg_realloc_array($1.elements, void *,
111 : $1.nelements + 1);
112 264 : $$.elements[$1.nelements] = $2;
113 264 : $$.nelements = $1.nelements + 1;
114 : }
115 : | session
116 : {
117 179 : $$.nelements = 1;
118 179 : $$.elements = pg_malloc_object(void *);
119 179 : $$.elements[0] = $1;
120 : }
121 : ;
122 :
123 : session:
124 : SESSION identifier opt_setup step_list opt_teardown
125 : {
126 443 : $$ = pg_malloc_object(Session);
127 443 : $$->name = $2;
128 443 : $$->setupsql = $3;
129 443 : $$->steps = (Step **) $4.elements;
130 443 : $$->nsteps = $4.nelements;
131 443 : $$->teardownsql = $5;
132 : }
133 : ;
134 :
135 : step_list:
136 : step_list step
137 : {
138 1395 : $$.elements = pg_realloc_array($1.elements, void *,
139 : $1.nelements + 1);
140 1395 : $$.elements[$1.nelements] = $2;
141 1395 : $$.nelements = $1.nelements + 1;
142 : }
143 : | step
144 : {
145 443 : $$.nelements = 1;
146 443 : $$.elements = pg_malloc_object(void *);
147 443 : $$.elements[0] = $1;
148 : }
149 : ;
150 :
151 :
152 : step:
153 : STEP identifier sqlblock
154 : {
155 1838 : $$ = pg_malloc_object(Step);
156 1838 : $$->name = $2;
157 1838 : $$->sql = $3;
158 1838 : $$->session = -1; /* until filled */
159 1838 : $$->used = false;
160 : }
161 : ;
162 :
163 :
164 : opt_permutation_list:
165 : permutation_list
166 : {
167 165 : $$ = $1;
168 : }
169 : | /* EMPTY */
170 : {
171 14 : $$.elements = NULL;
172 14 : $$.nelements = 0;
173 : }
174 :
175 : permutation_list:
176 : permutation_list permutation
177 : {
178 1203 : $$.elements = pg_realloc_array($1.elements, void *,
179 : $1.nelements + 1);
180 1203 : $$.elements[$1.nelements] = $2;
181 1203 : $$.nelements = $1.nelements + 1;
182 : }
183 : | permutation
184 : {
185 165 : $$.nelements = 1;
186 165 : $$.elements = pg_malloc_object(void *);
187 165 : $$.elements[0] = $1;
188 : }
189 : ;
190 :
191 :
192 : permutation:
193 : PERMUTATION permutation_step_list
194 : {
195 1368 : $$ = pg_malloc_object(Permutation);
196 1368 : $$->nsteps = $2.nelements;
197 1368 : $$->steps = (PermutationStep **) $2.elements;
198 : }
199 : ;
200 :
201 : permutation_step_list:
202 : permutation_step_list permutation_step
203 : {
204 8646 : $$.elements = pg_realloc_array($1.elements, void *,
205 : $1.nelements + 1);
206 8646 : $$.elements[$1.nelements] = $2;
207 8646 : $$.nelements = $1.nelements + 1;
208 : }
209 : | permutation_step
210 : {
211 1368 : $$.nelements = 1;
212 1368 : $$.elements = pg_malloc_object(void *);
213 1368 : $$.elements[0] = $1;
214 : }
215 : ;
216 :
217 : permutation_step:
218 : identifier
219 : {
220 9931 : $$ = pg_malloc_object(PermutationStep);
221 9931 : $$->name = $1;
222 9931 : $$->blockers = NULL;
223 9931 : $$->nblockers = 0;
224 9931 : $$->step = NULL;
225 : }
226 : | identifier '(' blocker_list ')'
227 : {
228 83 : $$ = pg_malloc_object(PermutationStep);
229 83 : $$->name = $1;
230 83 : $$->blockers = (PermutationStepBlocker **) $3.elements;
231 83 : $$->nblockers = $3.nelements;
232 83 : $$->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 83 : $$.nelements = 1;
247 83 : $$.elements = pg_malloc_object(void *);
248 83 : $$.elements[0] = $1;
249 : }
250 : ;
251 :
252 : blocker:
253 : identifier
254 : {
255 69 : $$ = pg_malloc_object(PermutationStepBlocker);
256 69 : $$->stepname = $1;
257 69 : $$->blocktype = PSB_OTHER_STEP;
258 69 : $$->num_notices = -1;
259 69 : $$->step = NULL;
260 69 : $$->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 13 : $$ = pg_malloc_object(PermutationStepBlocker);
274 13 : $$->stepname = NULL;
275 13 : $$->blocktype = PSB_ONCE;
276 13 : $$->num_notices = -1;
277 13 : $$->step = NULL;
278 13 : $$->target_notices = -1;
279 : }
280 : ;
281 :
282 : %%
|