2

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?

Sam
  • 2,745
  • 3
  • 20
  • 42
  • 1
    This may be largely related (or even a duplicate) of [this question](http://stackoverflow.com/questions/9763942/fparsec-identifiers-vs-keywords). You may need to provide with some code and sample input to explain your needs. – Be Brave Be Like Ukraine Aug 07 '15 at 15:44

0 Answers0