[Haskell-beginners] Consuming Rule Based Parsing

Christopher Howard christopher.howard at frigidcode.com
Sat Nov 17 02:13:17 CET 2012


On 11/16/2012 12:55 AM, Karl Voelker wrote:
> 
> 
> There is an approach called "parser combinators". The basic idea is this:
> 
> type Parser a = String -> [(a, String)]
> 
> In other words, a parser of values of type "a" is a function which takes
> a string and returns all possible parses of some prefix of that string
> as an "a"-value, each paired with whatever input was left after parsing.
> 
> You can then start writing functions to combine parsers. Thus, you end
> up with "parser combinators".
> 
> There is a library called Parsec which is the industrial-strength
> incarnation of the parser combinator concept. But I would recommend that
> you start by getting familiar with a home-grown parser combinator
> library of your own.
> 
> -Karl

Thank you for your help. Can you elaborate a little more on your
explanation? So, would "a" be some data type representing the atoms of
the grammar? Or some kind of recursive data type that could represent
any kind of valid structure? Or...?

I'll wait until I'm clear on that point before asking about how I would
combine parsers. (Presumably, two combined parsers would both have to
have the same "a" type.)

-- 
frigidcode.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 551 bytes
Desc: OpenPGP digital signature
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121116/b56054c9/attachment.pgp>


More information about the Beginners mailing list