Branch data Line data Source code
1 : : %top{
2 : : /*
3 : : * A scanner for EMP-style numeric ranges
4 : : * contrib/cube/cubescan.l
5 : : */
6 : :
7 : : #include "postgres.h"
8 : :
9 : : #include "cubedata.h"
10 : : #include "cubeparse.h" /* must be after cubedata.h for YYSTYPE and NDBOX */
11 : : }
12 : :
13 : : %{
14 : : /* LCOV_EXCL_START */
15 : :
16 : : /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
17 : : #undef fprintf
18 : : #define fprintf(file, fmt, msg) fprintf_to_ereport(fmt, msg)
19 : :
20 : : static void
21 : 0 : fprintf_to_ereport(const char *fmt, const char *msg)
22 : : {
23 [ # # ]: 0 : ereport(ERROR, (errmsg_internal("%s", msg)));
24 : : }
25 : : %}
26 : :
27 : : %option reentrant
28 : : %option bison-bridge
29 : : %option 8bit
30 : : %option never-interactive
31 : : %option nodefault
32 : : %option noinput
33 : : %option nounput
34 : : %option noyywrap
35 : : %option noyyalloc
36 : : %option noyyrealloc
37 : : %option noyyfree
38 : : %option warn
39 : : %option prefix="cube_yy"
40 : :
41 : :
42 : : n [0-9]+
43 : : integer [+-]?{n}
44 : : real [+-]?({n}\.{n}?|\.{n})
45 : : float ({integer}|{real})([eE]{integer})?
46 : : infinity [+-]?[iI][nN][fF]([iI][nN][iI][tT][yY])?
47 : : NaN [nN][aA][nN]
48 : :
49 : : %%
50 : :
51 : 14058 : {float} *yylval = yytext; return CUBEFLOAT;
52 : 2 : {infinity} *yylval = yytext; return CUBEFLOAT;
53 : 2 : {NaN} *yylval = yytext; return CUBEFLOAT;
54 : 1 : \[ *yylval = "("; return O_BRACKET;
55 : 23 : \] *yylval = ")"; return C_BRACKET;
56 : 21 : \( *yylval = "("; return O_PAREN;
57 : 6604 : \) *yylval = ")"; return C_PAREN;
58 : 6602 : \, *yylval = ","; return COMMA;
59 : 10645 : [ \t\n\r\f\v]+ /* discard spaces */
60 : 39 : . return yytext[0]; /* alert parser of the garbage */
61 : 6 :
62 : 0 : %%
63 : :
64 : : /* LCOV_EXCL_STOP */
65 : :
66 : : /* result and scanbuflen are not used, but Bison expects this signature */
67 : : void
68 : 24 : cube_yyerror(NDBOX **result, Size scanbuflen,
69 : : struct Node *escontext,
70 : : yyscan_t yyscanner,
71 : : const char *message)
72 : : {
73 : 24 : struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; /* needed for yytext
74 : : * macro */
75 : :
76 [ + + ]: 24 : if (*yytext == YY_END_OF_BUFFER_CHAR)
77 : : {
78 [ + - ]: 3 : errsave(escontext,
79 : : (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
80 : : errmsg("invalid input syntax for cube"),
81 : : /* translator: %s is typically "syntax error" */
82 : : errdetail("%s at end of input", message)));
83 : : }
84 : : else
85 : : {
86 [ + + ]: 21 : errsave(escontext,
87 : : (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
88 : : errmsg("invalid input syntax for cube"),
89 : : /* translator: first %s is typically "syntax error" */
90 : : errdetail("%s at or near \"%s\"", message, yytext)));
91 : : }
92 : 1 : }
93 : :
94 : :
95 : : /*
96 : : * Called before any actual parsing is done
97 : : */
98 : : void
99 : 3435 : cube_scanner_init(const char *str, Size *scanbuflen, yyscan_t *yyscannerp)
100 : : {
101 : 3435 : Size slen = strlen(str);
102 : : yyscan_t yyscanner;
103 : :
104 [ - + ]: 3435 : if (yylex_init(yyscannerp) != 0)
105 [ # # ]: 0 : elog(ERROR, "yylex_init() failed: %m");
106 : :
107 : 3435 : yyscanner = *yyscannerp;
108 : :
109 : 3435 : yy_scan_bytes(str, slen, yyscanner);
110 : 3435 : *scanbuflen = slen;
111 : 3435 : }
112 : :
113 : :
114 : : /*
115 : : * Called after parsing is done to clean up after cube_scanner_init()
116 : : */
117 : : void
118 : 3405 : cube_scanner_finish(yyscan_t yyscanner)
119 : : {
120 : 3405 : yylex_destroy(yyscanner);
121 : 3405 : }
122 : :
123 : : /*
124 : : * Interface functions to make flex use palloc() instead of malloc().
125 : : * It'd be better to make these static, but flex insists otherwise.
126 : : */
127 : :
128 : : void *
129 : 13740 : yyalloc(yy_size_t size, yyscan_t yyscanner)
130 : : {
131 : 13740 : return palloc(size);
132 : : }
133 : :
134 : : void *
135 : 0 : yyrealloc(void *ptr, yy_size_t size, yyscan_t yyscanner)
136 : : {
137 [ # # ]: 0 : if (ptr)
138 : 0 : return repalloc(ptr, size);
139 : : else
140 : 0 : return palloc(size);
141 : : }
142 : :
143 : : void
144 : 17025 : yyfree(void *ptr, yyscan_t yyscanner)
145 : : {
146 [ + + ]: 17025 : if (ptr)
147 : 13620 : pfree(ptr);
148 : 17025 : }
|