graphviz
graphviz copied to clipboard
Parsing issue
Hello,
I have this simple code:
runParser' Data.GraphViz.Parsing.parseUnqt $ printDotGraph $ digraph (Str "x") $ do "a0" --> "a1"
however it results in this error:
*** Exception: Error when parsing Dot code:
Expected one or more digits
Parse.many1Satisfy: failed
Remaining input:
"digraph x {\n a0 -> a1;\n}"
Same if one changes digraph to graph.
@CGenie I'd guess that you doing this in ghci; there runParser' :: Parse a -> Text -> a has no idea which a to pick, defaults to a ~ Int and then bails out on invalid input. If that's indeed the case, try specifying the expected type explicitly. Something like DotGraph String should do the trick.
ghci> (runParser' Data.GraphViz.Parsing.parseUnqt $ printDotGraph $ digraph (Str "x") $ do "a0" --> "a1") :: DotGraph String
fromCanonical DotGraph {strictGraph = False, directedGraph = True, graphID = Just (Str "x"), graphStatements = DotStmts {attrStmts = [], subGraphs = [], nodeStmts = [DotNode {nodeID = "a0", nodeAttributes = []},DotNode {nodeID = "a1", nodeAttributes = []}], edgeStmts = [DotEdge {fromNode = "a0", toNode = "a1", edgeAttributes = []}]}}
Indeed!
runParser' (Data.GraphViz.Parsing.parse :: Parse (Data.GraphViz.DotGraph Text)) $ printDotGraph $ graph (Str "x") $ do "a0" --> "a1"
returns
DotGraph {strictGraph = False, directedGraph = False, graphID = Just (Str "x"), graphStatements = DotStmts {attrStmts = [], subGraphs = [], nodeStmts = [], edgeStmts = [DotEdge {fromNode = "a0", toNode = "a1", edgeAttributes = []}]}}
Thanks!