I think Jack's solution should do the trick for you. However, if you're looking for a primitive that represents a parser which succeeds, without consuming any input, then you probably want preturn
from FParsec.Primitives
(see preturn
in the documentation).
It could be useful if you were combining parsers that build values of some AST instead of strings. For example if you had a discriminated union:
type Vehicle = Car | Bike | Other
You could use pstring "car" >>% Car
and pstring "bike" >>% Bike
to build parsers that return Vehicle
values. Then you could combine them using <|>
and add a special (empty) case using preturn
:
let parseA =
pstring "car" >>% Car <|>
pstring "bike" >>% Bike <|>
preturn Other
The preturn
operation is probably not used directly very often, but it is one of the basic primitives (because it defines the monadic unit or return operation of parsers).