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