2019-05-02 14:24:22 +00:00
# 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
2019-05-14 17:40:47 +00:00
P -> "(" _ AS _ ")" {% ([,,e]) => e %}
2019-05-02 13:58:39 +00:00
| NumericTerminal {% id %}
2019-05-14 17:40:47 +00:00
ComparisonOperator -> ">" | "<" | ">=" | "<=" | "=" | "!="
2017-03-06 16:35:30 +00:00
2019-05-14 17:40:47 +00:00
Comparison -> Comparable _ ComparisonOperator _ Comparable {% ([A, , operator, , B]) => ({
[operator]:
[A, B]
}) %}
2017-03-06 16:35:30 +00:00
2019-05-14 17:40:47 +00:00
Comparable -> ( AS | NonNumericTerminal) {% ([[e]]) => e %}
2019-05-02 13:58:39 +00:00
NonNumericTerminal ->
Boolean {% id %}
| String {% id %}
| NegatedVariable {% id %}
2017-03-06 16:35:30 +00:00
2019-05-14 17:40:47 +00:00
NegatedVariable -> "≠" _ Variable {% ([,,variable]) => ({'≠': variable }) %}
2017-05-09 13:39:42 +00:00
2019-05-14 17:40:47 +00:00
FilteredVariable -> Variable _ Filter {% ([variable,,filtre]) => ({filtre: {filtre, variable}}) %}
2017-06-22 16:03:12 +00:00
2019-05-14 17:40:47 +00:00
Filter -> "(" VariableFragment ")" {% ([,filtre]) =>filtre %}
2017-06-22 16:03:12 +00:00
2019-05-14 17:40:47 +00:00
TemporalVariable -> Variable _ TemporalTransform {% ([variable,,chemin]) => ({'conversion temporelle': {variable, chemin}}) %}
2017-03-06 16:35:30 +00:00
2019-05-14 17:40:47 +00:00
TemporalTransform -> "[" Temporality "]" {% d =>d[1] %}
2017-03-06 16:35:30 +00:00
2019-05-14 17:40:47 +00:00
Temporality -> "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
2019-05-14 17:40:47 +00:00
AS -> AS _ ASOperator _ MD {% ([A, , operator, , B]) => ({
[operator]:
[A, B]
2017-03-08 16:47:12 +00:00
}) %}
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
2019-05-14 17:40:47 +00:00
MD -> MD _ MDOperator _ P {%
([A, , operator, , B]) => ({
[operator]:
[A, B]
2019-05-02 13:58:39 +00:00
}) %}
| 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-14 17:40:47 +00:00
Variable -> VariableFragment (_ Dot _ VariableFragment {% ([,,,fragment]) => fragment %}):*
{% ([firstFragment, nextFragments]) =>
({variable: {
category: 'variable',
2019-05-02 14:24:22 +00:00
fragments: [firstFragment, ...nextFragments],
2019-05-14 17:40:47 +00:00
}}) %}
2017-03-06 16:35:30 +00:00
2019-05-14 17:40:47 +00:00
String -> "'" [ .'a-zA-Z\-\u00C0-\u017F ]:+ "'" {% d => ({constante: {
2017-09-07 14:52:14 +00:00
type: 'string',
nodeValue: d[1].join('')
2019-05-14 17:40:47 +00:00
}}) %}
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
2019-05-14 17:40:47 +00:00
number -> [0-9]:+ ([\.] [0-9]:+):? {% d => ({constante:{ nodeValue: parseFloat(d[0].join("")+(d[1]?(d[1][0]+d[1][1].join("")):""))}}) %}
percentage -> [0-9]:+ ([\.] [0-9]:+):? [\%] {% d => ({ 'percentage':{ nodeValue: parseFloat(d[0].join("")+(d[1]?(d[1][0]+d[1][1].join("")):""))/100}}) %}
2017-09-19 11:17:43 +00:00
2018-08-07 18:46:26 +00:00
2019-05-14 17:40:47 +00:00
Boolean -> ("oui"
| "non" ) {% ([val])=> ({constante:{type: 'boolean', nodeValue: {'oui': true, 'non': false}[val]}}) %}
2019-05-02 13:58:39 +00:00