From 72e614d3e0712cde76c838a17f8fd8bb3c5ce706 Mon Sep 17 00:00:00 2001 From: "Emden R. Gansner" Date: Thu, 18 Jul 2013 11:17:37 -0400 Subject: [PATCH] Fix lefty parser to allow anonymous graphs --- cmd/lefty/dot2l/dot2l.c | 12 ++++++++++++ cmd/lefty/dot2l/dotparse.y | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/lefty/dot2l/dot2l.c b/cmd/lefty/dot2l/dot2l.c index 8a0ff1077..496d86cc1 100644 --- a/cmd/lefty/dot2l/dot2l.c +++ b/cmd/lefty/dot2l/dot2l.c @@ -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 */ diff --git a/cmd/lefty/dot2l/dotparse.y b/cmd/lefty/dot2l/dotparse.y index 07b159382..a5e1e41c7 100644 --- a/cmd/lefty/dot2l/dotparse.y +++ b/cmd/lefty/dot2l/dotparse.y @@ -43,11 +43,12 @@ extern void yyerror(const char *fmt, ...); %token T_node T_edge T_edgeop %token T_id %type node_name node_id subg_stmt +%type optgraphname %left 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 -- 2.40.0