1 /* Validating XML processor for xbt/graphxml.dtd.
2 * Generated 2006/07/18 21:02:16.
4 * This program was generated with the FleXML XML processor generator.
5 * FleXML is Copyright (C) 1999-2005 Kristoffer Rose. All rights reserved.
6 * FleXML is Copyright (C) 2003-2006 Martin Quinson. All rights reserved.
7 * (Id: flexml.pl,v 1.53 2006/07/18 12:12:06 mquinson Exp).
9 * There are two, intertwined parts to this program, part A and part B.
14 * Some parts, here collectively called "Part A", are found in the
15 * FleXML package. They are Copyright (C) 1999-2005 Kristoffer Rose
16 * and Copyright (C) 2003-2006 Martin Quinson. All rights reserved.
18 * You can redistribute, use, perform, display and/or modify "Part A"
19 * provided the following two conditions hold:
21 * 1. The program is distributed WITHOUT ANY WARRANTY from the author of
22 * FleXML; without even the implied warranty of MERCHANTABILITY or
23 * FITNESS FOR A PARTICULAR PURPOSE.
25 * 2. The program distribution conditions do not in any way affect the
26 * distribution conditions of the FleXML system used to generate this
27 * file or any version of FleXML derived from that system.
29 * Notice that these are explicit rights granted to you for files
30 * generated by the FleXML system. For your rights in connection with
31 * the FleXML system itself please consult the GNU General Public License.
36 * The other parts, here collectively called "Part B", and which came
37 * from the DTD used by FleXML to generate this program, can be
38 * distributed (or not, as the case may be) under the terms of whoever
39 * wrote them, provided these terms respect and obey the two conditions
40 * above under the heading "Part A".
42 * The author of and contributors to FleXML specifically disclaim
43 * any copyright interest in "Part B", unless "Part B" was written
44 * by the author of or contributors to FleXML.
50 /* Version strings. */
51 const char rcs_graphxml_flexml_skeleton[] =
52 "$" "Id: skel,v 1.31 2006/07/18 18:21:13 mquinson Exp $";
53 const char rcs_graphxml_flexml[] =
54 "$" "Id: flexml.pl,v 1.53 2006/07/18 12:12:06 mquinson Exp $";
64 /* Generated definitions. */
65 #define FLEXML_yylineno
66 #define FLEXML_BUFFERSTACKSIZE 1000000
68 /* XML processor api. */
69 /* FleXML-provided data. */
70 const char* graphxml_pcdata;
71 AT_graphxml_node_name A_graphxml_node_name;
72 AT_graphxml_edge_source A_graphxml_edge_source;
73 AT_graphxml_node_position_y A_graphxml_node_position_y;
74 AT_graphxml_node_position_x A_graphxml_node_position_x;
75 AT_graphxml_edge_data A_graphxml_edge_data;
76 AT_graphxml_edge_target A_graphxml_edge_target;
77 AT_graphxml_graph_isDirected A_graphxml_graph_isDirected;
78 AT_graphxml_node_label A_graphxml_node_label;
79 AT_graphxml_node_data A_graphxml_node_data;
80 AT_graphxml_edge_label A_graphxml_edge_label;
81 AT_graphxml_edge_length A_graphxml_edge_length;
82 AT_graphxml_edge_name A_graphxml_edge_name;
86 # define ENTER(state) debug_enter(state,#state)
87 # define LEAVE debug_leave()
88 # define SET(state) debug_set(state,#state)
89 static void debug_enter(int, const char*);
90 static void debug_leave(void);
91 static void debug_set(int, const char*);
93 # define ENTER(state) (yy_push_state(state))
94 # define LEAVE (yy_pop_state())
95 # define SET(state) BEGIN(state)
98 /* Generic actions. */
100 #define SUCCEED CLEANUP; return 0
102 #define FAIL return fail
103 static int fail(const char*, ...);
104 const char * graphxml_parse_err_msg(void);
107 static void cleanup(void);
108 #define CLEANUP cleanup()
110 /* Text buffer stack handling. */
111 static char bufferstack[FLEXML_BUFFERSTACKSIZE];
112 static char* limit = bufferstack + FLEXML_BUFFERSTACKSIZE;
113 typedef struct BufferLast_s {
114 struct BufferLast_s *old; const char* saved; char new1[1];
116 #ifdef FLEXML_HasMixed
117 static BufferLast* last = (BufferLast*)0;
119 static char* next = bufferstack;
121 #define BUFFERSET(P) (P = next)
122 #define BUFFERPUTC(C) (assert(next<limit), *(next++) = (C))
123 #define BUFFERDONE (BUFFERPUTC('\0'))
125 #define BUFFERLITERAL(C,P) bufferliteral(C,&(P),yytext)
126 static void bufferliteral(char c, const char** pp, char* text)
128 char *s = strchr(text,c), *e = strrchr(text,c);
129 assert(s <= e); BUFFERSET(*pp);
131 if (isspace(*s)) { BUFFERPUTC(' '); while (isspace(*s)) ++s; }
137 #ifdef FLEXML_HasMixed
138 static void pushbuffer(const char* p)
140 BufferLast* l = (BufferLast*)next;
141 assert(next < limit);
148 static const char* popbuffer(void)
150 BufferLast* l = last;
151 assert(last != (BufferLast*)0);
158 /* General internal entities are `unput' back onto the input stream... */
159 #define ENTITYTEXT(T) \
160 { char *s = (T), *e = s+strlen(s);\
161 while (--e >= s) { unput(*e); }}
164 /* Flex standard options. */
166 %option noyy_top_state
172 /* Flex user-requested options. */
176 /* XML character classes (currently restricted to ASCII). */
178 /* "Common syntactic structures." */
182 /* "Names and Tokens." */
183 NameChar [A-Za-z0-9.:_-]
184 Name [A-Za-z_:]{NameChar}*
185 Names {Name}({S}{Name})*
186 Nmtoken ({NameChar})+
187 Nmtokens {Nmtoken}({S}{Nmtoken})*
190 VersionNum [a-zA-Z0-9_.:-]+
192 Literal \'[^'']*\'|\"[^""]*\"
194 /* Parser states (flex `exclusive start conditions'):
196 * PROLOG the XML prolog of the document before <?xml...>
197 * DOCTYPE the XML prolog of the document after <?xml...>
198 * EPILOG after the root element
199 * INCOMMENT inside an XML comment <!--....-->
200 * INPI inside an XML PI <?...?>
201 * VALUE1 inside a '...'-delimited literal
202 * VALUE2 inside a "..."-delimited literal
203 * CDATA inside a <![CDATA[...] ]> section.
204 * ROOT_<tag> expect root element <tag>
205 * AL_<tag> inside the attribute list for <tag>
206 * IN_<tag> inside a <tag> with element contents (ready for end tag)
207 * IMPOSSIBLE dummy to permit disabling rules; must be last
209 %x PROLOG DOCTYPE EPILOG INCOMMENT INPI VALUE1 VALUE2 CDATA
210 %x ROOT_graphxml_graph AL_graphxml_graph S_graphxml_graph S_graphxml_graph_1 S_graphxml_graph_2 S_graphxml_graph_3 S_graphxml_graph_4 S_graphxml_graph_5 E_graphxml_graph
211 %x ROOT_graphxml_node AL_graphxml_node E_graphxml_node
212 %x ROOT_graphxml_edge AL_graphxml_edge E_graphxml_edge
217 const char* *graphxml_statenames=NULL;
222 /* Bypass Flex's default INITIAL state and begin by parsing the XML prolog. */
226 if(!graphxml_statenames) {graphxml_statenames= (const char **)calloc(IMPOSSIBLE,sizeof(char*));
227 graphxml_statenames[PROLOG] = NULL;
228 graphxml_statenames[DOCTYPE] = NULL;
229 graphxml_statenames[EPILOG] = NULL;
230 graphxml_statenames[INCOMMENT] = NULL;
231 graphxml_statenames[INPI] = NULL;
232 graphxml_statenames[VALUE1] = NULL;
233 graphxml_statenames[VALUE2] = NULL;
234 graphxml_statenames[CDATA] = NULL;
235 graphxml_statenames[ROOT_graphxml_graph] = NULL;
236 graphxml_statenames[AL_graphxml_graph] = NULL;
237 graphxml_statenames[S_graphxml_graph] = "graph";
238 graphxml_statenames[S_graphxml_graph_1] = "graph";
239 graphxml_statenames[S_graphxml_graph_2] = "graph";
240 graphxml_statenames[S_graphxml_graph_3] = "graph";
241 graphxml_statenames[S_graphxml_graph_4] = "graph";
242 graphxml_statenames[S_graphxml_graph_5] = "graph";
243 graphxml_statenames[E_graphxml_graph] = "graph";
244 graphxml_statenames[ROOT_graphxml_node] = NULL;
245 graphxml_statenames[AL_graphxml_node] = NULL;
246 graphxml_statenames[E_graphxml_node] = "node";
247 graphxml_statenames[ROOT_graphxml_edge] = NULL;
248 graphxml_statenames[AL_graphxml_edge] = NULL;
249 graphxml_statenames[E_graphxml_edge] = "edge";
252 /* COMMENTS and PIs: handled uniformly for efficiency. */
254 <ROOT_graphxml_graph,AL_graphxml_graph,S_graphxml_graph,S_graphxml_graph_1,S_graphxml_graph_2,S_graphxml_graph_3,S_graphxml_graph_4,S_graphxml_graph_5,E_graphxml_graph,ROOT_graphxml_node,AL_graphxml_node,E_graphxml_node,ROOT_graphxml_edge,AL_graphxml_edge,E_graphxml_edge,PROLOG,DOCTYPE,EPILOG>{
255 "<!--" ENTER(INCOMMENT);
263 <<EOF>> FAIL("EOF in comment.");
269 <<EOF>> FAIL("EOF in PI (processing instruction).");
272 /* SPACES: skipped uniformly */
274 <ROOT_graphxml_graph,AL_graphxml_graph,S_graphxml_graph,S_graphxml_graph_1,S_graphxml_graph_2,S_graphxml_graph_3,S_graphxml_graph_4,S_graphxml_graph_5,E_graphxml_graph,ROOT_graphxml_node,AL_graphxml_node,E_graphxml_node,ROOT_graphxml_edge,AL_graphxml_edge,E_graphxml_edge,PROLOG,DOCTYPE,EPILOG>{S} SKIP;
276 /* PROLOG: determine root element and process it. */
279 "<?xml"({S}version{Eq}(\'{VersionNum}\'|\"{VersionNum}\"))?({S}encoding{Eq}(\'[^']*\'|\"[^"]*\"))?"?>" SET(DOCTYPE);
280 "<?xml"[^>]*">" FAIL("Bad declaration %s.",yytext);
284 "<!DOCTYPE"{S}"edge"{S}SYSTEM{S}("'graphxml.dtd'"|"\"graphxml.dtd\""){s}">" SET(ROOT_graphxml_edge);
285 "<!DOCTYPE"{S}"node"{S}SYSTEM{S}("'graphxml.dtd'"|"\"graphxml.dtd\""){s}">" SET(ROOT_graphxml_node);
286 "<!DOCTYPE"{S}"graph"{S}SYSTEM{S}("'graphxml.dtd'"|"\"graphxml.dtd\""){s}">" SET(ROOT_graphxml_graph);
287 "<!"[^>-][^>]*">" FAIL("Bad declaration %s.",yytext);
288 . FAIL("Unexpected character `%c' in prolog.", yytext[0]);
289 <<EOF>> FAIL("EOF in prolog.");
292 /* RULES DERIVED FROM DTD. */
294 /* <!-- Small DTD for xbt graphs. --> */
296 /* isDirected (true|false) "true"
299 <ROOT_graphxml_graph>"<graph"{s} {
300 A_graphxml_graph_isDirected = A_graphxml_graph_isDirected_true;
301 ENTER(AL_graphxml_graph);
305 "isDirected"{Eq}"'true'" |
306 "isDirected"{Eq}"\"true\"" A_graphxml_graph_isDirected = A_graphxml_graph_isDirected_true;
307 "isDirected"{Eq}"'false'" |
308 "isDirected"{Eq}"\"false\"" A_graphxml_graph_isDirected = A_graphxml_graph_isDirected_false;
311 LEAVE; STag_graphxml_graph();graphxml_pcdata = NULL; ENTER(S_graphxml_graph);
314 LEAVE; STag_graphxml_graph(); graphxml_pcdata = NULL; ETag_graphxml_graph();
316 case ROOT_graphxml_graph: SET(EPILOG); break;
319 . FAIL("Unexpected character `%c' in attribute list of graph element.", yytext[0]);
320 {Name} FAIL("Bad attribute `%s' in `graph' element start tag.",yytext);
321 <<EOF>> FAIL("EOF in attribute list of `graph' element.");
324 <S_graphxml_graph_1,E_graphxml_graph,S_graphxml_graph_3,S_graphxml_graph_5,S_graphxml_graph>{
327 ETag_graphxml_graph();
329 case ROOT_graphxml_graph: SET(EPILOG); break;
332 "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</graph>' expected.",yytext);
333 . FAIL("Unexpected character `%c': `</graph>' expected.",yytext[0]);
334 <<EOF>> FAIL("Premature EOF: `</graph>' expected.");
338 * name CDATA #REQUIRED
340 * position_x CDATA "-1.0"
341 * position_y CDATA "-1.0"
344 <ROOT_graphxml_node,S_graphxml_graph_2,S_graphxml_graph_3,S_graphxml_graph>"<node"{s} {
345 A_graphxml_node_label = NULL;
346 A_graphxml_node_name = NULL;
347 A_graphxml_node_data = NULL;
348 A_graphxml_node_position_x = "-1.0";
349 A_graphxml_node_position_y = "-1.0";
350 ENTER(AL_graphxml_node);
354 "label"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_node_label);
355 "label"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_node_label);
357 "name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_node_name);
358 "name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_node_name);
360 "data"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_node_data);
361 "data"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_node_data);
363 "position_x"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_node_position_x);
364 "position_x"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_node_position_x);
366 "position_y"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_node_position_y);
367 "position_y"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_node_position_y);
370 if (!A_graphxml_node_name) FAIL("Required attribute `name' not set for `node' element.");
371 LEAVE; STag_graphxml_node();graphxml_pcdata = NULL; ENTER(E_graphxml_node);
374 if (!A_graphxml_node_name) FAIL("Required attribute `name' not set for `node' element.");
375 LEAVE; STag_graphxml_node(); graphxml_pcdata = NULL; ETag_graphxml_node();
377 case S_graphxml_graph_2: case S_graphxml_graph_3: case S_graphxml_graph: SET(S_graphxml_graph_3); break;
378 case ROOT_graphxml_node: SET(EPILOG); break;
381 . FAIL("Unexpected character `%c' in attribute list of node element.", yytext[0]);
382 {Name} FAIL("Bad attribute `%s' in `node' element start tag.",yytext);
383 <<EOF>> FAIL("EOF in attribute list of `node' element.");
389 ETag_graphxml_node();
391 case S_graphxml_graph_2: case S_graphxml_graph_3: case S_graphxml_graph: SET(S_graphxml_graph_3); break;
392 case ROOT_graphxml_node: SET(EPILOG); break;
395 "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</node>' expected.",yytext);
396 . FAIL("Unexpected character `%c': `</node>' expected.",yytext[0]);
397 <<EOF>> FAIL("Premature EOF: `</node>' expected.");
401 * name CDATA #IMPLIED
402 * source CDATA #REQUIRED
403 * target CDATA #REQUIRED
404 * length CDATA "-1.0"
408 <ROOT_graphxml_edge,S_graphxml_graph_1,S_graphxml_graph_3,S_graphxml_graph_5,S_graphxml_graph_4,S_graphxml_graph>"<edge"{s} {
409 A_graphxml_edge_label = NULL;
410 A_graphxml_edge_name = NULL;
411 A_graphxml_edge_source = NULL;
412 A_graphxml_edge_target = NULL;
413 A_graphxml_edge_length = "-1.0";
414 A_graphxml_edge_data = NULL;
415 ENTER(AL_graphxml_edge);
419 "label"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_label);
420 "label"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_label);
422 "name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_name);
423 "name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_name);
425 "source"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_source);
426 "source"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_source);
428 "target"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_target);
429 "target"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_target);
431 "length"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_length);
432 "length"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_length);
434 "data"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_data);
435 "data"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_data);
438 if (!A_graphxml_edge_source) FAIL("Required attribute `source' not set for `edge' element.");
439 if (!A_graphxml_edge_target) FAIL("Required attribute `target' not set for `edge' element.");
440 LEAVE; STag_graphxml_edge();graphxml_pcdata = NULL; ENTER(E_graphxml_edge);
443 if (!A_graphxml_edge_source) FAIL("Required attribute `source' not set for `edge' element.");
444 if (!A_graphxml_edge_target) FAIL("Required attribute `target' not set for `edge' element.");
445 LEAVE; STag_graphxml_edge(); graphxml_pcdata = NULL; ETag_graphxml_edge();
447 case S_graphxml_graph_1: case S_graphxml_graph_3: case S_graphxml_graph_5: case S_graphxml_graph_4: case S_graphxml_graph: SET(S_graphxml_graph_5); break;
448 case ROOT_graphxml_edge: SET(EPILOG); break;
451 . FAIL("Unexpected character `%c' in attribute list of edge element.", yytext[0]);
452 {Name} FAIL("Bad attribute `%s' in `edge' element start tag.",yytext);
453 <<EOF>> FAIL("EOF in attribute list of `edge' element.");
459 ETag_graphxml_edge();
461 case S_graphxml_graph_1: case S_graphxml_graph_3: case S_graphxml_graph_5: case S_graphxml_graph_4: case S_graphxml_graph: SET(S_graphxml_graph_5); break;
462 case ROOT_graphxml_edge: SET(EPILOG); break;
465 "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</edge>' expected.",yytext);
466 . FAIL("Unexpected character `%c': `</edge>' expected.",yytext[0]);
467 <<EOF>> FAIL("Premature EOF: `</edge>' expected.");
470 /* EPILOG: after the root element. */
473 . {SET(PROLOG); yyless(0); CLEANUP; return -1;}
477 /* CHARACTER DATA. */
479 <IMPOSSIBLE,VALUE1,VALUE2>{
480 /* Non-defined standard entities... */
481 "&" BUFFERPUTC('&');
482 "<" BUFFERPUTC('<');
483 ">" BUFFERPUTC('>');
484 "'" BUFFERPUTC('\'');
485 """ BUFFERPUTC('"');
487 /* Character entities. */
488 "&#"[[:digit:]]+";" BUFFERPUTC((unsigned char)atoi(yytext+2));
489 "&#x"[[:xdigit:]]+";" BUFFERPUTC((unsigned char)strtol(yytext+3,NULL,16));
492 <IMPOSSIBLE,VALUE1,VALUE2,CDATA>{
496 "\n\r" BUFFERPUTC('\n');
500 "<![CDATA[" ENTER(CDATA);
501 "]""]>" FAIL("Unexpected `]""]>' in character data.");
505 \' BUFFERDONE; LEAVE;
506 <<EOF>> FAIL("EOF in literal (\"'\" expected).");
510 \" BUFFERDONE; LEAVE;
511 <<EOF>> FAIL("EOF in literal (`\"' expected).");
514 <IMPOSSIBLE,VALUE1,VALUE2>{
515 [^<&] BUFFERPUTC(yytext[0]);
516 [<&] FAIL("Spurious `%c' in character data.",yytext[0]);
521 /* "]""]" BUFFERPUTC(yytext[0]); BUFFERPUTC(yytext[1]); */
522 . BUFFERPUTC(yytext[0]);
523 <<EOF>> FAIL("EOF in CDATA section.");
526 /* Impossible rules to avoid warnings from flex(1). */
527 /* Ideally, this should be replaced by code in flexml.pl that
528 generates just the states not covered by other rules. */
530 .|[\n] FAIL("Syntax error on character `%c'.", yytext[0]);
535 /* Element context stack lookup. */
536 int graphxml_element_context(int i)
538 return (0<i && i<yy_start_stack_depth
539 ? yy_start_stack[yy_start_stack_ptr - i]
544 void print_yy_stack(char* fmt, ...)
546 int i = 0; va_list ap; va_start(ap, fmt);
547 vfprintf(stderr, fmt, ap);
548 for (i=1; i<yy_start_stack_ptr; i++)
549 fprintf(stderr, "%s/", graphxml_statenames[yy_start_stack[i] ]);
550 fprintf(stderr,"%s\n", graphxml_statenames[YY_START]);
554 static void debug_enter(int state, const char* statename) {
555 yy_push_state(state);
556 if (yy_flex_debug) print_yy_stack("--ENTER(%s) : ",statename);
559 static void debug_leave(void) {
560 if (yy_flex_debug) print_yy_stack("--LEAVE : ");
564 static void debug_set(int state, const char* statename) {
566 if (yy_flex_debug) print_yy_stack("--SET(%s) : ",statename);
570 enum {flexml_max_err_msg_size = 512};
572 static char flexml_err_msg[flexml_max_err_msg_size];
573 const char * graphxml_parse_err_msg()
575 return flexml_err_msg;
578 static void reset_graphxml_parse_err_msg()
580 flexml_err_msg[0] = '\0';
584 static void cleanup(void)
586 if (graphxml_statenames) {
587 free(graphxml_statenames);
588 graphxml_statenames = NULL;
593 static int fail(const char* fmt, ...)
595 int chars_left, used;
596 va_list ap; va_start(ap, fmt);
597 #ifdef FLEXML_yylineno
598 used = sprintf(flexml_err_msg,
599 "Invalid XML (XML input line %d, state %d): ",
602 used = sprintf(flexml_err_msg,
603 "Invalid XML (state %d): ",
606 chars_left = flexml_max_err_msg_size - used - 1;
607 vsnprintf(flexml_err_msg + used, chars_left, fmt, ap);
610 #ifndef FLEXML_quiet_parser
611 /* print directly to sdterr */
612 fprintf(stderr, "%s\n", flexml_err_msg);
613 flexml_err_msg[0] = '\0';