Closed gustavomick closed 7 years ago
+1
@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));
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.
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.
@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
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"…}