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