From bf6455c33c1263df3fe204fc68ecc7055f3d1ed0 Mon Sep 17 00:00:00 2001 From: Mael Date: Tue, 4 Jun 2019 16:01:21 +0200 Subject: [PATCH] :memo: :gear: Documentation de la grammaire --- source/engine/grammar.ne | 20 ++++++++++++-------- source/engine/maSuperFonction.js | 6 ------ 2 files changed, 12 insertions(+), 14 deletions(-) delete mode 100644 source/engine/maSuperFonction.js diff --git a/source/engine/grammar.ne b/source/engine/grammar.ne index 3ba147294..cfaf4e574 100644 --- a/source/engine/grammar.ne +++ b/source/engine/grammar.ne @@ -1,3 +1,7 @@ +# This grammar is inspired by the "fancier grammar" tab of the nearley playground : https://omrelli.ug/nearley-playground + +# Look for the PEMDAS system : Parentheses, Exponents (omitted here), Multiplication, and you should guess the rest :) + @preprocessor esmodule @{% @@ -5,7 +9,7 @@ import {string, filteredVariable, variable, temporalVariable, operation, boolea %} main -> - AS {% id %} + AdditionSubstraction {% id %} | Comparison {% id %} | NonNumericTerminal {% id %} @@ -16,14 +20,14 @@ NumericTerminal -> | percentage {% id %} | number {% id %} -Parentheses -> "(" AS ")" {% ([,e]) => e %} +Parentheses -> "(" AdditionSubstraction ")" {% ([,e]) => e %} | NumericTerminal {% id %} ComparisonOperator -> ">" | "<" | ">=" | "<=" | "=" | "!=" Comparison -> Comparable _ ComparisonOperator _ Comparable {% operation('comparison')%} -Comparable -> ( AS | NonNumericTerminal) {% ([[e]]) => e %} +Comparable -> ( AdditionSubstraction | NonNumericTerminal) {% ([[e]]) => e %} NonNumericTerminal -> Boolean {% id %} @@ -46,18 +50,18 @@ Temporality -> "annuel" | "mensuel" {% id %} # Addition and subtraction -AS -> AS _ ASOperator _ MD {% operation('calculation') %} - | MD {% id %} +AdditionSubstraction -> AdditionSubstraction _ AdditionSubstractionOperator _ MultiplicationDivision {% operation('calculation') %} + | MultiplicationDivision {% id %} -ASOperator -> "+" {% id %} +AdditionSubstractionOperator -> "+" {% id %} | "-" {% id %} -MDOperator -> "*" {% id %} +MultiplicationDivisionOperator -> "*" {% id %} | "/" {% id %} # Multiplication and division -MD -> MD _ MDOperator _ Parentheses {% operation('calculation') %} +MultiplicationDivision -> MultiplicationDivision _ MultiplicationDivisionOperator _ Parentheses {% operation('calculation') %} | Parentheses {% id %} Term -> Variable {% id %} diff --git a/source/engine/maSuperFonction.js b/source/engine/maSuperFonction.js deleted file mode 100644 index 0039db3d7..000000000 --- a/source/engine/maSuperFonction.js +++ /dev/null @@ -1,6 +0,0 @@ -export default d => ({ - category: 'comparison', - type: 'boolean', - operator: d[2][0], - explanation: [d[0], d[4]] -})