Logo AND Algorithmique Numérique Distribuée

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