]> granicus.if.org Git - graphviz/commitdiff
Fix lefty parser to allow anonymous graphs
authorEmden R. Gansner <erg@research.att.com>
Thu, 18 Jul 2013 15:17:37 +0000 (11:17 -0400)
committerEmden R. Gansner <erg@research.att.com>
Thu, 18 Jul 2013 15:17:37 +0000 (11:17 -0400)
cmd/lefty/dot2l/dot2l.c
cmd/lefty/dot2l/dotparse.y

index 8a0ff1077eae6b6f067bd4c571bf70b14ebfc943..496d86cc1d439bb87eeab36250befea064e01c79 100644 (file)
@@ -522,8 +522,16 @@ static void quotestring (char *buf, Tobj so) {
     *s1++ = '"', *s1 = 0;
 }
 
+static void anonname(char* buf)
+{
+    static int              anon_id = 0;
+
+    sprintf(buf,"_anonymous_%d",anon_id++);
+}
+
 void D2Lbegin (char *name) {
 
+    char buf[BUFSIZ];
     newgid = neweid = newnid = 0;
     attrclass = GRAPH;
 
@@ -535,6 +543,10 @@ void D2Lbegin (char *name) {
 
     gmark = Mpushmark ((gstack->g = Ttable (12)));
     Tinss (gstack->g, "type", Tstring (gtype));
+    if (!name) {
+        anonname(buf);
+        name = buf;
+    }
     Tinss (gstack->g, "name", Tstring (name));
 
     /* the dictionaries */
index 07b159382387410dc0bdfe87da71d1d69d32c2d1..a5e1e41c7a62e2d10811aa853508fbca7ed2684b 100644 (file)
@@ -43,11 +43,12 @@ extern void yyerror(const char *fmt, ...);
 %token <i> T_node T_edge T_edgeop
 %token <s> T_id
 %type <o> node_name node_id subg_stmt
+%type <s> optgraphname
 %left <i> T_subgraph /* to eliminate subgraph hdr shift/reduce conflict */
 %left '{'
 %%
 
-file: graph_type T_id
+file: graph_type optgraphname
     { D2Lbegin ($2); free ($2); }
   '{' stmt_list '}'
     { D2Lend (); }
@@ -57,6 +58,8 @@ file: graph_type T_id
     { D2Labort (); }
 ;
 
+optgraphname:   T_id {$$=$1;} | /* empty */ {$$=0;} ;
+
 graph_type: T_graph /* safe to change graph type/name before contents appear */
     { gtype = "graph"; etype = "--"; }
 | T_strict T_graph