My solution for graph:
My solution for edges:
The edges solution was simple enough that I could emit the code directly during the parse and hence did not have to create an abstract syntax tree.