문제

I would like to parse a big sentence, which can contain names in fsharp. I posit that names is in the form first name + last name. In the absence of a first name list (can't find, will do later), I say that a first name is a string of length 4 or more, same for the last name.

When I try my very smart parser

let firstorlastname x = (parray 4 letter)  x
firstorlastname "JEAN"
firstorlastname "CHRISTOPHE"

So, it works for both, but the problem is that it consumes only 4 characters, which is not the desired behaviour for Christophe. I would like the whole word to be consumed.

How can I instruct FParsec to consume the entire word, but fail if the word is less than 4 characters ?

도움이 되었습니까?

해결책

Haven't tested it, but I think this should do it:

let firstOrLastName = manyMinMaxSatisfy 4 Int32.MaxValue isLetter
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top