3 ** A scanner for EMP-style numeric ranges
8 /* No reason to constrain amount of data slurped */
9 #define YY_READ_BUF_SIZE 16777216
11 /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
13 #define fprintf(file, fmt, msg) ereport(ERROR, (errmsg_internal("%s", msg)))
15 /* Handles to the buffer that the lexer uses internally */
16 static YY_BUFFER_STATE scanbufhandle;
18 static int scanbuflen;
20 /* flex 2.5.4 doesn't bother with a decl for this */
23 void seg_scanner_init(const char *str);
24 void seg_scanner_finish(void);
28 %option never-interactive
33 %option prefix="seg_yy"
37 plumin (\'\+\-\')|(\(\+\-)\)
39 real [+-]?[0-9]+\.[0-9]+
40 float ({integer}|{real})([eE]{integer})?
44 {range} yylval.text = yytext; return RANGE;
45 {plumin} yylval.text = yytext; return PLUMIN;
46 {float} yylval.text = yytext; return SEGFLOAT;
47 \< yylval.text = "<"; return EXTENSION;
48 \> yylval.text = ">"; return EXTENSION;
49 \~ yylval.text = "~"; return EXTENSION;
50 [ \t\n\r\f]+ /* discard spaces */
51 . return yytext[0]; /* alert parser of the garbage */
56 yyerror(const char *message)
58 if (*yytext == YY_END_OF_BUFFER_CHAR)
61 (errcode(ERRCODE_SYNTAX_ERROR),
62 errmsg("bad seg representation"),
63 /* translator: %s is typically "syntax error" */
64 errdetail("%s at end of input", message)));
69 (errcode(ERRCODE_SYNTAX_ERROR),
70 errmsg("bad seg representation"),
71 /* translator: first %s is typically "syntax error" */
72 errdetail("%s at or near \"%s\"", message, yytext)));
78 * Called before any actual parsing is done
81 seg_scanner_init(const char *str)
83 Size slen = strlen(str);
86 * Might be left over after ereport()
88 if (YY_CURRENT_BUFFER)
89 yy_delete_buffer(YY_CURRENT_BUFFER);
92 * Make a scan buffer with special termination needed by flex.
95 scanbuf = palloc(slen + 2);
96 memcpy(scanbuf, str, slen);
97 scanbuf[slen] = scanbuf[slen + 1] = YY_END_OF_BUFFER_CHAR;
98 scanbufhandle = yy_scan_buffer(scanbuf, slen + 2);
105 * Called after parsing is done to clean up after seg_scanner_init()
108 seg_scanner_finish(void)
110 yy_delete_buffer(scanbufhandle);