wwalser / merv

Simple logical expression evaluator.
The Unlicense
1 stars 0 forks source link

Logical Condition Or not working as expected. #1

Open kervanaslan opened 3 years ago

kervanaslan commented 3 years ago

Firstly, thanks for this great library. It is the first and alone in NPM.

But I'm getting some trouble.

This code needs to return true but returns false;

var mervjs = require("mervjs").default;

const mervInstance = mervjs({variables: {"PDP_title":'ABC',"article_description":'Brille-Ray-Ban-Schwarz'}});
const mervExpression = 'PDP_title=="Seenx" || article_description=="Brille-Ray-Ban-Schwarz"';

var result = mervInstance.parse(mervExpression)(); // result must be true but returning false

Also this code doesn't work as expected.

var mervjs = require("mervjs").default;

const mervInstance = mervjs({variables: {"PDP_title":'ABC',"article_description":'Brille-Ray-Ban-Schwarz'}});
const mervExpression = 'PDP_title=="ABC" && article_description=="Brille-Ray-Ban-Schwarz"';

var result = mervInstance.parse(mervExpression)(); //must be true but returning false

am I doing a mistake in expression?

wwalser commented 3 years ago

Because the parser does not implement operator precedence the expression that is actually executing is not what you intend.

'PDP_title=="Seenx" || article_description=="Brille-Ray-Ban-Schwarz"'

I know what you want to execute with that statement but what is actually being executed is: ((article_description=="Brille-Ray-Ban-Schwarz") || "Seenx") == PDP_title

This is annoying enough that I think a bug is justified.

This library was written on a lark in a couple of hours, I can't commit to fixing the problem. Patches are welcome, of course, but it's also reasonable to another library.

kervanaslan commented 3 years ago

Thank you for reply.

Can you offer me another library that fits your requirements?