I am trying to create a parser that recognizes the names of predefined functions in contrast to general/random string literals.
I am looking to create a parser starting with the following code as the function defintion: let pArray (arr:'a[]) :Parser<'a> =
... but I am unsure how to continue.
In short, I think I need to somehow get the CharStream
(as a string) out of the Parser<'a>
type and compare this with what is contained in the array. Just not sure how to achieve that?
The other alternative is to create an array of string parsers - one for each element of the array and apply/combine them with the alternative combinator <|>
into a single parser. This seems (no evidence) heavy-handed though given that I have approx 400 distinct functions. Is it OK to create a parser with this many alternatives or will performance come under undue pressure?
I have searched in the FParsec user guide but couldn't find something matching this scenario - am I on the right path or is this NOT the way I should be solving this problem?