On Tue, Mar 08, 2005 at 11:02:23AM +0800, Shu-chun Weng wrote:
> Hello, this mail is an analysis of implementing operator ternary
> operator "?? ::" in pugs.

Greetings.  Thanks for your extensive survey, which helped a lot
on pruning dead ends in my attempt in getting this implemented.

The key insight was provided a few minutes ago by kosmikus on #haskell:

    00:52 < kosmikus> could you somehow view the whole thing from ? to :
    as an infix binary operator?
    00:52 < kosmikus> the binary operators can be parametrized over
    arbitrary parsers, can't they?

and, to keep a long story short, ?? :: is now parsed correctly as
(ternOp "??" "::" "if") in Parser.hs, with ternOp defined thus:

    ternOp pre post syn = (`Infix` AssocRight) $ do
        symbol pre
        y <- parseTightOp
        symbol post
        return $ \x z -> Syn syn [x, y, z]

that is, it reads everything between ?? and ::, allowing only
tight operators (i.e. "=" and everything tighter than it, but not
"and" etc), and bind the left and right inside an "if" syntactic
form.  The AssocRight lets us parse (x ?? y :: z ?? v :: w) as
(x ?? y :: (z ?? v :: w)) instead of the other way around.

So, I consider this case closed.  Let me know if you manage to
uncover any subtle errors in ?? :: parsing.  Thanks again for your
investigation work and unit tests!

Thanks,
/Autrijus/

Attachment: pgpYd6TDEPOSt.pgp
Description: PGP signature

Reply via email to