Question

Is it possible to parse a non-symbolic operator (e.g., AND, OR) case-insensitively using OperatorPrecedenceParser?

Was it helpful?

Solution

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.)

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top