
19 Aug
2017
19 Aug
'17
4:37 a.m.
Jeffrey Brown
I want to write a parser that lets someone write "(a #uses b) #because (c #needs d)" and read it into a tree:
data Tree = Tree String Tree Tree | Leaf String magic "(a #uses b) #because (c #needs d)" = Tree "because" (Tree "uses" (Leaf "a") (Leaf "b")) (Tree "needs" (Leaf "c") (Leaf "d"))
I thought I could use Text.Megaparsec.Expr for it, but now I realize it hadnles binary operations, and this is a ternary one.
Suggestions?
Parse it as three binary ones and check the tree afterwards? -- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk