I try to parse xml-like tags (but not a correct xml document..): the goal is to get back just "Flange width" without the beginning or trailing whitespaces, but with the internal ones.
open FParsec
let testParser =
pstring "<desc>" .>>. spaces
>>. manyCharsTill anyChar (spaces .>>. pstring "</desc>")
run testParser "<desc> Flange width </desc>"
The expected result if I understood the parser combinators:
the anyChar parser to keep swallowing chars unit the "till" parser which looks for spaces followed by the end tag succeeds.
What actually happens, is the "till" parser fails on the space before "width" (as it should) but short circuits the manyTill parser instead of letting the anyChar swallow that space and continue onwards.
Output:
val it : ParserResult<string,unit> =
Failure:
Error in Ln: 1 Col: 15
<desc> Flange width </desc>
^
Expecting: '</desc>'
What am I not getting? or what would be an idiomatic solution here?