From: Mark Tarver
Subject: Re: Type of a Skip Parser?
Date: 
Message-ID: <1179475923.343037.258690@o5g2000hsb.googlegroups.com>
On 15 May, 19:02, Alex Rubinsteyn <···············@gmail.com> wrote:
> Hello,
> I am implementing a parser combinator library in C++. I know C++ isn't
> a popular language in this group, but my question is about getting the
> type signatures of parsers to match, which is a problem some here may
> have dealt with in other languages. Specifically, I can't figure out
> how implement the skip parser (which consumes input but returns
> nothing).
>
> My parsers are class templates parameterized on their Result and Input
> types.
>
> For example, this parser recognizes the containing the character a
> ch('a') //The type of this parser is Parser<string, string>.
>
> Here are two parsers sequentially linked to recognize the string
> ("()"):
> ch('(') >> ch(')') //The type of this parser is SeqParser<string,
> string>
>
> Now, if I wanted to write something like:
> Parser<int, string>* int_in_parens = skip(ch('(')) >> integer >>
> skip(ch(')'))
>
> I encounter all sorts of difficulties. int_in_parens recognizes string
> like "(394)" and should return the enclosed integer.
> How do I write the >> combinator to accomplish this?  Do I need to
> make "skippedness" part of the type (Parser<Result, Input, bool
> Skip>)?
>
> Thanks,
> Alex

I'm not a C++ programmer, Alex, but if I were doing the job in a
functional language, then I'd build up the expected output as a list.
The semantic actions of your parser would append their output to this
list and the
skip action would just append the empty list or leave the global
output unchanged.  (Which course you take depends on how you design
your parser).

If your FPL is untyped this is no problem.  If the parse output is a
unityped list then types are no problem either.

If you need types and the list is not unityped I'd probably do it in
Qi because for that sort of thing Qi is good.  However you could also
do it in Haskell or ML, but you would probably need constructor
functions.

Apologies if I'm repeating advice given.  I've not got time to read
this whole thread.

Mark