Age Owner TLA 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 : {
4991 kgrittn@postgresql.o 68 CBC 156 : parseresult.setupsqls = (char **) $1.elements;
69 156 : parseresult.nsetupsqls = $1.nelements;
5566 heikki.linnakangas@i 70 156 : parseresult.teardownsql = $2;
71 156 : parseresult.sessions = (Session **) $3.elements;
72 156 : parseresult.nsessions = $3.nelements;
73 156 : parseresult.permutations = (Permutation **) $4.elements;
74 156 : parseresult.npermutations = $4.nelements;
75 : }
76 : ;
77 :
78 : setup_list:
79 : /* EMPTY */
80 : {
4991 kgrittn@postgresql.o 81 156 : $$.elements = NULL;
82 156 : $$.nelements = 0;
83 : }
84 : | setup_list setup
85 : {
67 michael@paquier.xyz 86 GNC 164 : $$.elements = pg_realloc_array($1.elements, void *,
87 : $1.nelements + 1);
4991 kgrittn@postgresql.o 88 CBC 164 : $$.elements[$1.nelements] = $2;
89 164 : $$.nelements = $1.nelements + 1;
90 : }
91 : ;
92 :
93 : opt_setup:
5566 heikki.linnakangas@i 94 156 : /* EMPTY */ { $$ = NULL; }
4991 kgrittn@postgresql.o 95 228 : | setup { $$ = $1; }
96 : ;
97 :
98 : setup:
99 392 : SETUP sqlblock { $$ = $2; }
100 : ;
101 :
102 : opt_teardown:
5566 heikki.linnakangas@i 103 367 : /* EMPTY */ { $$ = NULL; }
104 173 : | TEARDOWN sqlblock { $$ = $2; }
105 : ;
106 :
107 : session_list:
108 : session_list session
109 : {
67 michael@paquier.xyz 110 GNC 228 : $$.elements = pg_realloc_array($1.elements, void *,
111 : $1.nelements + 1);
5566 heikki.linnakangas@i 112 CBC 228 : $$.elements[$1.nelements] = $2;
113 228 : $$.nelements = $1.nelements + 1;
114 : }
115 : | session
116 : {
117 156 : $$.nelements = 1;
67 michael@paquier.xyz 118 GNC 156 : $$.elements = pg_malloc_object(void *);
5566 heikki.linnakangas@i 119 CBC 156 : $$.elements[0] = $1;
120 : }
121 : ;
122 :
123 : session:
124 : SESSION identifier opt_setup step_list opt_teardown
125 : {
67 michael@paquier.xyz 126 GNC 384 : $$ = pg_malloc_object(Session);
5566 heikki.linnakangas@i 127 CBC 384 : $$->name = $2;
128 384 : $$->setupsql = $3;
129 384 : $$->steps = (Step **) $4.elements;
130 384 : $$->nsteps = $4.nelements;
131 384 : $$->teardownsql = $5;
132 : }
133 : ;
134 :
135 : step_list:
136 : step_list step
137 : {
67 michael@paquier.xyz 138 GNC 1258 : $$.elements = pg_realloc_array($1.elements, void *,
139 : $1.nelements + 1);
5566 heikki.linnakangas@i 140 CBC 1258 : $$.elements[$1.nelements] = $2;
141 1258 : $$.nelements = $1.nelements + 1;
142 : }
143 : | step
144 : {
145 384 : $$.nelements = 1;
67 michael@paquier.xyz 146 GNC 384 : $$.elements = pg_malloc_object(void *);
5566 heikki.linnakangas@i 147 CBC 384 : $$.elements[0] = $1;
148 : }
149 : ;
150 :
151 :
152 : step:
153 : STEP identifier sqlblock
154 : {
67 michael@paquier.xyz 155 GNC 1642 : $$ = pg_malloc_object(Step);
5566 heikki.linnakangas@i 156 CBC 1642 : $$->name = $2;
157 1642 : $$->sql = $3;
1778 tgl@sss.pgh.pa.us 158 1642 : $$->session = -1; /* until filled */
2446 michael@paquier.xyz 159 1642 : $$->used = false;
160 : }
161 : ;
162 :
163 :
164 : opt_permutation_list:
165 : permutation_list
166 : {
5566 heikki.linnakangas@i 167 142 : $$ = $1;
168 : }
169 : | /* EMPTY */
170 : {
171 14 : $$.elements = NULL;
172 14 : $$.nelements = 0;
173 : }
174 :
175 : permutation_list:
176 : permutation_list permutation
177 : {
67 michael@paquier.xyz 178 GNC 1287 : $$.elements = pg_realloc_array($1.elements, void *,
179 : $1.nelements + 1);
5566 heikki.linnakangas@i 180 CBC 1287 : $$.elements[$1.nelements] = $2;
181 1287 : $$.nelements = $1.nelements + 1;
182 : }
183 : | permutation
184 : {
185 142 : $$.nelements = 1;
67 michael@paquier.xyz 186 GNC 142 : $$.elements = pg_malloc_object(void *);
5566 heikki.linnakangas@i 187 CBC 142 : $$.elements[0] = $1;
188 : }
189 : ;
190 :
191 :
192 : permutation:
193 : PERMUTATION permutation_step_list
194 : {
67 michael@paquier.xyz 195 GNC 1429 : $$ = pg_malloc_object(Permutation);
5566 heikki.linnakangas@i 196 CBC 1429 : $$->nsteps = $2.nelements;
1778 tgl@sss.pgh.pa.us 197 1429 : $$->steps = (PermutationStep **) $2.elements;
198 : }
199 : ;
200 :
201 : permutation_step_list:
202 : permutation_step_list permutation_step
203 : {
67 michael@paquier.xyz 204 GNC 9240 : $$.elements = pg_realloc_array($1.elements, void *,
205 : $1.nelements + 1);
5566 heikki.linnakangas@i 206 CBC 9240 : $$.elements[$1.nelements] = $2;
207 9240 : $$.nelements = $1.nelements + 1;
208 : }
209 : | permutation_step
210 : {
211 1429 : $$.nelements = 1;
67 michael@paquier.xyz 212 GNC 1429 : $$.elements = pg_malloc_object(void *);
5566 heikki.linnakangas@i 213 CBC 1429 : $$.elements[0] = $1;
214 : }
215 : ;
216 :
217 : permutation_step:
218 : identifier
219 : {
67 michael@paquier.xyz 220 GNC 10594 : $$ = pg_malloc_object(PermutationStep);
1778 tgl@sss.pgh.pa.us 221 CBC 10594 : $$->name = $1;
222 10594 : $$->blockers = NULL;
223 10594 : $$->nblockers = 0;
224 10594 : $$->step = NULL;
225 : }
226 : | identifier '(' blocker_list ')'
227 : {
67 michael@paquier.xyz 228 GNC 75 : $$ = pg_malloc_object(PermutationStep);
1778 tgl@sss.pgh.pa.us 229 CBC 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 : {
67 michael@paquier.xyz 239 UNC 0 : $$.elements = pg_realloc_array($1.elements, void *,
240 : $1.nelements + 1);
1778 tgl@sss.pgh.pa.us 241 UBC 0 : $$.elements[$1.nelements] = $3;
242 0 : $$.nelements = $1.nelements + 1;
243 : }
244 : | blocker
245 : {
1778 tgl@sss.pgh.pa.us 246 CBC 75 : $$.nelements = 1;
67 michael@paquier.xyz 247 GNC 75 : $$.elements = pg_malloc_object(void *);
1778 tgl@sss.pgh.pa.us 248 CBC 75 : $$.elements[0] = $1;
249 : }
250 : ;
251 :
252 : blocker:
253 : identifier
254 : {
67 michael@paquier.xyz 255 GNC 62 : $$ = pg_malloc_object(PermutationStepBlocker);
1778 tgl@sss.pgh.pa.us 256 CBC 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 : {
67 michael@paquier.xyz 264 GNC 1 : $$ = pg_malloc_object(PermutationStepBlocker);
1778 tgl@sss.pgh.pa.us 265 CBC 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 : {
67 michael@paquier.xyz 273 GNC 12 : $$ = pg_malloc_object(PermutationStepBlocker);
1778 tgl@sss.pgh.pa.us 274 CBC 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 : %%
|