- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Why there's no ~!> and <~! parsers combinators?
Mon, 2010-08-23, 16:57
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
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
Mon, 2010-08-23, 17:37
#2
Re: Why there's no ~!> and <~! parsers combinators?
2010/8/23 Paul Phillips <paulp@improving.org>
Sounds like a chance to provide my first patch to scala library, isn't it?
--
Grzegorz Kossakowski
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
Tue, 2010-08-24, 09:07
#3
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.
>
>
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.