Update copyright for 2022
[pgsql.git] / src / test / isolation / specparse.y
blobeb368184b8b5aeaec91401f30cb4a6a58bc574a3
1 %{
2 /*-------------------------------------------------------------------------
4 * specparse.y
5 * bison grammar for the isolation test file format
7 * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 *-------------------------------------------------------------------------
13 #include "postgres_fe.h"
15 #include "isolationtester.h"
18 TestSpec parseresult; /* result of parsing is left here */
22 %expect 0
23 %name-prefix="spec_yy"
25 %union
27 char *str;
28 int integer;
29 Session *session;
30 Step *step;
31 Permutation *permutation;
32 PermutationStep *permutationstep;
33 PermutationStepBlocker *blocker;
34 struct
36 void **elements;
37 int nelements;
38 } ptr_list;
41 %type <ptr_list> setup_list
42 %type <str> opt_setup opt_teardown
43 %type <str> setup
44 %type <ptr_list> step_list session_list permutation_list opt_permutation_list
45 %type <ptr_list> permutation_step_list blocker_list
46 %type <session> session
47 %type <step> step
48 %type <permutation> permutation
49 %type <permutationstep> permutation_step
50 %type <blocker> blocker
52 %token <str> sqlblock identifier
53 %token <integer> INTEGER
54 %token NOTICES PERMUTATION SESSION SETUP STEP TEARDOWN TEST
58 TestSpec:
59 setup_list
60 opt_teardown
61 session_list
62 opt_permutation_list
64 parseresult.setupsqls = (char **) $1.elements;
65 parseresult.nsetupsqls = $1.nelements;
66 parseresult.teardownsql = $2;
67 parseresult.sessions = (Session **) $3.elements;
68 parseresult.nsessions = $3.nelements;
69 parseresult.permutations = (Permutation **) $4.elements;
70 parseresult.npermutations = $4.nelements;
74 setup_list:
75 /* EMPTY */
77 $$.elements = NULL;
78 $$.nelements = 0;
80 | setup_list setup
82 $$.elements = pg_realloc($1.elements,
83 ($1.nelements + 1) * sizeof(void *));
84 $$.elements[$1.nelements] = $2;
85 $$.nelements = $1.nelements + 1;
89 opt_setup:
90 /* EMPTY */ { $$ = NULL; }
91 | setup { $$ = $1; }
94 setup:
95 SETUP sqlblock { $$ = $2; }
98 opt_teardown:
99 /* EMPTY */ { $$ = NULL; }
100 | TEARDOWN sqlblock { $$ = $2; }
103 session_list:
104 session_list session
106 $$.elements = pg_realloc($1.elements,
107 ($1.nelements + 1) * sizeof(void *));
108 $$.elements[$1.nelements] = $2;
109 $$.nelements = $1.nelements + 1;
111 | session
113 $$.nelements = 1;
114 $$.elements = pg_malloc(sizeof(void *));
115 $$.elements[0] = $1;
119 session:
120 SESSION identifier opt_setup step_list opt_teardown
122 $$ = pg_malloc(sizeof(Session));
123 $$->name = $2;
124 $$->setupsql = $3;
125 $$->steps = (Step **) $4.elements;
126 $$->nsteps = $4.nelements;
127 $$->teardownsql = $5;
131 step_list:
132 step_list step
134 $$.elements = pg_realloc($1.elements,
135 ($1.nelements + 1) * sizeof(void *));
136 $$.elements[$1.nelements] = $2;
137 $$.nelements = $1.nelements + 1;
139 | step
141 $$.nelements = 1;
142 $$.elements = pg_malloc(sizeof(void *));
143 $$.elements[0] = $1;
148 step:
149 STEP identifier sqlblock
151 $$ = pg_malloc(sizeof(Step));
152 $$->name = $2;
153 $$->sql = $3;
154 $$->session = -1; /* until filled */
155 $$->used = false;
160 opt_permutation_list:
161 permutation_list
163 $$ = $1;
165 | /* EMPTY */
167 $$.elements = NULL;
168 $$.nelements = 0;
171 permutation_list:
172 permutation_list permutation
174 $$.elements = pg_realloc($1.elements,
175 ($1.nelements + 1) * sizeof(void *));
176 $$.elements[$1.nelements] = $2;
177 $$.nelements = $1.nelements + 1;
179 | permutation
181 $$.nelements = 1;
182 $$.elements = pg_malloc(sizeof(void *));
183 $$.elements[0] = $1;
188 permutation:
189 PERMUTATION permutation_step_list
191 $$ = pg_malloc(sizeof(Permutation));
192 $$->nsteps = $2.nelements;
193 $$->steps = (PermutationStep **) $2.elements;
197 permutation_step_list:
198 permutation_step_list permutation_step
200 $$.elements = pg_realloc($1.elements,
201 ($1.nelements + 1) * sizeof(void *));
202 $$.elements[$1.nelements] = $2;
203 $$.nelements = $1.nelements + 1;
205 | permutation_step
207 $$.nelements = 1;
208 $$.elements = pg_malloc(sizeof(void *));
209 $$.elements[0] = $1;
213 permutation_step:
214 identifier
216 $$ = pg_malloc(sizeof(PermutationStep));
217 $$->name = $1;
218 $$->blockers = NULL;
219 $$->nblockers = 0;
220 $$->step = NULL;
222 | identifier '(' blocker_list ')'
224 $$ = pg_malloc(sizeof(PermutationStep));
225 $$->name = $1;
226 $$->blockers = (PermutationStepBlocker **) $3.elements;
227 $$->nblockers = $3.nelements;
228 $$->step = NULL;
232 blocker_list:
233 blocker_list ',' blocker
235 $$.elements = pg_realloc($1.elements,
236 ($1.nelements + 1) * sizeof(void *));
237 $$.elements[$1.nelements] = $3;
238 $$.nelements = $1.nelements + 1;
240 | blocker
242 $$.nelements = 1;
243 $$.elements = pg_malloc(sizeof(void *));
244 $$.elements[0] = $1;
248 blocker:
249 identifier
251 $$ = pg_malloc(sizeof(PermutationStepBlocker));
252 $$->stepname = $1;
253 $$->blocktype = PSB_OTHER_STEP;
254 $$->num_notices = -1;
255 $$->step = NULL;
256 $$->target_notices = -1;
258 | identifier NOTICES INTEGER
260 $$ = pg_malloc(sizeof(PermutationStepBlocker));
261 $$->stepname = $1;
262 $$->blocktype = PSB_NUM_NOTICES;
263 $$->num_notices = $3;
264 $$->step = NULL;
265 $$->target_notices = -1;
267 | '*'
269 $$ = pg_malloc(sizeof(PermutationStepBlocker));
270 $$->stepname = NULL;
271 $$->blocktype = PSB_ONCE;
272 $$->num_notices = -1;
273 $$->step = NULL;
274 $$->target_notices = -1;
280 #include "specscanner.c"