When using alternative parsers, is there an option to get which parser matched input.
My input string can be like below format
{firstPart_number} {secondPart_operator_symbol} {thirdPart}
Here firstPart is always number, second part is alternative parser to parse operator and thirdPart is also alternative (of number, list of string).
sample input
1 + 2
5 * 3
1 in {2,45,6}
Since my discriminated unions are of different types, I want to know which parser matched input so that based on that parser I can create instance of my discriminate union type?
How to handle this situation in FParsec, where my first part is same across parsers but second and third parsers are different and based on that instantiate Type using |>>
|>>operator. Something likelet pOperator = (pstr "*" |>> OpTimes) <|> (pstr "+" |>> OpPlus) <|> (pstr "in" |>> OpIn). But I'd like to see your code so I can give better suggestions. - rmunn