diff --git a/source/engine/grammar.ne b/source/engine/grammar.ne index 3d3bbcd71..487f0fb64 100644 --- a/source/engine/grammar.ne +++ b/source/engine/grammar.ne @@ -2,14 +2,21 @@ main -> - CalcExpression {% id %} - | Boolean {% id %} - | Variable {% id %} - | NegatedVariable {% id %} + AS {% id %} + | Comparison {% id %} + | NonNumericTerminal {% id %} + +NumericTerminal -> + Variable {% id %} | TemporalVariable {% id %} | FilteredVariable {% id %} | percentage {% id %} - | Comparison {% id %} + | number {% id %} + +# Parentheses +P -> "(" _ AS _ ")" {% function(d) {return {category:'parentheses', explanation: d[2]}} %} + | NumericTerminal {% id %} + Comparison -> Comparable _ ComparisonOperator _ Comparable {% d => ({ category: 'comparison', @@ -18,7 +25,13 @@ Comparison -> Comparable _ ComparisonOperator _ Comparable {% d => ({ explanation: [d[0], d[4]] }) %} -Comparable -> (number | percentage | CalcExpression | Variable | TemporalVariable | Constant) {% d => d[0][0] %} +Comparable -> ( AS | NonNumericTerminal) {% d => d[0][0] %} + +NonNumericTerminal -> + Boolean {% id %} + | String {% id %} + | NegatedVariable {% id %} + ComparisonOperator -> ">" | "<" | ">=" | "<=" | "=" | "!=" @@ -36,33 +49,45 @@ Temporalities -> "annuel" | "mensuel" {% id %} #----- -CalcExpression -> Term _ ArithmeticOperator _ Term {% d => ({ +# Addition and subtraction +AS -> AS _ ASOperator _ MD {% d => ({ category: 'calcExpression', operator: d[2], explanation: [d[0], d[4]], type: 'numeric' }) %} + | MD {% id %} + + +ASOperator -> "+" {% id %} + | "-" {% id %} + +MDOperator -> "*" {% id %} + | "/" {% id %} + +# Multiplication and division +MD -> MD _ MDOperator _ P {% d => ({ + category: 'calcExpression', + operator: d[2], + explanation: [d[0], d[4]], + type: 'numeric' +}) %} + + | P {% id %} + Term -> Variable {% id %} | FilteredVariable {% id %} | number {% id %} | percentage {% id %} -ArithmeticOperator -> "+" {% id %} - | "-" {% id %} - | "*" {% id %} - | "/" {% id %} - - - - Variable -> VariableFragment (_ Dot _ VariableFragment {% d => d[3] %}):* {% d => ({ category: 'variable', fragments: [d[0], ...d[1]], type: 'numeric | boolean' }) %} -Constant -> "'" [ .'a-zA-Z\-\u00C0-\u017F ]:+ "'" {% d => ({ +String -> "'" [ .'a-zA-Z\-\u00C0-\u017F ]:+ "'" {% d => ({ category: 'value', type: 'string', nodeValue: d[1].join('') @@ -84,3 +109,4 @@ percentage -> [0-9]:+ ([\.] [0-9]:+):? [\%] {% d => ({category: 'percenta Boolean -> "oui" {% d=> ({category: 'boolean', nodeValue: true}) %} | "non" {% d=> ({category: 'boolean', nodeValue: false}) %} + diff --git a/source/engine/treat.js b/source/engine/treat.js index e0a1a710d..34787f4a5 100644 --- a/source/engine/treat.js +++ b/source/engine/treat.js @@ -211,6 +211,7 @@ export let treatString = (rules, rule) => rawNode => { return { evaluate, jsx, + operator, text: rawNode, category: parseResult.category,