Re: [Haskell-cafe] Wanted: composoable parsers from haskell-src-exts

2011-03-18 Thread S. Doaitse Swierstra
Although this may need a bit of work you might take the parsing code form the 
Utrecht Haskell Compiler (http://www.cs.uu.nl/wiki/bin/view/UHC/Download), 
which uses the uulib parser combinators. They are top-down parsers, and thus 
can be used to parse any prefix given a specific parser, i.e. given the 
non-terminal which describes the prefix.

The UHC contains a separate scanner, since the layout rule makes scannerless 
parsing very complicated.

The uulib should be easily replaced with the newer uu-parsing lib, but this may 
again a bit of some work. This latter library is more easily adapted, and has 
less complicated internals.

   Doaitse

 


On 14 mrt 2011, at 18:55, J. Waldmann wrote:

> Hi.
> 
> I want to use parsers from haskell-src-exts as sub-parsers,
> which does not seem to work since they insist on consuming the input 
> completely.
> 
> I would need them to parse a maximal prefix, 
> and return the (unconsumed) rest of input as well
> (cf.
> http://hackage.haskell.org/packages/archive/parsec/3.1.1/doc/html/Text-Parsec-Prim.html#v:getInput
> )
> 
> I figure that happy has the %partial directive for that, but the description
> http://www.haskell.org/happy/doc/html/sec-directives.html#sec-partial-parsers
> does not really tell me how to obtain the rest of the input.
> 
> Any hints (or code samples) appreciated. Thanks - J.W.
> 
> 
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Wanted: composoable parsers from haskell-src-exts

2011-03-18 Thread Josef Svenningsson
On Thu, Mar 17, 2011 at 10:58 PM, Niklas Broberg
wrote:

> > >  I already export a partial parser for top-of-file pragmas,
> >
> > I see. What I don't see is how such a parser would return the "rest of
> input".
>
> Hmm. I see. And I see that you are correct in not seeing it, since it
> appears it cannot be done with Happy, which I believed. It would then be
> down to the parser/lexer to pass on unconsumed input, which seems a daunting
> and disruptive task, seeing how the lexer typically would tokenize some
> input in advance before the parser discovers that it cannot consume what has
> been lexed... Hmm.
>

I think this is actually doable, although not necessarily easy, using a
technique due to Oleg. He has used delimited continuations to take ordinary
parsers and make them incremental. Dan Doel has experimented with applying
the technique to Parsec parsers with some success. I think choosing the
right parser monad in Happy can make this work.

Reference to Oleg's technique:
http://okmij.org/ftp/continuations/differentiating-parsers.html

Cheers,

Josef
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Wanted: composoable parsers from haskell-src-exts

2011-03-17 Thread Niklas Broberg
> >  I already export a partial parser for top-of-file pragmas,
>
> I see. What I don't see is how such a parser would return the "rest of
input".

Hmm. I see. And I see that you are correct in not seeing it, since it
appears it cannot be done with Happy, which I believed. It would then be
down to the parser/lexer to pass on unconsumed input, which seems a daunting
and disruptive task, seeing how the lexer typically would tokenize some
input in advance before the parser discovers that it cannot consume what has
been lexed... Hmm.

I still find it a highly desirable feature, and at some point I would like
to give it some further thought, to see if a way can be found. In the mean
time, would you mind filing a feature request at
http://trac.haskell.org/haskell-src-exts ?

Cheers,

/Niklas
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Wanted: composoable parsers from haskell-src-exts

2011-03-15 Thread Johannes Waldmann
Thanks for supporting the idea.

>  I already export a partial parser for top-of-file pragmas, 

I see. What I don't see is how such a parser would return the "rest of input".

J.W.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Wanted: composoable parsers from haskell-src-exts

2011-03-15 Thread Niklas Broberg
Hi Johannes,

The answer is:

A) You can't, the way haskell-src-exts is built. You need to specify the
%partial directives in the happy grammar, so without editing
haskell-src-exts there's no way you could tack on partiality to the existing
parsing primitives.

B) It's a great feature request (to the point where I wonder why I haven't
thought of it before), that should be quite easy to implement. I already
export a partial parser for top-of-file pragmas, there's no reason why I
couldn't export partial parsers for all the other entry points as well. I
hope I can implement it shortly, but if you want it really fast and certain
- patches are most welcome!

Cheers,

/Niklas


On Mon, Mar 14, 2011 at 6:55 PM, J. Waldmann
wrote:

> Hi.
>
> I want to use parsers from haskell-src-exts as sub-parsers,
> which does not seem to work since they insist on consuming the input
> completely.
>
> I would need them to parse a maximal prefix,
> and return the (unconsumed) rest of input as well
> (cf.
>
> http://hackage.haskell.org/packages/archive/parsec/3.1.1/doc/html/Text-Parsec-Prim.html#v:getInput
> )
>
> I figure that happy has the %partial directive for that, but the
> description
>
> http://www.haskell.org/happy/doc/html/sec-directives.html#sec-partial-parsers
> does not really tell me how to obtain the rest of the input.
>
> Any hints (or code samples) appreciated. Thanks - J.W.
>
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Wanted: composoable parsers from haskell-src-exts

2011-03-14 Thread Stephen Tetley
I haven't tried myself - but from the docs, partial parsers seem to
depend on finding an error token so they seem to be partial as in
"handles failure".

If you want to parse specific fragments you probably want to generate
multiple parsers from a single grammar see section 2.7.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Wanted: composoable parsers from haskell-src-exts

2011-03-14 Thread J . Waldmann
Hi.

I want to use parsers from haskell-src-exts as sub-parsers,
which does not seem to work since they insist on consuming the input completely.

I would need them to parse a maximal prefix, 
and return the (unconsumed) rest of input as well
(cf.
http://hackage.haskell.org/packages/archive/parsec/3.1.1/doc/html/Text-Parsec-Prim.html#v:getInput
)

I figure that happy has the %partial directive for that, but the description
http://www.haskell.org/happy/doc/html/sec-directives.html#sec-partial-parsers
does not really tell me how to obtain the rest of the input.

Any hints (or code samples) appreciated. Thanks - J.W.



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe