Alexander Galkin
Alexander Galkin

Reputation: 12554

Parsing string literals with FParsec?

I would like to parse string literals using FParsec. By "string literals" I mean something between opening and closing quote (in my case -- single quote):

'Please, switch off your mobile phone'

What I am currently doing is the following:

let string = between (pstring "'") (pstring "'") (manySatisfy isLetter)

But this stops after the first letter consumed. Is there any way to make it greedy?

Upvotes: 2

Views: 1422

Answers (1)

pad
pad

Reputation: 41290

It's already greedy; manySatisfy isLetter parses a sequence of letters from the input stream.

The problem is that the parser fails with , or spaces since they are not letters. It could be fixed by using:

manyChars (noneOf "'")

or more explicitly using:

manySatisfy ((<>) '\'')

instead.

Upvotes: 8

Related Questions