This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Why there's no ~!> and <~! parsers combinators?

3 replies
gkossakowski
Joined: 2010-03-11,
User offline. Last seen 33 weeks 5 days ago.
Hi,
I'm wondering why there are no method defined like this:
def ~!> [U](p: => Parser[U]): Parser[U] = OnceParser { (for(a <- this; b <- p) yield b).named("~>") } def <~! [U](p: => Parser[U]): Parser[U] = def ~> [U](p: => Parser[U]): Parser[U] = OnceParser { (for(a <- this; b <- p) yield b).named("~>") (for(a <- this; b <- p) yield b).named("~>") }
They would be useful while you want to drop some keywoard and avoid back-tracking at the same time, e.g.:
("val" ~!> ws ~!> ident <~! ws <~! "=") ~! expression
--
Grzegorz Kossakowski

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Why there's no ~!> and <~! parsers combinators?

On Mon, Aug 23, 2010 at 11:57:38AM -0400, Grzegorz Kossakowski wrote:
> def ~!> [U](p: => Parser[U]): Parser[U] = OnceParser { (for(a <- this;
> b <- p) yield b).named("~>") }

Not for any reason. It's one of the first things I added to my
"ParsersPlus" trait when I started writing lots of parsers.

gkossakowski
Joined: 2010-03-11,
User offline. Last seen 33 weeks 5 days ago.
Re: Why there's no ~!> and <~! parsers combinators?
2010/8/23 Paul Phillips <paulp@improving.org>
On Mon, Aug 23, 2010 at 11:57:38AM -0400, Grzegorz Kossakowski wrote:
> def ~!> [U](p: => Parser[U]): Parser[U] = OnceParser { (for(a <- this;
> b <- p) yield b).named("~>") }

Not for any reason.  It's one of the first things I added to my
"ParsersPlus" trait when I started writing lots of parsers. 

Sounds like a chance to provide my first patch to scala library, isn't it?

--
Grzegorz Kossakowski

Stefan Wachter
Joined: 2009-09-18,
User offline. Last seen 42 years 45 weeks ago.
Re: Why there's no ~!> and <~! parsers combinators?

Hi Paul,

can you share your ParsersPlus trait? It would be very interesting to
see what else can help to write parsers.

--Stefan

Am 23.08.2010 18:12, schrieb Paul Phillips:
> On Mon, Aug 23, 2010 at 11:57:38AM -0400, Grzegorz Kossakowski wrote:
>
>> def ~!> [U](p: => Parser[U]): Parser[U] = OnceParser { (for(a <- this;
>> b <- p) yield b).named("~>") }
>>
> Not for any reason. It's one of the first things I added to my
> "ParsersPlus" trait when I started writing lots of parsers.
>
>

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland