This project has moved and is read-only. For the latest updates, please go here.

Parsing parenthesis in FreeTextLiteral

Dec 7, 2016 at 4:31 PM
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

(fuzzy logic)

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?

Dec 21, 2016 at 3:29 AM
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..