develooper Front page | perl.perl6.compiler | Postings from March 2005

Re: Analysis of operator "?? ::"

Thread Previous | Thread Next
From:
Autrijus Tang
Date:
March 15, 2005 09:35
Subject:
Re: Analysis of operator "?? ::"
Message ID:
20050315173512.GB75992@aut.dyndns.org
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/


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About