Ports & compass points in node statements?

Lately I’ve been trying to debug and make-sane Pydot’s parsing and quoting rules, when constructing and generating DOT code.

According to the documented grammar, node_id values (which can contain port values and compass_pt directions), can appear both on the endpoints of an edge_stmt, or in the start of a node_stmt.

The edge_stmt I totally get, but the node_stmt implies that DOT code like this is valid and has a purpose:

digraph {
  node2:port5:nw [label="Node2!", color="red"];
  node1:port1 -> node2:port5:nw;
}

But… does it, actually? It seems functionally identical to this:

digraph {
  node2 [label="Node2!", color="red"];
  node1:port1 -> node2:port5:nw;
}

Obviously that’s a contrived example since the ports in question aren’t actually defined anywhere. But even assuming they are, do complex node_stmts like that have any purpose? Is there some context in which there’s a difference between these?

nodeM [label="foo", color="red"];
nodeM:portN:sw [label="foo", color="red"];
1 Like

It doesn’t have any meaning. It was a small mistake in the language design to allow this.

1 Like

Nice catch

1 Like

Cool, thanks! That’s good to know, actually, because that means we’re probably pretty safe to assume that a user who writes something like this…

import pydot
G = pydot.Dot("Class schedule", "graph")
G.add_node(pydot.Node("01:Math", color="blue"))
G.add_node(pydot.Node("02:Chemistry", color="blue"))
G.add_node(pydot.Node("03:English", color="red"))
G.add_node(pydot.Node("04:Phys.Ed", color="green"))
G.add_node(pydot.Node("05:Lunch", color="yellow"))
G.add_node(pydot.Node("06:French", color="red"))
G.add_node(pydot.Node("07:Physics", color="blue"))

Probably want this output from G.to_string():

graph "Class schedule" {
"01:Math" [color=blue];
"02:Chemistry" [color=blue];
"03:English" [color=red];
"04:Phys.Ed" [color=green];
"05:Lunch" [color=yellow];
"06:French" [color=red];
"07:Physics" [color=blue];
}

(despite them not double-double-quoting all of the node names). And not a set of numbered nodes, each of which has a port named “Math”, “Chemistry”, “English”, etc…