blob: e95318a1b356cb8a73e781e67be82ae40ae03fa9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
%{
/*-------------------------------------------------------------------------
*
* specscanner.l
* a lexical scanner for an isolation test specification
*
* Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*-------------------------------------------------------------------------
*/
static int yyline = 1; /* line number for error reporting */
static char litbuf[1024];
static int litbufpos = 0;
static void addlitchar(char c);
%}
%option 8bit
%option never-interactive
%option nodefault
%option noinput
%option nounput
%option noyywrap
%option warn
%option prefix="spec_yy"
%x sql
%x qstr
non_newline [^\n\r]
space [ \t\r\f]
comment ("#"{non_newline}*)
%%
permutation { return(PERMUTATION); }
session { return(SESSION); }
setup { return(SETUP); }
step { return(STEP); }
teardown { return(TEARDOWN); }
[\n] { yyline++; }
{comment} { /* ignore */ }
{space} { /* ignore */ }
/* Quoted strings: "foo" */
\" {
litbufpos = 0;
BEGIN(qstr);
}
<qstr>\" {
litbuf[litbufpos] = '\0';
yylval.str = strdup(litbuf);
BEGIN(INITIAL);
return(string);
}
<qstr>. { addlitchar(yytext[0]); }
<qstr>\n { yyerror("unexpected newline in quoted string"); }
<qstr><<EOF>> { yyerror("unterminated quoted string"); }
/* SQL blocks: { UPDATE ... } */
"{"{space}* {
litbufpos = 0;
BEGIN(sql);
}
<sql>{space}*"}" {
litbuf[litbufpos] = '\0';
yylval.str = strdup(litbuf);
BEGIN(INITIAL);
return(sqlblock);
}
<sql>. {
addlitchar(yytext[0]);
}
<sql>\n {
yyline++;
addlitchar(yytext[0]);
}
<sql><<EOF>> {
yyerror("unterminated sql block");
}
. {
fprintf(stderr, "syntax error at line %d: unexpected character \"%s\"\n", yyline, yytext);
exit(1);
}
%%
static void
addlitchar(char c)
{
if (litbufpos >= sizeof(litbuf) - 1)
{
fprintf(stderr, "SQL step too long\n");
exit(1);
}
litbuf[litbufpos++] = c;
}
void
yyerror(const char *message)
{
fprintf(stderr, "%s at line %d\n", message, yyline);
exit(1);
}
|