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

有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top