Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top