I have set up a basic grammar class, in the constructor I have the following:
FreeTextLiteral FreeTextTerm = new FreeTextLiteral("FreeTextTerm", FreeTextOptions.AllowEof | FreeTextOptions.AllowEmpty);
var Expression = new NonTerminal("Expression");
var ParenthesizedExpression = new NonTerminal("ParenthesizedExpression");
ParenthesizedExpression.Rule = "(" + Expression + ")";
this.Root = Expression;
Expression.Rule = FreeTextTerm | ParenthesizedExpression;
When I parse a string such as
I want it to recognise the whole thing as being a ParenthesizedExpression, and then go on to recognise the 'fuzzy logic' part as being the FreeTextTerm. Instead, it just recognises the whole phrase (fuzzy logic) as a FreeTextTerm. Any ideas on how I can change
the code to pick up the parenthesis correctly?
I believe if you flip the expression.Rule to:
Expression.Rule = ParenthesizedExpression | FreeTextTerm;
It should give preference to evaluating as a ParenthesizedExpression first.
Note that I'm no expert to parsing so not sure if there are any additional implications of doing this..