Commit 72e614d3 authored by Emden R. Gansner's avatar Emden R. Gansner

Fix lefty parser to allow anonymous graphs

parent f7679ef0
......@@ -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 */
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment