1 /* Validating XML processor for graphxml.dtd.
2 * Generated 2006/03/21 13:43:39.
4 * This program was generated with the FleXML XML processor generator.
5 * FleXML is Copyright © 1999-2005 Kristoffer Rose. All rights reserved.
6 * (Id: flexml.pl,v 1.47 2006/03/21 11:12:57 legranda Exp).
8 * There are two, intertwined parts to this program, part A and part B.
13 * Some parts, here collectively called "Part A", are found in the
14 * FleXML package. They are Copyright © 1999-2005 Kristoffer Rose.
15 * All rights reserved.
17 * You can redistribute, use, perform, display and/or modify "Part A"
18 * provided the following two conditions hold:
20 * 1. The program is distributed WITHOUT ANY WARRANTY from the author of
21 * FleXML; without even the implied warranty of MERCHANTABILITY or
22 * FITNESS FOR A PARTICULAR PURPOSE.
24 * 2. The program distribution conditions do not in any way affect the
25 * distribution conditions of the FleXML system used to generate this
26 * file or any version of FleXML derived from that system.
28 * Notice that these are explicit rights granted to you for files
29 * generated by the FleXML system. For your rights in connection with
30 * the FleXML system itself please consult the GNU General Public License.
35 * The other parts, here collectively called "Part B", and which came
36 * from the DTD used by FleXML to generate this program, can be
37 * distributed (or not, as the case may be) under the terms of whoever
38 * wrote them, provided these terms respect and obey the two conditions
39 * above under the heading "Part A".
41 * The author of and contributors to FleXML specifically disclaim
42 * any copyright interest in "Part B", unless "Part B" was written
43 * by the author of or contributors to FleXML.
49 /* Version strings. */
50 const char rcs_graphxml_flexml_skeleton[] =
51 "$" "Id: skel,v 1.28 2006/03/21 12:04:13 legranda Exp $";
52 const char rcs_graphxml_flexml[] =
53 "$" "Id: flexml.pl,v 1.47 2006/03/21 11:12:57 legranda Exp $";
63 /* Generated definitions. */
64 #define FLEXML_yylineno
65 #define FLEXML_BUFFERSTACKSIZE 1000000
67 /* XML processor api. */
68 /* FleXML-provided data. */
70 AT_graphxml_node_name A_graphxml_node_name;
71 AT_graphxml_edge_source A_graphxml_edge_source;
72 AT_graphxml_edge_isDirected A_graphxml_edge_isDirected;
73 AT_graphxml_edge_target A_graphxml_edge_target;
74 AT_graphxml_node_label A_graphxml_node_label;
75 AT_graphxml_edge_label A_graphxml_edge_label;
76 AT_graphxml_edge_name A_graphxml_edge_name;
77 AT_graphxml_edge_length A_graphxml_edge_length;
81 # define ENTER(state) debug_enter(state,#state)
82 # define LEAVE debug_leave()
83 # define SET(state) debug_set(state,#state)
84 static void debug_enter(int, const char*);
85 static void debug_leave(void);
86 static void debug_set(int, const char*);
88 # define ENTER(state) (yy_push_state(state))
89 # define LEAVE (yy_pop_state())
90 # define SET(state) BEGIN(state)
93 /* Generic actions. */
95 #define SUCCEED CLEANUP; return 0
97 #define FAIL return fail
98 static int fail(const char*, ...);
99 const char * graphxml_parse_err_msg(void);
102 static void cleanup(void);
103 #define CLEANUP cleanup()
105 /* Text buffer stack handling. */
106 char bufferstack[FLEXML_BUFFERSTACKSIZE];
107 static char* limit = bufferstack + FLEXML_BUFFERSTACKSIZE;
108 typedef struct BufferLast_s {
109 struct BufferLast_s *old; char* saved; char new1[1];
111 #ifdef FLEXML_HasMixed
112 static BufferLast* last = (BufferLast*)0;
114 static char* next = bufferstack;
116 #define BUFFERSET(P) (P = next)
117 #define BUFFERPUTC(C) (assert(next<limit), *(next++) = (C))
118 #define BUFFERDONE (BUFFERPUTC('\0'))
120 #define BUFFERLITERAL(C,P) bufferliteral(C,&(P),yytext)
121 static void bufferliteral(char c, const char** pp, char* text)
123 char *s = strchr(text,c), *e = strrchr(text,c);
124 assert(s <= e); BUFFERSET(*pp);
126 if (isspace(*s)) { BUFFERPUTC(' '); while (isspace(*s)) ++s; }
132 #ifdef FLEXML_HasMixed
133 static void pushbuffer(char* p)
135 BufferLast* l = (BufferLast*)next;
136 assert(next < limit);
143 static char* popbuffer(void)
145 BufferLast* l = last;
146 assert(last != (BufferLast*)0);
153 /* General internal entities are `unput' back onto the input stream... */
154 #define ENTITYTEXT(T) \
155 { char *s = (T), *e = s+strlen(s);\
156 while (--e >= s) { unput(*e); }}
159 /* Flex standard options. */
161 %option noyy_top_state
167 /* Flex user-requested options. */
171 /* XML character classes (currently restricted to ASCII). */
173 /* "Common syntactic structures." */
177 /* "Names and Tokens." */
178 NameChar [A-Za-z0-9.:_-]
179 Name [A-Za-z_:]{NameChar}*
180 Names {Name}({S}{Name})*
181 Nmtoken ({NameChar})+
182 Nmtokens {Nmtoken}({S}{Nmtoken})*
185 VersionNum [a-zA-Z0-9_.:-]+
187 Literal \'[^'']*\'|\"[^""]*\"
189 /* Parser states (flex `exclusive start conditions'):
191 * PROLOG the XML prolog of the document before <?xml...>
192 * DOCTYPE the XML prolog of the document after <?xml...>
193 * EPILOG after the root element
194 * INCOMMENT inside an XML comment <!--....-->
195 * INPI inside an XML PI <?...?>
196 * VALUE1 inside a '...'-delimited literal
197 * VALUE2 inside a "..."-delimited literal
198 * CDATA inside a <![CDATA[...] ]> section.
199 * ROOT_<tag> expect root element <tag>
200 * AL_<tag> inside the attribute list for <tag>
201 * IN_<tag> inside a <tag> with element contents (ready for end tag)
202 * IMPOSSIBLE dummy to permit disabling rules; must be last
204 %x PROLOG DOCTYPE EPILOG INCOMMENT INPI VALUE1 VALUE2 CDATA
205 %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
206 %x ROOT_graphxml_node AL_graphxml_node E_graphxml_node
207 %x ROOT_graphxml_edge AL_graphxml_edge E_graphxml_edge
212 const char* *graphxml_statenames=NULL;
217 /* Bypass Flex's default INITIAL state and begin by parsing the XML prolog. */
221 if(!graphxml_statenames) {graphxml_statenames= (const char **)calloc(IMPOSSIBLE,sizeof(char*));
222 graphxml_statenames[PROLOG] = NULL;
223 graphxml_statenames[DOCTYPE] = NULL;
224 graphxml_statenames[EPILOG] = NULL;
225 graphxml_statenames[INCOMMENT] = NULL;
226 graphxml_statenames[INPI] = NULL;
227 graphxml_statenames[VALUE1] = NULL;
228 graphxml_statenames[VALUE2] = NULL;
229 graphxml_statenames[CDATA] = NULL;
230 graphxml_statenames[ROOT_graphxml_graph] = NULL;
231 graphxml_statenames[AL_graphxml_graph] = NULL;
232 graphxml_statenames[S_graphxml_graph] = "graph";
233 graphxml_statenames[S_graphxml_graph_1] = "graph";
234 graphxml_statenames[S_graphxml_graph_2] = "graph";
235 graphxml_statenames[S_graphxml_graph_3] = "graph";
236 graphxml_statenames[S_graphxml_graph_4] = "graph";
237 graphxml_statenames[S_graphxml_graph_5] = "graph";
238 graphxml_statenames[E_graphxml_graph] = "graph";
239 graphxml_statenames[ROOT_graphxml_node] = NULL;
240 graphxml_statenames[AL_graphxml_node] = NULL;
241 graphxml_statenames[E_graphxml_node] = "node";
242 graphxml_statenames[ROOT_graphxml_edge] = NULL;
243 graphxml_statenames[AL_graphxml_edge] = NULL;
244 graphxml_statenames[E_graphxml_edge] = "edge";
247 /* COMMENTS and PIs: handled uniformly for efficiency. */
249 <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>{
250 "<!--" ENTER(INCOMMENT);
258 <<EOF>> FAIL("EOF in comment.");
264 <<EOF>> FAIL("EOF in PI (processing instruction).");
267 /* SPACES: skipped uniformly */
269 <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;
271 /* PROLOG: determine root element and process it. */
274 "<?xml"({S}version{Eq}(\'{VersionNum}\'|\"{VersionNum}\"))?({S}encoding{Eq}(\'[^']*\'|\"[^"]*\"))?"?>" SET(DOCTYPE);
275 "<?xml"[^>]*">" FAIL("Bad declaration %s.",yytext);
279 "<!DOCTYPE"{S}"edge"{S}SYSTEM{S}("'graphxml.dtd'"|"\"graphxml.dtd\""){s}">" SET(ROOT_graphxml_edge);
280 "<!DOCTYPE"{S}"node"{S}SYSTEM{S}("'graphxml.dtd'"|"\"graphxml.dtd\""){s}">" SET(ROOT_graphxml_node);
281 "<!DOCTYPE"{S}"graph"{S}SYSTEM{S}("'graphxml.dtd'"|"\"graphxml.dtd\""){s}">" SET(ROOT_graphxml_graph);
282 "<!"[^>-][^>]*">" FAIL("Bad declaration %s.",yytext);
283 . FAIL("Unexpected character `%c' in prolog.", yytext[0]);
284 <<EOF>> FAIL("EOF in prolog.");
287 /* RULES DERIVED FROM DTD. */
289 /* <!-- Small DTD for xbt graphs. --> */
291 <ROOT_graphxml_graph>"<graph"{s} {
292 ENTER(AL_graphxml_graph);
297 LEAVE; STag_graphxml_graph();pcdata = NULL; ENTER(S_graphxml_graph);
300 LEAVE; STag_graphxml_graph(); pcdata = NULL; ETag_graphxml_graph();
302 case ROOT_graphxml_graph: SET(EPILOG); break;
305 . FAIL("Unexpected character `%c' in attribute list of graph element.", yytext[0]);
306 {Name} FAIL("Bad attribute `%s' in `graph' element start tag.",yytext);
307 <<EOF>> FAIL("EOF in attribute list of `graph' element.");
310 <S_graphxml_graph_1,E_graphxml_graph,S_graphxml_graph_3,S_graphxml_graph_5,S_graphxml_graph>{
313 ETag_graphxml_graph();
315 case ROOT_graphxml_graph: SET(EPILOG); break;
318 "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</graph>' expected.",yytext);
319 . FAIL("Unexpected character `%c': `</graph>' expected.",yytext[0]);
320 <<EOF>> FAIL("Premature EOF: `</graph>' expected.");
324 * name CDATA #REQUIRED
327 <ROOT_graphxml_node,S_graphxml_graph_2,S_graphxml_graph_3,S_graphxml_graph>"<node"{s} {
328 A_graphxml_node_label = NULL;
329 A_graphxml_node_name = NULL;
330 ENTER(AL_graphxml_node);
334 "label"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_node_label);
335 "label"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_node_label);
337 "name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_node_name);
338 "name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_node_name);
341 if (!A_graphxml_node_name) FAIL("Required attribute `name' not set for `node' element.");
342 LEAVE; STag_graphxml_node();pcdata = NULL; ENTER(E_graphxml_node);
345 if (!A_graphxml_node_name) FAIL("Required attribute `name' not set for `node' element.");
346 LEAVE; STag_graphxml_node(); pcdata = NULL; ETag_graphxml_node();
348 case S_graphxml_graph_2: case S_graphxml_graph_3: case S_graphxml_graph: SET(S_graphxml_graph_3); break;
349 case ROOT_graphxml_node: SET(EPILOG); break;
352 . FAIL("Unexpected character `%c' in attribute list of node element.", yytext[0]);
353 {Name} FAIL("Bad attribute `%s' in `node' element start tag.",yytext);
354 <<EOF>> FAIL("EOF in attribute list of `node' element.");
360 ETag_graphxml_node();
362 case S_graphxml_graph_2: case S_graphxml_graph_3: case S_graphxml_graph: SET(S_graphxml_graph_3); break;
363 case ROOT_graphxml_node: SET(EPILOG); break;
366 "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</node>' expected.",yytext);
367 . FAIL("Unexpected character `%c': `</node>' expected.",yytext[0]);
368 <<EOF>> FAIL("Premature EOF: `</node>' expected.");
372 * name CDATA #IMPLIED
373 * source CDATA #REQUIRED
374 * target CDATA #REQUIRED
376 * isDirected (true|false) "true"
379 <ROOT_graphxml_edge,S_graphxml_graph_1,S_graphxml_graph_3,S_graphxml_graph_5,S_graphxml_graph_4,S_graphxml_graph>"<edge"{s} {
380 A_graphxml_edge_label = NULL;
381 A_graphxml_edge_name = NULL;
382 A_graphxml_edge_source = NULL;
383 A_graphxml_edge_target = NULL;
384 A_graphxml_edge_length = "0.0";
385 A_graphxml_edge_isDirected = A_graphxml_edge_isDirected_true;
386 ENTER(AL_graphxml_edge);
390 "label"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_label);
391 "label"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_label);
393 "name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_name);
394 "name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_name);
396 "source"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_source);
397 "source"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_source);
399 "target"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_target);
400 "target"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_target);
402 "length"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_length);
403 "length"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_length);
405 "isDirected"{Eq}"'true'" |
406 "isDirected"{Eq}"\"true\"" A_graphxml_edge_isDirected = A_graphxml_edge_isDirected_true;
407 "isDirected"{Eq}"'false'" |
408 "isDirected"{Eq}"\"false\"" A_graphxml_edge_isDirected = A_graphxml_edge_isDirected_false;
411 if (!A_graphxml_edge_source) FAIL("Required attribute `source' not set for `edge' element.");
412 if (!A_graphxml_edge_target) FAIL("Required attribute `target' not set for `edge' element.");
413 LEAVE; STag_graphxml_edge();pcdata = NULL; ENTER(E_graphxml_edge);
416 if (!A_graphxml_edge_source) FAIL("Required attribute `source' not set for `edge' element.");
417 if (!A_graphxml_edge_target) FAIL("Required attribute `target' not set for `edge' element.");
418 LEAVE; STag_graphxml_edge(); pcdata = NULL; ETag_graphxml_edge();
420 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;
421 case ROOT_graphxml_edge: SET(EPILOG); break;
424 . FAIL("Unexpected character `%c' in attribute list of edge element.", yytext[0]);
425 {Name} FAIL("Bad attribute `%s' in `edge' element start tag.",yytext);
426 <<EOF>> FAIL("EOF in attribute list of `edge' element.");
432 ETag_graphxml_edge();
434 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;
435 case ROOT_graphxml_edge: SET(EPILOG); break;
438 "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</edge>' expected.",yytext);
439 . FAIL("Unexpected character `%c': `</edge>' expected.",yytext[0]);
440 <<EOF>> FAIL("Premature EOF: `</edge>' expected.");
443 /* EPILOG: after the root element. */
446 . {SET(PROLOG); yyless(0); CLEANUP; return -1;}
450 /* CHARACTER DATA. */
452 <IMPOSSIBLE,VALUE1,VALUE2>{
453 /* Non-defined standard entities... */
454 "&" BUFFERPUTC('&');
455 "<" BUFFERPUTC('<');
456 ">" BUFFERPUTC('>');
457 "'" BUFFERPUTC('\'');
458 """ BUFFERPUTC('"');
460 /* Character entities. */
461 "&#"[[:digit:]]+";" BUFFERPUTC((unsigned char)atoi(yytext+2));
462 "&#x"[[:xdigit:]]+";" BUFFERPUTC((unsigned char)strtol(yytext+3,NULL,16));
465 <IMPOSSIBLE,VALUE1,VALUE2,CDATA>{
469 "\n\r" BUFFERPUTC('\n');
473 "<![CDATA[" ENTER(CDATA);
474 "]""]>" FAIL("Unexpected `]""]>' in character data.");
478 \' BUFFERDONE; LEAVE;
479 <<EOF>> FAIL("EOF in literal (\"'\" expected).");
483 \" BUFFERDONE; LEAVE;
484 <<EOF>> FAIL("EOF in literal (`\"' expected).");
487 <IMPOSSIBLE,VALUE1,VALUE2>{
488 [^<&] BUFFERPUTC(yytext[0]);
489 [<&] FAIL("Spurious `%c' in character data.",yytext[0]);
494 /* "]""]" BUFFERPUTC(yytext[0]); BUFFERPUTC(yytext[1]); */
495 . BUFFERPUTC(yytext[0]);
496 <<EOF>> FAIL("EOF in CDATA section.");
499 /* Impossible rules to avoid warnings from flex(1). */
500 /* Ideally, this should be replaced by code in flexml.pl that
501 generates just the states not covered by other rules. */
503 .|[\n] FAIL("Syntax error on character `%c'.", yytext[0]);
508 /* Element context stack lookup. */
509 int graphxml_element_context(int i)
511 return (0<i && i<yy_start_stack_depth
512 ? yy_start_stack[yy_start_stack_ptr - i]
517 void print_yy_stack(char* fmt, ...)
519 int i = 0; va_list ap; va_start(ap, fmt);
520 vfprintf(stderr, fmt, ap);
521 for (i=1; i<yy_start_stack_ptr; i++)
522 fprintf(stderr, "%s/", graphxml_statenames[yy_start_stack[i] ]);
523 fprintf(stderr,"%s\n", graphxml_statenames[YY_START]);
527 static void debug_enter(int state, const char* statename) {
528 yy_push_state(state);
529 if (yy_flex_debug) print_yy_stack("--ENTER(%s) : ",statename);
532 static void debug_leave(void) {
533 if (yy_flex_debug) print_yy_stack("--LEAVE : ");
537 static void debug_set(int state, const char* statename) {
539 if (yy_flex_debug) print_yy_stack("--SET(%s) : ",statename);
543 enum {flexml_max_err_msg_size = 512};
545 static char flexml_err_msg[flexml_max_err_msg_size];
546 const char * graphxml_parse_err_msg()
548 return flexml_err_msg;
551 static void reset_graphxml_parse_err_msg()
553 flexml_err_msg[0] = '\0';
557 static void cleanup(void)
559 if (graphxml_statenames) {
560 free(graphxml_statenames);
561 graphxml_statenames = NULL;
566 static int fail(const char* fmt, ...)
568 int chars_left, used;
569 va_list ap; va_start(ap, fmt);
570 #ifdef FLEXML_yylineno
571 used = sprintf(flexml_err_msg,
572 "Invalid XML (XML input line %d, state %d): ",
575 used = sprintf(flexml_err_msg,
576 "Invalid XML (state %d): ",
579 chars_left = flexml_max_err_msg_size - used - 1;
580 vsnprintf(flexml_err_msg + used, chars_left, fmt, ap);
583 #ifndef FLEXML_quiet_parser
584 /* print directly to sdterr */
585 fprintf(stderr, "%s\n", flexml_err_msg);
586 flexml_err_msg[0] = '\0';