[Haskell-cafe] Ternary infix expression parser
Jon Fairbairn
jon.fairbairn at cl.cam.ac.uk
Sat Aug 19 08:37:52 UTC 2017
Jeffrey Brown <jeffbrown.the at gmail.com> writes:
> 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 at cl.cam.ac.uk
More information about the Haskell-Cafe
mailing list