psql: Add missing punctuation in help output
[pgsql.git] / contrib / cube / cubescan.l
bloba30fbfc3111a25c2493931bc81d9dc7fbf2e7b17
1 %top{
2 /*
3  * A scanner for EMP-style numeric ranges
4  * contrib/cube/cubescan.l
5  */
7 #include "postgres.h"
9 /*
10  * NB: include cubeparse.h only AFTER defining YYSTYPE (to match cubeparse.y)
11  * and cubedata.h for NDBOX.
12  */
13 #include "cubedata.h"
14 #define YYSTYPE char *
15 #include "cubeparse.h"
19 /* LCOV_EXCL_START */
21 /* No reason to constrain amount of data slurped */
22 #define YY_READ_BUF_SIZE 16777216
24 /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
25 #undef fprintf
26 #define fprintf(file, fmt, msg)  fprintf_to_ereport(fmt, msg)
28 static void
29 fprintf_to_ereport(const char *fmt, const char *msg)
31         ereport(ERROR, (errmsg_internal("%s", msg)));
34 /* Handles to the buffer that the lexer uses internally */
35 static YY_BUFFER_STATE scanbufhandle;
36 static char *scanbuf;
39 %option 8bit
40 %option never-interactive
41 %option nodefault
42 %option noinput
43 %option nounput
44 %option noyywrap
45 %option warn
46 %option prefix="cube_yy"
49 n            [0-9]+
50 integer      [+-]?{n}
51 real         [+-]?({n}\.{n}?|\.{n})
52 float        ({integer}|{real})([eE]{integer})?
53 infinity     [+-]?[iI][nN][fF]([iI][nN][iI][tT][yY])?
54 NaN          [nN][aA][nN]
58 {float}      cube_yylval = yytext; return CUBEFLOAT;
59 {infinity}   cube_yylval = yytext; return CUBEFLOAT;
60 {NaN}        cube_yylval = yytext; return CUBEFLOAT;
61 \[           cube_yylval = "("; return O_BRACKET;
62 \]           cube_yylval = ")"; return C_BRACKET;
63 \(           cube_yylval = "("; return O_PAREN;
64 \)           cube_yylval = ")"; return C_PAREN;
65 \,           cube_yylval = ","; return COMMA;
66 [ \t\n\r\f\v]+ /* discard spaces */
67 .            return yytext[0]; /* alert parser of the garbage */
71 /* LCOV_EXCL_STOP */
73 /* result and scanbuflen are not used, but Bison expects this signature */
74 void
75 cube_yyerror(NDBOX **result, Size scanbuflen,
76                          struct Node *escontext,
77                          const char *message)
79         if (*yytext == YY_END_OF_BUFFER_CHAR)
80         {
81                 errsave(escontext,
82                                 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
83                                  errmsg("invalid input syntax for cube"),
84                                  /* translator: %s is typically "syntax error" */
85                                  errdetail("%s at end of input", message)));
86         }
87         else
88         {
89                 errsave(escontext,
90                                 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
91                                  errmsg("invalid input syntax for cube"),
92                                  /* translator: first %s is typically "syntax error" */
93                                  errdetail("%s at or near \"%s\"", message, yytext)));
94         }
99  * Called before any actual parsing is done
100  */
101 void
102 cube_scanner_init(const char *str, Size *scanbuflen)
104         Size            slen = strlen(str);
106         /*
107          * Might be left over after ereport()
108          */
109         if (YY_CURRENT_BUFFER)
110                 yy_delete_buffer(YY_CURRENT_BUFFER);
112         /*
113          * Make a scan buffer with special termination needed by flex.
114          */
115         *scanbuflen = slen;
116         scanbuf = palloc(slen + 2);
117         memcpy(scanbuf, str, slen);
118         scanbuf[slen] = scanbuf[slen + 1] = YY_END_OF_BUFFER_CHAR;
119         scanbufhandle = yy_scan_buffer(scanbuf, slen + 2);
121         BEGIN(INITIAL);
126  * Called after parsing is done to clean up after cube_scanner_init()
127  */
128 void
129 cube_scanner_finish(void)
131         yy_delete_buffer(scanbufhandle);
132         pfree(scanbuf);