PostgreSQL Source Code git master
specscanner.l File Reference
#include "postgres_fe.h"
#include "isolationtester.h"
#include "specparse.h"
Include dependency graph for specscanner.l:

Go to the source code of this file.

Macros

#define LITBUF_INIT   1024 /* initial size of litbuf */
 

Functions

static void addlitchar (char c)
 
int yylex (void)
 
void spec_yyerror (const char *message)
 

Variables

static int yyline = 1
 
static char * litbuf = NULL
 
static size_t litbufsize = 0
 
static size_t litbufpos = 0
 

Macro Definition Documentation

◆ LITBUF_INIT

#define LITBUF_INIT   1024 /* initial size of litbuf */

Definition at line 25 of file specscanner.l.

Function Documentation

◆ addlitchar()

static void addlitchar ( char  c)
static

Definition at line 150 of file specscanner.l.

151{
152 /* We must always leave room to add a trailing \0 */
153 if (litbufpos >= litbufsize - 1)
154 {
155 /* Double the size of litbuf if it gets full */
158 }
159 litbuf[litbufpos++] = c;
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
char * c
static size_t litbufsize
Definition: specscanner.l:27
static size_t litbufpos
Definition: specscanner.l:28
static char * litbuf
Definition: specscanner.l:26
160}

References litbuf, litbufpos, litbufsize, and pg_realloc().

◆ spec_yyerror()

void spec_yyerror ( const char *  message)

Definition at line 163 of file specscanner.l.

164{
165 fprintf(stderr, "%s at line %d\n", message, yyline);
166 exit(1);
#define fprintf(file, fmt, msg)
Definition: cubescan.l:21
exit(1)
static int yyline
Definition: specscanner.l:23
167}

References exit(), fprintf, and yyline.

◆ yylex()

int yylex ( void  )

Definition at line 62 of file specscanner.l.

64 {
65 /* Allocate litbuf in first call of yylex() */
66 if (litbuf == NULL)
67 {
70 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
#define LITBUF_INIT
Definition: specscanner.l:25
71%}
72
73 /* Keywords (must appear before the {identifier} rule!) */
74notices { return NOTICES; }
75permutation { return PERMUTATION; }
76session { return SESSION; }
77setup { return SETUP; }
78step { return STEP; }
79teardown { return TEARDOWN; }
80
81 /* Whitespace and comments */
82[\n] { yyline++; }
83{comment} { /* ignore */ }
84{space} { /* ignore */ }
85
86 /* Plain identifiers */
87{identifier} {
88 spec_yylval.str = pg_strdup(yytext);
89 return(identifier);
90 }
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
91
92 /* Quoted identifiers: "foo" */
93\" {
94 litbufpos = 0;
95 BEGIN(qident);
96 }
97<qident>\"\" { addlitchar(yytext[0]); }
98<qident>\" {
99 litbuf[litbufpos] = '\0';
100 spec_yylval.str = pg_strdup(litbuf);
101 BEGIN(INITIAL);
102 return(identifier);
103 }
104<qident>. { addlitchar(yytext[0]); }
105<qident>\n { spec_yyerror("unexpected newline in quoted identifier"); }
106<qident><<EOF>> { spec_yyerror("unterminated quoted identifier"); }
107
108 /* SQL blocks: { UPDATE ... } */
109 /* We trim leading/trailing whitespace, otherwise they're unprocessed */
110"{"{space}* {
111
112 litbufpos = 0;
113 BEGIN(sql);
114 }
115<sql>{space}*"}" {
116 litbuf[litbufpos] = '\0';
117 spec_yylval.str = pg_strdup(litbuf);
118 BEGIN(INITIAL);
119 return(sqlblock);
120 }
121<sql>. {
122 addlitchar(yytext[0]);
123 }
static void addlitchar(char c)
Definition: specscanner.l:150
124<sql>\n {
125 yyline++;
126 addlitchar(yytext[0]);
127 }
128<sql><<EOF>> {
129 spec_yyerror("unterminated sql block");
130 }
void spec_yyerror(const char *message)
Definition: specscanner.l:163
131
132 /* Numbers and punctuation */
133{digit}+ {
134 spec_yylval.integer = atoi(yytext);
135 return INTEGER;
136 }
137
138{self} { return yytext[0]; }
139
140 /* Anything else is an error */
141. {
142 fprintf(stderr, "syntax error at line %d: unexpected character \"%s\"\n", yyline, yytext);
143 exit(1);
144 }
145%%

Variable Documentation

◆ litbuf

char* litbuf = NULL
static

Definition at line 26 of file specscanner.l.

Referenced by addlitchar().

◆ litbufpos

size_t litbufpos = 0
static

Definition at line 28 of file specscanner.l.

Referenced by addlitchar().

◆ litbufsize

size_t litbufsize = 0
static

Definition at line 27 of file specscanner.l.

Referenced by addlitchar().

◆ yyline

int yyline = 1
static

Definition at line 23 of file specscanner.l.

Referenced by spec_yyerror().