EdgeVerve / feel

Expression Language for creating and executing business rules in decision table based on DMN 1.1 specification for conformance level 3
MIT License
93 stars 48 forks source link

<= ( 1 + 2 ) not working #4

Closed gustavomick closed 7 years ago

gustavomick commented 7 years ago

hi, i was testing few examples and looks like this case is not working. is it valid?

res: peg$SyntaxError {message: "Expected "-", ".", [0-9], [?], [A-Z], [_], [a-z], …ꯥꯨ꯭ﬞ︀-️︠-︯], string, or whitespace but "(" found.", expected: Array(10), found: "(", location: Object, name: "SyntaxError"…}

raghav135 commented 7 years ago

+1

pragyandas commented 7 years ago

@gustavomick This is an invalid expression. According to the FEEL grammar, the right-hand side token in a "simple positive unary test" (the type of expression as mentioned) can only be a literal or a variable (called a name in FEEL) and cannot be an expression. But <= ( 1 + 2 ) can be achieved by assigning (1 + 2) to a context variable, and using the variable name in the expression as illustrated in the below example,


const FEEL = require('./dist/feel');

var context = '{a : (1 + 2)}'
var text = '>= a';
var parsedContext = FEEL.parse(context);
var parsedGrammar = FEEL.parse(text);

parsedContext.build().then(ctx => {
    return parsedGrammar.build(ctx);
}).then(result => {
    console.log(result(4));
}).catch(err => console.log(err));
gustavomick commented 7 years ago

Thanks for the explanation, i checked that ( page 108 ). My example thou was may be too trivial, i was thinking more about setting a threshold/alarm example, where if X <= ( Y * 1.10 ) => True. if you don't mind to give me your thoughts on this. thanks.

pragyandas commented 7 years ago

I think you can do *"if X <= ( Y 1.10 ) then true else false" and take X and Y as part of context or payload.

gustavomick commented 7 years ago

@pragyandas thanks but in this context i have 2 inputs, X and Y , both are numbers, so i have to return X if my expression is at column X so that rule resolves as true / valid. "if X <= ( Y * 1.10 ) then X else !X" is like that?? this example is related to discussion on usability, where something that should be very trivial to write for user, ends convoluted bc spec has maturity few pendings. thinking out loud thou, appreciate your feedback on this matter. thanks