Added quantiling UDAFs
[com/gs-lite.git] / src / tools / xml.l
1 /* ------------------------------------------------\r
2 Copyright 2014 AT&T Intellectual Property\r
3    Licensed under the Apache License, Version 2.0 (the "License");\r
4    you may not use this file except in compliance with the License.\r
5    You may obtain a copy of the License at\r
6 \r
7      http://www.apache.org/licenses/LICENSE-2.0\r
8 \r
9    Unless required by applicable law or agreed to in writing, software\r
10    distributed under the License is distributed on an "AS IS" BASIS,\r
11    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12    See the License for the specific language governing permissions and\r
13    limitations under the License.\r
14  ------------------------------------------- */\r
15 \r
16 /*\r
17         MUST COMPILE WITH\r
18                 flex -PxmlParser -oxmllexer.cc xml.l\r
19         (or equivalent).\r
20 */      \r
21 \r
22 %{\r
23 /*\r
24  * AT&T lex can't handle this lexer due to lex bugs.  It works with flex\r
25  * 2.3.7, pclex 2.0.5, and MKS lex 3.1a.\r
26  */\r
27 \r
28  // #include "parse_fta.h"\r
29  #include <string.h>\r
30 \r
31 \r
32 \r
33 #include "xml.tab.hh"\r
34 \r
35 /*\r
36         Some includes that flex doesn't include as standard,\r
37         but which are needed.\r
38 */\r
39 \r
40 #include <stdlib.h>\r
41 #include <string.h>\r
42 \r
43 \r
44 //              Prevent flex from defining yywrap as extern "C" \r
45 \r
46 #define YY_SKIP_YYWRAP\r
47 \r
48 /*              No lex lib, supply the yywrap fcn. that normally resides there\r
49 */\r
50 \r
51 int xmlParserwrap(){return(1);}\r
52 \r
53 extern int xmlParserdebug;\r
54 \r
55 \r
56 /*\r
57                 These variables are used for error reporting:\r
58                 flex_xml_lineno : the line currently being parsed when the error occurs.\r
59                 flex_xml_ch : the character on the line where the error occurs\r
60                 flex_xml_linebuf : store the line for reporting.\r
61 \r
62                 NOTE : 1) the fixed size flex_xml_linebuf buffer is dangerous.\r
63                            2) You might get pointed to a place shortly after\r
64                                   where the syntax error occurs.  It is close enough\r
65                                   for now.\r
66 */\r
67 \r
68 int flex_xml_lineno = 1;\r
69 int flex_xml_ch = 0;\r
70 char flex_xml_linebuf[20000];\r
71 \r
72 char *flex_xml_stringinput = NULL;\r
73 int flex_xml_stringinput_ptr = 0;\r
74 FILE *flex_xml_fileinput = NULL;\r
75 int my_xmlParser_yyinput(char *buf, int max_size);\r
76 \r
77 \r
78 \r
79 void xmlParsererror(char *s){\r
80         int i;\r
81         fprintf(stderr,"On line %d, char %d: %s (token %s):\n%s\n",\r
82                                 flex_xml_lineno, flex_xml_ch, s, xmlParsertext, flex_xml_linebuf );\r
83     for(i=0;i<flex_xml_ch;i++){\r
84                 if(flex_xml_linebuf[i] == '\t'){\r
85                         fprintf(stderr,"\t");\r
86                 }else{\r
87                         fprintf(stderr," ");\r
88                 }\r
89         }\r
90         fprintf(stderr,"^\n");\r
91         //      fprintf(stderr,"%*s\n",1+flex_xml_ch,"^");\r
92 }\r
93 \r
94 #undef YY_INPUT\r
95 #define YY_INPUT(b, r, ms) (r = my_xmlParser_yyinput(b,ms))\r
96 \r
97 %}\r
98         /* MKS needs the next line to increase the NFA table */\r
99 %e 1200\r
100 %option noyywrap\r
101 \r
102 %%\r
103 \r
104         /* literal keyword tokens */\r
105 \r
106  /*\r
107                         The actions associated with each text token are to\r
108                         keep track of the current location (for syntax error reporting)\r
109                         and to report any necessary info to the emf.y parse tree builder\r
110 \r
111                         Its likely that there are a number of omissions, inconsistencies\r
112                         (some keywords do not need to be in caps), and relics\r
113                         (keywords such as BETWEEN, INDICATOR, etc., are not used\r
114                          in emf.y)\r
115                         This parser is somewhat of a work in progress.\r
116  */\r
117 \r
118  /*             Query keywords          */\r
119 \r
120 \r
121 \r
122 \r
123 [<>=/]  { flex_xml_ch+=xmlParserleng; return yytext[0]; }\r
124 \r
125         /* names */\r
126 \r
127 [A-Za-z_][A-Za-z0-9_:\-]*       { flex_xml_ch+=xmlParserleng; xmlParserlval.strval = strdup(yytext); return NAME; }\r
128 \r
129 \r
130         /* strings */\r
131 \r
132 \'[^\'\n]*\'    {\r
133                 \r
134                 int c;\r
135                 \r
136                 xmlParserlval.strval = strdup(xmlParsertext+1); \r
137 \r
138                 c = yyinput();\r
139 \r
140                 unput(c);       /* just peeking */\r
141                 if(c != '\'') {\r
142                         flex_xml_ch+=xmlParserleng; \r
143                         xmlParserlval.strval[xmlParserleng-2] = '\0';\r
144                         return STRING_TOKEN;\r
145                 } else\r
146                         yymore();\r
147         }\r
148                 \r
149 \'[^\'\n]*$     { flex_xml_ch+=xmlParserleng; xmlParsererror("Unterminated string"); }\r
150 \r
151  /*                                                                                                                     */\r
152  /*             Newline : advance the error reporting line number       */\r
153  /*             and grab the next line into flex_xml_linebuf                    */\r
154  /*                                                                                                                     */\r
155 \r
156 \n.*            {flex_xml_ch=0; flex_xml_lineno++;\r
157                            strcpy(flex_xml_linebuf,xmlParsertext+1);\r
158                            yyless(1);\r
159                            }\r
160 \r
161 [ \t\r]+        {flex_xml_ch+=xmlParserleng; }  /* white space */\r
162 \r
163 "--".*$         {flex_xml_ch+=xmlParserleng; }; /* comment */\r
164 "//".*$         {flex_xml_ch+=xmlParserleng; }; /* comment */\r
165 "<?xml".*$      {flex_xml_ch+=xmlParserleng; }; /* comment */\r
166 \r
167 .|\n            {flex_xml_ch+=xmlParserleng; fprintf(stderr,"Warning: unknown token (ignored)\n");  xmlParsererror(yytext);}\r
168 \r
169 %%\r
170 \r
171 int my_xmlParser_yyinput(char *buf, int max_size){\r
172         int c = 0;\r
173         int inchar = 0;\r
174         \r
175         if(flex_xml_stringinput != NULL){\r
176                 while(c<max_size){\r
177                         if(flex_xml_stringinput[flex_xml_stringinput_ptr] != '\0'){\r
178                                 buf[c++] = flex_xml_stringinput[flex_xml_stringinput_ptr++];\r
179                         }else{\r
180                                 break;\r
181                         }\r
182                 }\r
183                 return(c);\r
184         }\r
185         \r
186         if(flex_xml_fileinput != NULL){\r
187                 while(c < max_size){\r
188                         inchar = getc(flex_xml_fileinput);\r
189                         if(inchar != EOF){\r
190                                 buf[c++] = inchar;\r
191                         }else{\r
192                                 break;\r
193                         }\r
194                 }\r
195                 return(c);\r
196         }\r
197         \r
198         return(0);\r
199 }\r
200 \r
201 void xmlParser_setfileinput(FILE *f){\r
202         xmlParserrestart(NULL);\r
203 \r
204         flex_xml_fileinput = f;\r
205         flex_xml_stringinput = NULL;\r
206         flex_xml_lineno = 1;\r
207         flex_xml_ch = 0;\r
208 }\r
209 \r
210 void xmlParser_setstringinput(char *s){\r
211         xmlParserrestart(NULL);\r
212 \r
213         flex_xml_fileinput = NULL;\r
214         flex_xml_stringinput = s;\r
215         flex_xml_stringinput_ptr = 0;\r
216         flex_xml_lineno = 1;\r
217         flex_xml_ch = 0;\r
218 }\r
219         \r
220                 \r
221 \r
222 \r
223 \r