Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Regenerate files in maintainer mode.
[simgrid.git] / src / xbt / graphxml.l
1 /* Validating XML processor for src/xbt/graphxml.dtd.
2  *
3  * This program was generated with the FleXML XML processor generator.
4  * FleXML is Copyright (C) 1999-2005 Kristoffer Rose.  All rights reserved.
5  * FleXML is Copyright (C) 2003-2006 Martin Quinson.  All rights reserved.
6  * (Id: flexml.pl,v 1.62 2007/10/11 10:00:14 mquinson Exp).
7  * 
8  * There are two, intertwined parts to this program, part A and part B.
9  *
10  * Part A
11  * ------
12  * 
13  * Some parts, here collectively called "Part A", are found in the 
14  * FleXML package.  They are Copyright (C) 1999-2005 Kristoffer Rose
15  * and Copyright (C) 2003-2006 Martin Quinson. All rights reserved.
16  *
17  * You can redistribute, use, perform, display and/or modify "Part A"
18  * provided the following two conditions hold:
19  *
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.
23  *
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.
27  *
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.
31  * 
32  * Part B
33  * ------
34  * 
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".
40  *
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.
44  * 
45  */
46
47 %{
48
49 /* Version strings. */
50 const char rcs_graphxml_flexml_skeleton[] =
51  "$" "Id: skel,v 1.40 2007/10/11 09:57:24 mquinson Exp $";
52 const char rcs_graphxml_flexml[] =
53  "$" "Id: flexml.pl,v 1.62 2007/10/11 10:00:14 mquinson Exp $";
54
55 /* ANSI headers. */
56 #include <stdlib.h> /* for realloc() -- needed here when using flex 2.5.4 */
57 #include <stdio.h>
58 #include <string.h>
59 #include <assert.h>
60 #include <stdarg.h>
61 #include <ctype.h>
62      
63 #if defined(_XBT_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__TOS_WIN__)
64 # ifndef __STRICT_ANSI__
65 #  include <io.h>
66 #  include <process.h>
67 # endif
68 #else
69 # include <unistd.h>
70 #endif
71      
72 #ifndef FLEXML_INDEXSTACKSIZE
73 #define FLEXML_INDEXSTACKSIZE 1000
74 #endif
75
76 /* Generated definitions. */
77 #define FLEXML_yylineno
78 #ifndef FLEXML_BUFFERSTACKSIZE
79 #define FLEXML_BUFFERSTACKSIZE 1000000
80 #endif
81 #define FLEXML_NEED_BUFFERLIT
82
83 /* XML processor api. */
84 /* FleXML-provided data. */
85 int graphxml_pcdata_ix;
86 extern char *graphxml_bufferstack;
87 #define graphxml_pcdata (graphxml_bufferstack + graphxml_pcdata_ix)
88 AT_graphxml_node_name AX_graphxml_node_name;
89 #define A_graphxml_node_name (graphxml_bufferstack + AX_graphxml_node_name)
90 AT_graphxml_edge_source AX_graphxml_edge_source;
91 #define A_graphxml_edge_source (graphxml_bufferstack + AX_graphxml_edge_source)
92 AT_graphxml_node_position_y AX_graphxml_node_position_y;
93 #define A_graphxml_node_position_y (graphxml_bufferstack + AX_graphxml_node_position_y)
94 AT_graphxml_node_position_x AX_graphxml_node_position_x;
95 #define A_graphxml_node_position_x (graphxml_bufferstack + AX_graphxml_node_position_x)
96 AT_graphxml_edge_data AX_graphxml_edge_data;
97 #define A_graphxml_edge_data (graphxml_bufferstack + AX_graphxml_edge_data)
98 AT_graphxml_edge_target AX_graphxml_edge_target;
99 #define A_graphxml_edge_target (graphxml_bufferstack + AX_graphxml_edge_target)
100 AT_graphxml_graph_isDirected AX_graphxml_graph_isDirected;
101 #define A_graphxml_graph_isDirected AX_graphxml_graph_isDirected
102 AT_graphxml_node_label AX_graphxml_node_label;
103 #define A_graphxml_node_label (graphxml_bufferstack + AX_graphxml_node_label)
104 AT_graphxml_node_data AX_graphxml_node_data;
105 #define A_graphxml_node_data (graphxml_bufferstack + AX_graphxml_node_data)
106 AT_graphxml_edge_label AX_graphxml_edge_label;
107 #define A_graphxml_edge_label (graphxml_bufferstack + AX_graphxml_edge_label)
108 AT_graphxml_edge_length AX_graphxml_edge_length;
109 #define A_graphxml_edge_length (graphxml_bufferstack + AX_graphxml_edge_length)
110 AT_graphxml_edge_name AX_graphxml_edge_name;
111 #define A_graphxml_edge_name (graphxml_bufferstack + AX_graphxml_edge_name)
112
113 /* XML state. */
114 #ifdef FLEX_DEBUG
115 # define ENTER(state)   debug_enter(state,#state)
116 # define LEAVE          debug_leave()
117 # define SET(state)     debug_set(state,#state)
118   static void debug_enter(int, const char*);
119   static void debug_leave(void);
120   static void debug_set(int, const char*);
121 #else
122 # define ENTER(state)   (yy_push_state(state))
123 # define LEAVE          (yy_pop_state())
124 # define SET(state)     BEGIN(state)
125 #endif
126
127 /* Generic actions. */
128 #define SKIP    /*skip*/
129 #define SUCCEED        CLEANUP; return 0
130
131 #define FAIL    return fail
132 static int fail(const char*, ...);
133
134 enum {flexml_max_err_msg_size = 512};
135 static char flexml_err_msg[flexml_max_err_msg_size];
136 const char * graphxml_parse_err_msg()
137 {
138     return flexml_err_msg;
139 }
140 static void reset_graphxml_parse_err_msg()
141 {
142     flexml_err_msg[0] = '\0';
143 }
144
145 /* Cleanup */
146 static void cleanup(void);
147 #define CLEANUP  cleanup()
148
149 /* Text buffer stack handling. */
150 char *graphxml_bufferstack = NULL;
151 static int blimit = FLEXML_BUFFERSTACKSIZE;
152 static int bnext = 1;
153
154 static int *indexstack = NULL;
155 static int ilimit = FLEXML_INDEXSTACKSIZE;
156 static int inext = 1;
157
158 #define BUFFERSET(P)  (P = bnext)
159 #define BUFFERPUTC(C) (ck_blimit(), graphxml_bufferstack[bnext++] = (C))
160 #define BUFFERDONE    (BUFFERPUTC('\0'))
161
162 #define BUFFERLITERAL(C, P) graphxml_bufferliteral(C, &(P), yytext)
163
164 /* after this is called, there are at least 2 slots left in the stack */
165 static int ck_blimit()
166 {
167      if (bnext >= blimit) {
168          blimit += FLEXML_BUFFERSTACKSIZE + 2;
169          {
170              char *temp = (char *) realloc(graphxml_bufferstack, blimit);
171              assert(temp);
172              graphxml_bufferstack = temp;
173          }
174      }
175      return 0;
176 }
177
178 /* after this is called, there are at least 2 slots left in the stack */
179 static int ck_ilimit()
180 {
181      if (inext >= ilimit) {
182          ilimit += FLEXML_INDEXSTACKSIZE + 2;
183          {
184              int *temp = (int *) realloc(indexstack, ilimit);
185              assert(temp);
186              indexstack = temp;
187          }
188      }
189      return 0;
190 }
191
192 #ifdef FLEXML_NEED_BUFFERLIT
193 static void graphxml_bufferliteral(char c, int* pp, const char* text)
194 {
195   const char *s = (c ? strchr(text,c) : text-1), *e = strrchr(text,c);
196   assert(s <= e); BUFFERSET(*pp);
197   while (++s<e) {
198     if (isspace(*s) && c) { BUFFERPUTC(' '); while (isspace(*s)) ++s; }
199     else BUFFERPUTC(*s);
200   }
201   BUFFERDONE;
202 }
203 #endif
204
205 static void pushbuffer(int p)
206 {
207     ck_ilimit();
208     indexstack[inext++] = p;
209     indexstack[inext++] = bnext;    
210 }
211
212 static int popbuffer(void)
213 {
214     assert(inext >= 2);
215     bnext = indexstack[--inext];
216     return indexstack[--inext];
217 }
218
219 /* General internal entities are `unput' back onto the input stream... */
220 #define ENTITYTEXT(T) \
221   { char *s = (T), *e = s+strlen(s);\
222     while (--e >= s) { unput(*e); }}
223
224
225 %}
226
227 /* Flex standard options. */
228 %option stack
229 %option noyy_top_state
230 %option noinput
231 %option noreject
232 %option noyymore
233 %option noyywrap
234
235 /* Flex user-requested options. */
236 %option yylineno
237 %option nounput
238
239 /* XML character classes (currently restricted to ASCII). */
240
241 /* "Common syntactic structures." */
242 S               [ \t\n\r\f]+
243 s               [ \t\n\r\f]*
244
245 /* "Names and Tokens." */
246 NameChar        [A-Za-z0-9.:_-]
247 Name            [A-Za-z_:]{NameChar}*
248 Names           {Name}({S}{Name})*
249 Nmtoken         ({NameChar})+
250 Nmtokens        {Nmtoken}({S}{Nmtoken})*
251
252 /* Miscellaneous. */
253 VersionNum      [a-zA-Z0-9_.:-]+
254 Eq              {s}"="{s}
255 Literal         \'[^'']*\'|\"[^""]*\"
256
257 /* Parser states (flex `exclusive start conditions'):
258  *
259  * PROLOG       the XML prolog of the document before <?xml...>
260  * DOCTYPE      the XML prolog of the document after <?xml...>
261  * EPILOG       after the root element
262  * INCOMMENT    inside an XML comment <!--....-->
263  * INPI         inside an XML PI <?...?>
264  * VALUE1       inside a '...'-delimited literal
265  * VALUE2       inside a "..."-delimited literal
266  * CDATA        inside a <![CDATA[...] ]> section.
267  * ROOT_<tag>   expect root element <tag>
268  * AL_<tag>     inside the attribute list for <tag>
269  * IN_<tag>     inside a <tag> with element contents (ready for end tag)
270  * IMPOSSIBLE   dummy to permit disabling rules; must be last
271  */
272 %x PROLOG DOCTYPE EPILOG INCOMMENT INPI VALUE1 VALUE2 CDATA
273 %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
274 %x ROOT_graphxml_node AL_graphxml_node E_graphxml_node
275 %x ROOT_graphxml_edge AL_graphxml_edge E_graphxml_edge
276 %x IMPOSSIBLE
277
278 %{
279 /* State names. */
280 const char* *graphxml_statenames=NULL;
281 %}
282
283 %%
284
285  /* Bypass Flex's default INITIAL state and begin by parsing the XML prolog. */
286  SET(PROLOG);
287  reset_graphxml_parse_err_msg();
288  graphxml_bufferstack = (char *) malloc(FLEXML_BUFFERSTACKSIZE);
289  assert(graphxml_bufferstack);
290  #ifdef FLEX_DEBUG
291  {
292      int i;
293      for (i = 0; i < blimit; i++) {
294          graphxml_bufferstack[i] = '\377';
295      }
296  }
297  #endif
298  graphxml_bufferstack[0] = '\0';
299  indexstack = (int *) malloc(FLEXML_INDEXSTACKSIZE * sizeof(int));
300  assert(indexstack);
301  indexstack[0] = 0;
302
303   /* FleXML_init */
304   bnext = inext = 1;
305   graphxml_bufferliteral('\0', &bnext, "-1.0");
306   graphxml_bufferliteral('\0', &bnext, "-1.0");
307   graphxml_bufferliteral('\0', &bnext, "-1.0");
308   if(!graphxml_statenames) {graphxml_statenames= (const char **)calloc(IMPOSSIBLE,sizeof(char*));
309   graphxml_statenames[PROLOG] = NULL;
310   graphxml_statenames[DOCTYPE] = NULL;
311   graphxml_statenames[EPILOG] = NULL;
312   graphxml_statenames[INCOMMENT] = NULL;
313   graphxml_statenames[INPI] = NULL;
314   graphxml_statenames[VALUE1] = NULL;
315   graphxml_statenames[VALUE2] = NULL;
316   graphxml_statenames[CDATA] = NULL;
317   graphxml_statenames[ROOT_graphxml_graph] = NULL;
318   graphxml_statenames[AL_graphxml_graph] = NULL;
319   graphxml_statenames[S_graphxml_graph] = "graph";
320   graphxml_statenames[S_graphxml_graph_1] = "graph";
321   graphxml_statenames[S_graphxml_graph_2] = "graph";
322   graphxml_statenames[S_graphxml_graph_3] = "graph";
323   graphxml_statenames[S_graphxml_graph_4] = "graph";
324   graphxml_statenames[S_graphxml_graph_5] = "graph";
325   graphxml_statenames[E_graphxml_graph] = "graph";
326   graphxml_statenames[ROOT_graphxml_node] = NULL;
327   graphxml_statenames[AL_graphxml_node] = NULL;
328   graphxml_statenames[E_graphxml_node] = "node";
329   graphxml_statenames[ROOT_graphxml_edge] = NULL;
330   graphxml_statenames[AL_graphxml_edge] = NULL;
331   graphxml_statenames[E_graphxml_edge] = "edge";
332   }
333
334  /* COMMENTS and PIs: handled uniformly for efficiency. */
335
336 <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>{
337  "<!--" ENTER(INCOMMENT);
338  "<?" ENTER(INPI);
339 }
340 <INCOMMENT>{
341  "-->"          LEAVE;
342  "--"           |
343  .              |
344  \n             SKIP;
345  <<EOF>>        FAIL("EOF in comment.");
346 }
347 <INPI>{
348  "?>"           LEAVE;
349  .              |
350  \n             SKIP;
351  <<EOF>>        FAIL("EOF in PI (processing instruction).");
352 }
353
354  /* SPACES: skipped uniformly */
355
356 <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;
357
358  /* PROLOG: determine root element and process it. */
359
360 <PROLOG>{
361  "<?xml"({S}version{Eq}(\'{VersionNum}\'|\"{VersionNum}\"))?({S}encoding{Eq}(\'[^']*\'|\"[^"]*\"))?"?>" SET(DOCTYPE); 
362  "<?xml"[^>]*">" FAIL("Bad declaration %s.",yytext);
363 }
364
365 <PROLOG,DOCTYPE>{
366  "<!DOCTYPE"{S}"edge"{S}SYSTEM{S}("'graphxml.dtd'"|"\"graphxml.dtd\""){s}">" SET(ROOT_graphxml_edge);
367  "<!DOCTYPE"{S}"node"{S}SYSTEM{S}("'graphxml.dtd'"|"\"graphxml.dtd\""){s}">" SET(ROOT_graphxml_node);
368  "<!DOCTYPE"{S}"graph"{S}SYSTEM{S}("'graphxml.dtd'"|"\"graphxml.dtd\""){s}">" SET(ROOT_graphxml_graph);
369  "<!"[^>-][^>]*">" FAIL("Bad declaration %s.",yytext);
370  .              FAIL("Unexpected character `%c' in prolog.", yytext[0]);
371  <<EOF>>        FAIL("EOF in prolog.");
372 }
373
374  /* RULES DERIVED FROM DTD. */
375
376  /* <!-- Small DTD for xbt graphs. -->  */
377
378  /*     isDirected (true|false) "true"
379   * >  */
380
381 <S_graphxml_graph,S_graphxml_graph_3,S_graphxml_graph_1,S_graphxml_graph_5,S_graphxml_graph_2,S_graphxml_graph_4,E_graphxml_graph>"<graph"{s} FAIL("Starting tag <graph> is not allowed here.");
382
383 <ROOT_graphxml_graph>"<graph"{s} {
384   AX_graphxml_graph_isDirected = A_graphxml_graph_isDirected_true;
385   ENTER(AL_graphxml_graph); pushbuffer(0);
386   }
387
388 <AL_graphxml_graph>{
389  "isDirected"{Eq}"'true'" |
390  "isDirected"{Eq}"\"true\"" A_graphxml_graph_isDirected = A_graphxml_graph_isDirected_true;
391  "isDirected"{Eq}"'false'" |
392  "isDirected"{Eq}"\"false\"" A_graphxml_graph_isDirected = A_graphxml_graph_isDirected_false;
393
394  ">" {
395   LEAVE; STag_graphxml_graph();graphxml_pcdata_ix = 0; ENTER(S_graphxml_graph);
396  }
397  "/>" {
398   LEAVE; STag_graphxml_graph(); graphxml_pcdata_ix = 0; ETag_graphxml_graph(); popbuffer(); /* attribute */
399   switch (YY_START) {
400    case ROOT_graphxml_graph: SET(EPILOG); break;
401   }
402  }
403  .       FAIL("Unexpected character `%c' in attribute list of graph element.", yytext[0]);
404  {Name} FAIL("Bad attribute `%s' in `graph' element start tag.",yytext);
405  <<EOF>> FAIL("EOF in attribute list of `graph' element.");
406 }
407
408 <S_graphxml_graph_1,E_graphxml_graph,S_graphxml_graph_3,S_graphxml_graph_5,S_graphxml_graph>{
409  "</graph"{s}">" {
410   LEAVE;
411   ETag_graphxml_graph();
412   popbuffer(); /* attribute */
413   switch (YY_START) {
414    case ROOT_graphxml_graph: SET(EPILOG); break;
415   }
416  }
417  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</graph>' expected.",yytext);
418  .       FAIL("Unexpected character `%c': `</graph>' expected.",yytext[0]);
419  <<EOF>> FAIL("Premature EOF: `</graph>' expected.");
420 }
421
422  /*     label           CDATA                ""
423   *     name            CDATA                #REQUIRED
424   *     data            CDATA                ""
425   *     position_x          CDATA                "-1.0"
426   *     position_y          CDATA                "-1.0"
427   * >  */
428
429 <S_graphxml_graph_1,S_graphxml_graph_5,S_graphxml_graph_4,E_graphxml_graph>"<node"{s} FAIL("Starting tag <node> is not allowed here.");
430
431 <ROOT_graphxml_node,S_graphxml_graph_2,S_graphxml_graph_3,S_graphxml_graph>"<node"{s} {
432   AX_graphxml_node_label = 0;
433   AX_graphxml_node_name = 0;
434   AX_graphxml_node_data = 0;
435   AX_graphxml_node_position_x = 1;
436   AX_graphxml_node_position_y = 6;
437   ENTER(AL_graphxml_node); pushbuffer(0);
438   }
439
440 <AL_graphxml_node>{
441  "label"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_node_label);
442  "label"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_node_label);
443
444  "name"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_node_name);
445  "name"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_node_name);
446
447  "data"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_node_data);
448  "data"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_node_data);
449
450  "position_x"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_node_position_x);
451  "position_x"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_node_position_x);
452
453  "position_y"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_node_position_y);
454  "position_y"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_node_position_y);
455
456  ">" {
457   if (!AX_graphxml_node_name) FAIL("Required attribute `name' not set for `node' element.");
458   LEAVE; STag_graphxml_node();graphxml_pcdata_ix = 0; ENTER(E_graphxml_node);
459  }
460  "/>" {
461   if (!AX_graphxml_node_name) FAIL("Required attribute `name' not set for `node' element.");
462   LEAVE; STag_graphxml_node(); graphxml_pcdata_ix = 0; ETag_graphxml_node(); popbuffer(); /* attribute */
463   switch (YY_START) {
464    case S_graphxml_graph_2: case S_graphxml_graph_3: case S_graphxml_graph: SET(S_graphxml_graph_3); break;
465    case ROOT_graphxml_node: SET(EPILOG); break;
466   }
467  }
468  .       FAIL("Unexpected character `%c' in attribute list of node element.", yytext[0]);
469  {Name} FAIL("Bad attribute `%s' in `node' element start tag.",yytext);
470  <<EOF>> FAIL("EOF in attribute list of `node' element.");
471 }
472
473 <E_graphxml_node>{
474  "</node"{s}">" {
475   LEAVE;
476   ETag_graphxml_node();
477   popbuffer(); /* attribute */
478   switch (YY_START) {
479    case S_graphxml_graph_2: case S_graphxml_graph_3: case S_graphxml_graph: SET(S_graphxml_graph_3); break;
480    case ROOT_graphxml_node: SET(EPILOG); break;
481   }
482  }
483  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</node>' expected.",yytext);
484  .       FAIL("Unexpected character `%c': `</node>' expected.",yytext[0]);
485  <<EOF>> FAIL("Premature EOF: `</node>' expected.");
486 }
487
488  /*     label           CDATA                ""
489   *     name            CDATA               #IMPLIED
490   *     source          CDATA               #REQUIRED
491   *     target          CDATA               #REQUIRED
492   *     length          CDATA               "-1.0"
493   *     data            CDATA               ""
494   * >  */
495
496 <E_graphxml_graph,S_graphxml_graph_2>"<edge"{s} FAIL("Starting tag <edge> is not allowed here.");
497
498 <ROOT_graphxml_edge,S_graphxml_graph_1,S_graphxml_graph_3,S_graphxml_graph_5,S_graphxml_graph_4,S_graphxml_graph>"<edge"{s} {
499   AX_graphxml_edge_label = 0;
500   AX_graphxml_edge_name = 0;
501   AX_graphxml_edge_source = 0;
502   AX_graphxml_edge_target = 0;
503   AX_graphxml_edge_length = 11;
504   AX_graphxml_edge_data = 0;
505   ENTER(AL_graphxml_edge); pushbuffer(0);
506   }
507
508 <AL_graphxml_edge>{
509  "label"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_edge_label);
510  "label"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_edge_label);
511
512  "name"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_edge_name);
513  "name"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_edge_name);
514
515  "source"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_edge_source);
516  "source"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_edge_source);
517
518  "target"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_edge_target);
519  "target"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_edge_target);
520
521  "length"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_edge_length);
522  "length"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_edge_length);
523
524  "data"{Eq}\' ENTER(VALUE1); BUFFERSET(AX_graphxml_edge_data);
525  "data"{Eq}\" ENTER(VALUE2); BUFFERSET(AX_graphxml_edge_data);
526
527  ">" {
528   if (!AX_graphxml_edge_source) FAIL("Required attribute `source' not set for `edge' element.");
529   if (!AX_graphxml_edge_target) FAIL("Required attribute `target' not set for `edge' element.");
530   LEAVE; STag_graphxml_edge();graphxml_pcdata_ix = 0; ENTER(E_graphxml_edge);
531  }
532  "/>" {
533   if (!AX_graphxml_edge_source) FAIL("Required attribute `source' not set for `edge' element.");
534   if (!AX_graphxml_edge_target) FAIL("Required attribute `target' not set for `edge' element.");
535   LEAVE; STag_graphxml_edge(); graphxml_pcdata_ix = 0; ETag_graphxml_edge(); popbuffer(); /* attribute */
536   switch (YY_START) {
537    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;
538    case ROOT_graphxml_edge: SET(EPILOG); break;
539   }
540  }
541  .       FAIL("Unexpected character `%c' in attribute list of edge element.", yytext[0]);
542  {Name} FAIL("Bad attribute `%s' in `edge' element start tag.",yytext);
543  <<EOF>> FAIL("EOF in attribute list of `edge' element.");
544 }
545
546 <E_graphxml_edge>{
547  "</edge"{s}">" {
548   LEAVE;
549   ETag_graphxml_edge();
550   popbuffer(); /* attribute */
551   switch (YY_START) {
552    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;
553    case ROOT_graphxml_edge: SET(EPILOG); break;
554   }
555  }
556  "</"{Name}{s}">" FAIL("Unexpected end-tag `%s': `</edge>' expected.",yytext);
557  .       FAIL("Unexpected character `%c': `</edge>' expected.",yytext[0]);
558  <<EOF>> FAIL("Premature EOF: `</edge>' expected.");
559 }
560
561  /* EPILOG: after the root element. */
562
563 <EPILOG>{
564  . {SET(PROLOG); yyless(0); CLEANUP; return -1;}
565  <<EOF>>        SUCCEED;
566 }
567
568  /* CHARACTER DATA. */
569
570 <IMPOSSIBLE,VALUE1,VALUE2>{
571  /* Non-defined standard entities... */
572 "&amp;"  BUFFERPUTC('&');
573 "&lt;"   BUFFERPUTC('<');
574 "&gt;"   BUFFERPUTC('>');
575 "&apos;" BUFFERPUTC('\'');
576 "&quot;" BUFFERPUTC('"');
577
578  /* Character entities. */
579  "&#"[[:digit:]]+";"    BUFFERPUTC((unsigned char)atoi(yytext+2));
580  "&#x"[[:xdigit:]]+";"  BUFFERPUTC((unsigned char)strtol(yytext+3,NULL,16));
581 }
582
583 <IMPOSSIBLE,VALUE1,VALUE2,CDATA>{
584  "\n"           |
585  "\r"           |
586  "\r\n"         |
587  "\n\r"         BUFFERPUTC('\n');
588 }
589
590 <IMPOSSIBLE>{
591  "<![CDATA["    ENTER(CDATA);
592  "]""]>"                FAIL("Unexpected `]""]>' in character data.");
593 }
594
595 <VALUE1>{
596  \'             BUFFERDONE; LEAVE;
597  <<EOF>>        FAIL("EOF in literal (\"'\" expected).");
598 }
599
600 <VALUE2>{
601  \"             BUFFERDONE; LEAVE;
602  <<EOF>>        FAIL("EOF in literal (`\"' expected).");
603 }
604
605 <IMPOSSIBLE,VALUE1,VALUE2>{
606  [^<&]          BUFFERPUTC(yytext[0]);
607  [<&]           FAIL("Spurious `%c' in character data.",yytext[0]);
608 }
609
610 <CDATA>{
611  "]""]>"                LEAVE;
612  /* "]""]"              BUFFERPUTC(yytext[0]); BUFFERPUTC(yytext[1]); */
613  .              BUFFERPUTC(yytext[0]);
614  <<EOF>>        FAIL("EOF in CDATA section.");
615 }
616
617  /* Impossible rules to avoid warnings from flex(1). */
618  /* Ideally, this should be replaced by code in flexml.pl that
619     generates just the states not covered by other rules. */
620 <*>{
621  .|[\n] FAIL("Syntax error on character `%c'.", yytext[0]);
622 }
623
624 %%
625
626 /* Element context stack lookup. */
627 int graphxml_element_context(int i)
628 {
629   return (0<i && i<yy_start_stack_depth
630           ? yy_start_stack[yy_start_stack_ptr - i]
631           : 0);
632 }
633
634 #ifdef FLEX_DEBUG
635 void print_yy_stack(char* fmt, ...)
636 {
637   int i = 0; va_list ap; va_start(ap, fmt);
638   vfprintf(stderr, fmt, ap);
639   if (graphxml_statenames) {
640       for (i=1; i<yy_start_stack_ptr; i++) {
641           fprintf(stderr, "%s/", graphxml_statenames[yy_start_stack[i] ]);
642       }
643       fprintf(stderr,"%s\n", graphxml_statenames[YY_START]);
644   }
645   va_end(ap);
646 }
647
648 void print_graphxml_bufferstack()
649 {
650     int i;
651     fputs("Buffer: ", stderr);
652     for (i = 0; i < blimit; i++) {
653        if ( graphxml_bufferstack[i] == '\377' ) break;
654          putc(graphxml_bufferstack[i], stderr);
655     }
656     putc('\n', stderr);
657 }
658
659 static void debug_enter(int state, const char* statename) {
660   yy_push_state(state);
661   if (yy_flex_debug) {
662        print_yy_stack("--ENTER(%s) : ",statename);
663        print_graphxml_bufferstack();
664   }
665 }
666
667 static void debug_leave(void) {
668     if (yy_flex_debug) {
669         print_yy_stack("--LEAVE : ");
670         print_graphxml_bufferstack();
671     }
672   yy_pop_state();
673 }
674
675 static void debug_set(int state, const char* statename) {
676   BEGIN(state);
677   if (yy_flex_debug) print_yy_stack("--SET(%s) : ",statename);
678 }
679 #endif
680
681
682 static void cleanup(void)
683 {
684     if (graphxml_statenames) {
685         free(graphxml_statenames);
686         graphxml_statenames = NULL;
687     }
688     free(graphxml_bufferstack);
689     graphxml_bufferstack = NULL;
690
691     free(indexstack);
692     indexstack = NULL;
693 }
694
695
696 static int fail(const char* fmt, ...)
697 {
698     int chars_left, used;
699     va_list ap; va_start(ap, fmt);
700 #ifdef FLEXML_yylineno
701     used = sprintf(flexml_err_msg,
702                    "Invalid XML (XML input line %d, state %d): ",
703                    yylineno, YY_START);
704 #else
705     used = sprintf(flexml_err_msg,
706                    "Invalid XML (state %d): ",
707                    YY_START);
708 #endif
709     chars_left = flexml_max_err_msg_size - used - 1;
710     vsnprintf(flexml_err_msg + used, chars_left, fmt, ap);
711     va_end(ap);
712
713 #ifndef FLEXML_quiet_parser
714     /* print directly to sdterr */
715     fprintf(stderr, "%s\n", flexml_err_msg);
716     flexml_err_msg[0] = '\0';
717 #endif
718
719     cleanup();
720
721     return 1;
722 }