Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Added round trip time contraint to the SDP program, this parameter
[simgrid.git] / src / xbt / graphxml.l
1 /* Validating XML processor for xbt/graphxml.dtd.
2  * Generated 2006/07/18 21:02:16.
3  *
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).
8  * 
9  * There are two, intertwined parts to this program, part A and part B.
10  *
11  * Part A
12  * ------
13  * 
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.
17  *
18  * You can redistribute, use, perform, display and/or modify "Part A"
19  * provided the following two conditions hold:
20  *
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.
24  *
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.
28  *
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.
32  * 
33  * Part B
34  * ------
35  * 
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".
41  *
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.
45  * 
46  */
47
48 %{
49
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 $";
55
56 /* ANSI headers. */
57 #include <unistd.h>
58 #include <stdio.h>
59 #include <string.h>
60 #include <assert.h>
61 #include <stdarg.h>
62 #include <ctype.h>
63
64 /* Generated definitions. */
65 #define FLEXML_yylineno
66 #define FLEXML_BUFFERSTACKSIZE 1000000
67
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;
83
84 /* XML state. */
85 #ifdef FLEX_DEBUG
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*);
92 #else
93 # define ENTER(state)   (yy_push_state(state))
94 # define LEAVE          (yy_pop_state())
95 # define SET(state)     BEGIN(state)
96 #endif
97
98 /* Generic actions. */
99 #define SKIP    /*skip*/
100 #define SUCCEED        CLEANUP; return 0
101
102 #define FAIL    return fail
103 static int fail(const char*, ...);
104 const char * graphxml_parse_err_msg(void);
105
106 /* Cleanup */
107 static void cleanup(void);
108 #define CLEANUP  cleanup()
109
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];
115 } BufferLast;
116 #ifdef FLEXML_HasMixed
117 static BufferLast* last = (BufferLast*)0;
118 #endif
119 static char* next = bufferstack;
120
121 #define BUFFERSET(P)  (P = next)
122 #define BUFFERPUTC(C) (assert(next<limit), *(next++) = (C))
123 #define BUFFERDONE    (BUFFERPUTC('\0'))
124
125 #define BUFFERLITERAL(C,P) bufferliteral(C,&(P),yytext)
126 static void bufferliteral(char c, const char** pp, char* text)
127 {
128   char *s = strchr(text,c), *e = strrchr(text,c);
129   assert(s <= e); BUFFERSET(*pp);
130   while (++s<e) {
131     if (isspace(*s)) { BUFFERPUTC(' '); while (isspace(*s)) ++s; }
132     else BUFFERPUTC(*s);
133   }
134   BUFFERDONE;
135 }
136
137 #ifdef FLEXML_HasMixed
138 static void pushbuffer(const char* p)
139 {
140   BufferLast* l = (BufferLast*)next;
141   assert(next < limit);
142   l->old = last;
143   l->saved = p;
144   next = l->new1;
145   last = l;
146 }
147
148 static const char* popbuffer(void)
149 {
150   BufferLast* l = last;
151   assert(last != (BufferLast*)0);
152   last = l->old;
153   next = (char*)l;
154   return l->saved;
155 }
156 #endif
157
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); }}
162 %}
163
164 /* Flex standard options. */
165 %option stack
166 %option noyy_top_state
167 %option noinput
168 %option noreject
169 %option noyymore
170 %option noyywrap
171
172 /* Flex user-requested options. */
173 %option yylineno
174 %option nounput
175
176 /* XML character classes (currently restricted to ASCII). */
177
178 /* "Common syntactic structures." */
179 S               [ \t\n\r\f]+
180 s               [ \t\n\r\f]*
181
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})*
188
189 /* Miscellaneous. */
190 VersionNum      [a-zA-Z0-9_.:-]+
191 Eq              {s}"="{s}
192 Literal         \'[^'']*\'|\"[^""]*\"
193
194 /* Parser states (flex `exclusive start conditions'):
195  *
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
208  */
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
213 %x IMPOSSIBLE
214
215 %{
216 /* State names. */
217 const char* *graphxml_statenames=NULL;
218 %}
219
220 %%
221
222  /* Bypass Flex's default INITIAL state and begin by parsing the XML prolog. */
223  SET(PROLOG);
224   /* FleXML_init */
225   next = bufferstack;
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";
250   }
251
252  /* COMMENTS and PIs: handled uniformly for efficiency. */
253
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);
256  "<?" ENTER(INPI);
257 }
258 <INCOMMENT>{
259  "-->"          LEAVE;
260  "--"           |
261  .              |
262  \n             SKIP;
263  <<EOF>>        FAIL("EOF in comment.");
264 }
265 <INPI>{
266  "?>"           LEAVE;
267  .              |
268  \n             SKIP;
269  <<EOF>>        FAIL("EOF in PI (processing instruction).");
270 }
271
272  /* SPACES: skipped uniformly */
273
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;
275
276  /* PROLOG: determine root element and process it. */
277
278 <PROLOG>{
279  "<?xml"({S}version{Eq}(\'{VersionNum}\'|\"{VersionNum}\"))?({S}encoding{Eq}(\'[^']*\'|\"[^"]*\"))?"?>" SET(DOCTYPE); 
280  "<?xml"[^>]*">" FAIL("Bad declaration %s.",yytext);
281 }
282
283 <PROLOG,DOCTYPE>{
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.");
290 }
291
292  /* RULES DERIVED FROM DTD. */
293
294  /* <!-- Small DTD for xbt graphs. -->  */
295
296  /*     isDirected (true|false) "true"
297   * >  */
298
299 <ROOT_graphxml_graph>"<graph"{s} {
300   A_graphxml_graph_isDirected = A_graphxml_graph_isDirected_true;
301   ENTER(AL_graphxml_graph);
302   }
303
304 <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;
309
310  ">" {
311   LEAVE; STag_graphxml_graph();graphxml_pcdata = NULL; ENTER(S_graphxml_graph);
312  }
313  "/>" {
314   LEAVE; STag_graphxml_graph(); graphxml_pcdata = NULL; ETag_graphxml_graph();
315   switch (YY_START) {
316    case ROOT_graphxml_graph: SET(EPILOG); break;
317   }
318  }
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.");
322 }
323
324 <S_graphxml_graph_1,E_graphxml_graph,S_graphxml_graph_3,S_graphxml_graph_5,S_graphxml_graph>{
325  "</graph"{s}">" {
326   LEAVE;
327   ETag_graphxml_graph();
328   switch (YY_START) {
329    case ROOT_graphxml_graph: SET(EPILOG); break;
330   }
331  }
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.");
335 }
336
337  /*     label           CDATA                ""
338   *     name            CDATA                #REQUIRED
339   *     data            CDATA                ""
340   *     position_x          CDATA                "-1.0"
341   *     position_y          CDATA                "-1.0"
342   * >  */
343
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);
351   }
352
353 <AL_graphxml_node>{
354  "label"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_node_label);
355  "label"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_node_label);
356
357  "name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_node_name);
358  "name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_node_name);
359
360  "data"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_node_data);
361  "data"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_node_data);
362
363  "position_x"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_node_position_x);
364  "position_x"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_node_position_x);
365
366  "position_y"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_node_position_y);
367  "position_y"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_node_position_y);
368
369  ">" {
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);
372  }
373  "/>" {
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();
376   switch (YY_START) {
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;
379   }
380  }
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.");
384 }
385
386 <E_graphxml_node>{
387  "</node"{s}">" {
388   LEAVE;
389   ETag_graphxml_node();
390   switch (YY_START) {
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;
393   }
394  }
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.");
398 }
399
400  /*     label           CDATA                ""
401   *     name            CDATA               #IMPLIED
402   *     source          CDATA               #REQUIRED
403   *     target          CDATA               #REQUIRED
404   *     length          CDATA               "-1.0"
405   *     data            CDATA               ""
406   * >  */
407
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);
416   }
417
418 <AL_graphxml_edge>{
419  "label"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_label);
420  "label"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_label);
421
422  "name"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_name);
423  "name"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_name);
424
425  "source"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_source);
426  "source"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_source);
427
428  "target"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_target);
429  "target"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_target);
430
431  "length"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_length);
432  "length"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_length);
433
434  "data"{Eq}\' ENTER(VALUE1); BUFFERSET(A_graphxml_edge_data);
435  "data"{Eq}\" ENTER(VALUE2); BUFFERSET(A_graphxml_edge_data);
436
437  ">" {
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);
441  }
442  "/>" {
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();
446   switch (YY_START) {
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;
449   }
450  }
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.");
454 }
455
456 <E_graphxml_edge>{
457  "</edge"{s}">" {
458   LEAVE;
459   ETag_graphxml_edge();
460   switch (YY_START) {
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;
463   }
464  }
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.");
468 }
469
470  /* EPILOG: after the root element. */
471
472 <EPILOG>{
473  . {SET(PROLOG); yyless(0); CLEANUP; return -1;}
474  <<EOF>>        SUCCEED;
475 }
476
477  /* CHARACTER DATA. */
478
479 <IMPOSSIBLE,VALUE1,VALUE2>{
480  /* Non-defined standard entities... */
481 "&amp;"  BUFFERPUTC('&');
482 "&lt;"   BUFFERPUTC('<');
483 "&gt;"   BUFFERPUTC('>');
484 "&apos;" BUFFERPUTC('\'');
485 "&quot;" BUFFERPUTC('"');
486
487  /* Character entities. */
488  "&#"[[:digit:]]+";"    BUFFERPUTC((unsigned char)atoi(yytext+2));
489  "&#x"[[:xdigit:]]+";"  BUFFERPUTC((unsigned char)strtol(yytext+3,NULL,16));
490 }
491
492 <IMPOSSIBLE,VALUE1,VALUE2,CDATA>{
493  "\n"           |
494  "\r"           |
495  "\r\n"         |
496  "\n\r"         BUFFERPUTC('\n');
497 }
498
499 <IMPOSSIBLE>{
500  "<![CDATA["    ENTER(CDATA);
501  "]""]>"                FAIL("Unexpected `]""]>' in character data.");
502 }
503
504 <VALUE1>{
505  \'             BUFFERDONE; LEAVE;
506  <<EOF>>        FAIL("EOF in literal (\"'\" expected).");
507 }
508
509 <VALUE2>{
510  \"             BUFFERDONE; LEAVE;
511  <<EOF>>        FAIL("EOF in literal (`\"' expected).");
512 }
513
514 <IMPOSSIBLE,VALUE1,VALUE2>{
515  [^<&]          BUFFERPUTC(yytext[0]);
516  [<&]           FAIL("Spurious `%c' in character data.",yytext[0]);
517 }
518
519 <CDATA>{
520  "]""]>"                LEAVE;
521  /* "]""]"              BUFFERPUTC(yytext[0]); BUFFERPUTC(yytext[1]); */
522  .              BUFFERPUTC(yytext[0]);
523  <<EOF>>        FAIL("EOF in CDATA section.");
524 }
525
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. */
529 <*>{
530  .|[\n] FAIL("Syntax error on character `%c'.", yytext[0]);
531 }
532
533 %%
534
535 /* Element context stack lookup. */
536 int graphxml_element_context(int i)
537 {
538   return (0<i && i<yy_start_stack_depth
539           ? yy_start_stack[yy_start_stack_ptr - i]
540           : 0);
541 }
542
543 #ifdef FLEX_DEBUG
544 void print_yy_stack(char* fmt, ...)
545 {
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]);
551   va_end(ap);
552 }
553
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);
557 }
558
559 static void debug_leave(void) {
560   if (yy_flex_debug) print_yy_stack("--LEAVE : ");
561   yy_pop_state();
562 }
563
564 static void debug_set(int state, const char* statename) {
565   BEGIN(state);
566   if (yy_flex_debug) print_yy_stack("--SET(%s) : ",statename);
567 }
568 #endif
569
570 enum {flexml_max_err_msg_size = 512};
571
572 static char flexml_err_msg[flexml_max_err_msg_size];
573 const char * graphxml_parse_err_msg()
574 {
575     return flexml_err_msg;
576 }
577
578 static void reset_graphxml_parse_err_msg()
579 {
580     flexml_err_msg[0] = '\0';
581 }
582
583
584 static void cleanup(void)
585 {
586     if (graphxml_statenames) {
587         free(graphxml_statenames);
588         graphxml_statenames = NULL;
589     }
590 }
591
592
593 static int fail(const char* fmt, ...)
594 {
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): ",
600                    yylineno, YY_START);
601 #else
602     used = sprintf(flexml_err_msg,
603                    "Invalid XML (state %d): ",
604                    YY_START);
605 #endif
606     chars_left = flexml_max_err_msg_size - used - 1;
607     vsnprintf(flexml_err_msg + used, chars_left, fmt, ap);
608     va_end(ap);
609
610 #ifndef FLEXML_quiet_parser
611     /* print directly to sdterr */
612     fprintf(stderr, "%s\n", flexml_err_msg);
613     flexml_err_msg[0] = '\0';
614 #endif
615
616     cleanup();
617
618     return 1;
619 }