I'm trying to parse fixed strings with FParsec. For example parsing null
from the documentation:
open FParsec
type Json = JNull
let jnull : Parser<_> = stringReturn "null" JNull
then running jnull
on "null"
gives the expected result
> run jnull "null";;
val it : ParserResult<Json,unit> = Success: JNull
But if I run it on "nulls"
it also succeeds
> run jnull "nulls";;
val it : ParserResult<Json,unit> = Success: JNull
Then I tried to add the requirement that null
should be followed by a space:
let jnull : Parser<_> = stringReturn "null" JNull >>. spaces
However, this gives me the same result as before.
I also tried to use manyMinMaxSatisfyL
:
let jnull: Parser<_> =
manyMinMaxSatisfyL 4 4 isLower "should be null"
>>. pstring "null"
>>. spaces
This one fails on "nulls"
as it should, but is also fails on "null"
:
> run jnull "nulls";;
val it : ParserResult<unit,unit> =
Failure:
Error in Ln: 1 Col: 5
nulls
^
Expecting: 'null'
> run jnull "null";;
val it : ParserResult<unit,unit> =
Failure:
Error in Ln: 1 Col: 5
null
^
Note: The error occurred at the end of the input stream.
Expecting: 'null'
What am I doing wrong here? Or did I completely misunderstand something about parsing?