2019-05-02 14:24:22 +00:00
@preprocessor esmodule
@{%
import maSuperFonction from './maSuperFonction'
import treatVariableTransforms from './treatVariable'
%}
# To understand or edit this file, use the awesome nearley playground (but save your work, it can crash sometimes) : https://omrelli.ug/nearley-playground/
2017-05-07 17:45:44 +00:00
2017-05-09 13:39:42 +00:00
2017-03-07 17:25:25 +00:00
main ->
2019-05-02 13:58:39 +00:00
AS {% id %}
| Comparison {% id %}
| NonNumericTerminal {% id %}
NumericTerminal ->
Variable {% id %}
2018-11-13 15:14:57 +00:00
| TemporalVariable {% id %}
2017-06-22 16:03:12 +00:00
| FilteredVariable {% id %}
2017-09-19 11:17:43 +00:00
| percentage {% id %}
2019-05-02 13:58:39 +00:00
| number {% id %}
# Parentheses
P -> "(" _ AS _ ")" {% function(d) {return {category:'parentheses', explanation: d[2]}} %}
| NumericTerminal {% id %}
2017-03-06 16:35:30 +00:00
2019-05-02 14:24:22 +00:00
Comparison -> Comparable _ ComparisonOperator _ Comparable {% yo => maSuperFonction(yo) %}
2017-03-06 16:35:30 +00:00
2019-05-02 13:58:39 +00:00
Comparable -> ( AS | NonNumericTerminal) {% d => d[0][0] %}
NonNumericTerminal ->
Boolean {% id %}
| String {% id %}
| NegatedVariable {% id %}
2017-03-06 16:35:30 +00:00
2017-09-07 21:26:31 +00:00
ComparisonOperator -> ">" | "<" | ">=" | "<=" | "=" | "!="
2017-03-06 16:35:30 +00:00
2017-05-09 13:39:42 +00:00
NegatedVariable -> "≠" _ Variable {% d => ({category: 'negatedVariable', variable: d[2] }) %}
2018-10-01 15:41:55 +00:00
FilteredVariable -> Variable _ Filter {% d => ({category: 'variable', filter: d[2], variable: d[0] }) %}
2017-06-22 16:03:12 +00:00
2018-06-27 16:40:59 +00:00
Filter -> "(" VariableFragment ")" {% d =>d[1] %}
2017-06-22 16:03:12 +00:00
2018-11-13 15:14:57 +00:00
TemporalVariable -> Variable _ TemporalTransform {% d => ({...d[0], temporalTransform: d[2] }) %}
2017-03-06 16:35:30 +00:00
2018-11-13 15:14:57 +00:00
TemporalTransform -> "[" Temporalities "]" {% d =>d[1] %}
2017-03-06 16:35:30 +00:00
2018-11-13 15:14:57 +00:00
Temporalities -> "annuel" | "mensuel" {% id %}
2017-05-09 13:39:42 +00:00
#-----
2017-03-06 16:35:30 +00:00
2019-05-02 13:58:39 +00:00
# Addition and subtraction
AS -> AS _ ASOperator _ MD {% d => ({
2017-03-08 16:49:22 +00:00
category: 'calcExpression',
2017-03-08 16:47:12 +00:00
operator: d[2],
explanation: [d[0], d[4]],
type: 'numeric'
}) %}
2017-03-06 16:35:30 +00:00
2019-05-02 13:58:39 +00:00
| MD {% id %}
2017-03-06 16:35:30 +00:00
2019-05-02 13:58:39 +00:00
ASOperator -> "+" {% id %}
2017-03-07 17:25:25 +00:00
| "-" {% id %}
2017-03-06 16:35:30 +00:00
2019-05-02 13:58:39 +00:00
MDOperator -> "*" {% id %}
| "/" {% id %}
2017-03-06 16:35:30 +00:00
2019-05-02 13:58:39 +00:00
# Multiplication and division
MD -> MD _ MDOperator _ P {% d => ({
category: 'calcExpression',
operator: d[2],
explanation: [d[0], d[4]],
type: 'numeric'
}) %}
| P {% id %}
2017-03-06 16:35:30 +00:00
2019-05-02 13:58:39 +00:00
Term -> Variable {% id %}
| FilteredVariable {% id %}
| number {% id %}
| percentage {% id %}
2017-03-06 16:35:30 +00:00
2019-05-02 14:24:22 +00:00
Variable -> VariableFragment (_ Dot _ VariableFragment {% [,,,fragment] => fragment %}):*
{% ([firstFragment, nextFragments]) => treatVariableTransforms({
fragments: [firstFragment, ...nextFragments],
2017-03-08 16:47:12 +00:00
}) %}
2017-03-06 16:35:30 +00:00
2019-05-02 13:58:39 +00:00
String -> "'" [ .'a-zA-Z\-\u00C0-\u017F ]:+ "'" {% d => ({
2017-09-07 14:52:14 +00:00
category: 'value',
type: 'string',
nodeValue: d[1].join('')
}) %}
2017-03-06 16:35:30 +00:00
2017-03-08 16:47:12 +00:00
VariableFragment -> VariableWord (_ VariableWord {% d=> ' ' + d[1] %}):* {% d => d[0] + d[1].join('') %}
2017-03-06 16:35:30 +00:00
2019-02-18 18:31:00 +00:00
VariableWord -> [a-zA-Z\u00C0-\u017F] [\-'a-zA-Z\u00C0-\u017F]:* {% d => d[0] + d[1].join('') %}
2017-03-06 16:35:30 +00:00
2017-03-07 17:25:25 +00:00
Dot -> [\.] {% d => null %}
2017-03-06 16:35:30 +00:00
2017-03-07 17:25:25 +00:00
_ -> [\s] {% d => null %}
2017-03-06 16:35:30 +00:00
2017-09-19 11:17:43 +00:00
number -> [0-9]:+ ([\.] [0-9]:+):? {% d => ({category: 'value', nodeValue: parseFloat(d[0].join("")+(d[1]?(d[1][0]+d[1][1].join("")):""))}) %}
2019-05-02 14:24:22 +00:00
percentage -> [0-9]:+ ([\.] [0-9]:+):? [\%] {% d => percentage(d)%}
2018-08-07 18:46:26 +00:00
Boolean -> "oui" {% d=> ({category: 'boolean', nodeValue: true}) %}
| "non" {% d=> ({category: 'boolean', nodeValue: false}) %}
2019-05-02 13:58:39 +00:00