Is it possible to parse a non-symbolic operator (e.g., AND
, OR
) case-insensitively using OperatorPrecedenceParser
?
2 Answers
The OperatorPrecedenceParser has no built-in support for case insensitive matching of non-symbolic operators.
However, if your non-symbolic operators are short or you only have to support a few spelling variants (e.g. all lowercase, all uppercase, only first char uppercase, ...) then you can simply add all variants of the operator that you need to support. (Of course, you'd add the variants with a little helper function, not manually.)

- 3,062
- 21
- 28
It looks like PeekOp
is the method that handles determining whether there is an operator or not. It has no mention or method to handle case-insensitivity, since it relies on straight equality of characters (and CharStream.Match
).
You could always add the various possible versions of the operator manually. e.g.
Add("or");
Add("oR");
Add("Or");
Add("OR");
Finally another option would be to create a helper method to do this.

- 18,775
- 1
- 33
- 64
-
Oh, I couldn't see your deleted (and later undeleted) reply. Otherwise I'd have waited or commented on your reply instead of posting my own. – Stephan Tolksdorf Feb 10 '12 at 00:36
-
It was so far off the wagon I didn't want anyone to read it. I thought I was reading `Invoke`, but I was reading `Add`. `Reserved` is just used to keep operators unique ><. – Guvante Feb 10 '12 at 00:39
-
The helper function ought to do. – Daniel Feb 10 '12 at 01:42