Menu

#16 Unable to handle a String contains textual Operator

pending
Fathzer
None
Bug
None
2017-12-29
2017-09-08
Anonymous
No

I am following the guide to create a evaluator with textual operators:
http://javaluator.sourceforge.net/en/doc/tutorial.php?chapter=textualOperators
It works fine following the guide.

But if the value in the map variableToValue contains the String "AND", the evaluator returns unexpected result. See the test code below:

 public static void main(String[] args) {
    Map<String,String> variableToValue = new HashMap<String, String>();
    variableToValue.put("type", "PORT AND A");
    AbstractEvaluator<Boolean> evaluator = new TextualOperatorsEvaluator();
    System.out.println ("type='PORT AND A' AND true -> "+evaluator.evaluate("type='PORT AND A' AND true", variableToValue));
  }

It prints:
type='PORT AND A' AND true -> false

Discussion

  • Anonymous

    Anonymous - 2017-09-08

    Is there any way to escape the Operator?

     
  • Fathzer

    Fathzer - 2017-09-08

    Hi,
    The problem is with the protected Iterator<string> tokenize(String expression).
    It should cut the expression into tokens following your own grammar.
    The example in the tutorial states the tokens are separated by blank character, but it is not the case in the example you have.
    So you'll have to write a customized tokenize method that would return the following tokens in your example:
    type=PORT AND A
    AND
    * true
    If you need quote and escaped quote, you should handle these customizations yourself, sorry.
    Best regards,
    Jean-Marc Astesana</string>

     

    Last edit: Fathzer 2017-12-29
  • Anonymous

    Anonymous - 2017-09-11

    Hi,

    Thank you for your message. I finally resolve it by replacing the value that contains the operator with a String, and put the value in the map with the replaced String as the key. And then during evaluating the operands, I get the value from the map and use the value as the operand.

    Regards,
    Wenyuan

     
  • Fathzer

    Fathzer - 2017-12-29
    • status: unread --> pending
     

Anonymous
Anonymous

Add attachments
Cancel