문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top