Logo AND Algorithmique Numérique Distribuée

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