2019-06-04 14:01:21 +00:00
|
|
|
# This grammar is inspired by the "fancier grammar" tab of the nearley playground : https://omrelli.ug/nearley-playground
|
|
|
|
|
2019-09-05 13:48:22 +00:00
|
|
|
# Look for the PEMDAS system : Parentheses, Exponents (omitted here), Multiplication, and you should guess the rest :)
|
2019-06-04 14:01:21 +00:00
|
|
|
|
2019-05-16 13:58:30 +00:00
|
|
|
@preprocessor esmodule
|
|
|
|
|
2019-09-05 13:48:22 +00:00
|
|
|
@{%
|
2019-05-16 13:58:30 +00:00
|
|
|
import {string, filteredVariable, variable, temporalVariable, operation, boolean, number, percentage } from './grammarFunctions'
|
|
|
|
%}
|
|
|
|
|
2017-03-07 17:25:25 +00:00
|
|
|
main ->
|
2019-06-04 14:01:21 +00:00
|
|
|
AdditionSubstraction {% id %}
|
2019-05-02 13:58:39 +00:00
|
|
|
| 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 %}
|
|
|
|
|
2019-06-04 14:01:21 +00:00
|
|
|
Parentheses -> "(" AdditionSubstraction ")" {% ([,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-16 13:58:30 +00:00
|
|
|
Comparison -> Comparable _ ComparisonOperator _ Comparable {% operation('comparison')%}
|
2017-03-06 16:35:30 +00:00
|
|
|
|
2019-06-04 14:01:21 +00:00
|
|
|
Comparable -> ( AdditionSubstraction | NonNumericTerminal) {% ([[e]]) => e %}
|
2019-05-02 13:58:39 +00:00
|
|
|
|
2019-09-05 13:48:22 +00:00
|
|
|
NonNumericTerminal ->
|
|
|
|
Boolean {% id %}
|
2019-05-02 13:58:39 +00:00
|
|
|
| String {% id %}
|
|
|
|
|
2017-03-06 16:35:30 +00:00
|
|
|
|
2019-05-16 13:58:30 +00:00
|
|
|
FilteredVariable -> Variable _ Filter {% filteredVariable %}
|
2017-06-22 16:03:12 +00:00
|
|
|
|
2019-05-15 13:43:56 +00:00
|
|
|
Filter -> "[" VariableFragment "]" {% ([,filter]) => filter %}
|
2017-06-22 16:03:12 +00:00
|
|
|
|
2019-05-16 13:58:30 +00:00
|
|
|
TemporalVariable -> Variable _ TemporalTransform {% temporalVariable %}
|
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-06-04 14:01:21 +00:00
|
|
|
AdditionSubstraction -> AdditionSubstraction _ AdditionSubstractionOperator _ MultiplicationDivision {% operation('calculation') %}
|
|
|
|
| MultiplicationDivision {% id %}
|
2017-03-06 16:35:30 +00:00
|
|
|
|
2019-09-05 13:48:22 +00:00
|
|
|
|
2019-06-04 14:01:21 +00:00
|
|
|
AdditionSubstractionOperator -> "+" {% id %}
|
2017-03-07 17:25:25 +00:00
|
|
|
| "-" {% id %}
|
2017-03-06 16:35:30 +00:00
|
|
|
|
2019-06-04 14:01:21 +00:00
|
|
|
MultiplicationDivisionOperator -> "*" {% id %}
|
2019-05-02 13:58:39 +00:00
|
|
|
| "/" {% id %}
|
2017-03-06 16:35:30 +00:00
|
|
|
|
2019-05-02 13:58:39 +00:00
|
|
|
# Multiplication and division
|
2019-06-04 14:01:21 +00:00
|
|
|
MultiplicationDivision -> MultiplicationDivision _ MultiplicationDivisionOperator _ Parentheses {% operation('calculation') %}
|
2019-05-15 08:52:20 +00:00
|
|
|
| Parentheses {% id %}
|
2017-03-06 16:35:30 +00:00
|
|
|
|
2019-09-05 13:48:22 +00:00
|
|
|
Variable -> VariableFragment (_ Dot _ VariableFragment {% ([,,,fragment]) => fragment %}):*
|
2019-05-16 13:58:30 +00:00
|
|
|
{% variable %}
|
|
|
|
|
2019-09-05 13:48:22 +00:00
|
|
|
String -> "'" [ .'a-zA-Z\-\u00C0-\u017F0-9 ]:+ "'" {% string %}
|
2017-03-06 16:35:30 +00:00
|
|
|
|
2019-09-05 13:48:22 +00:00
|
|
|
VariableFragment -> VariableWordWithoutNumber (_ VariableWord {% d=> ' ' + d[1] %}):* {% d => d[0] + d[1].join('') %}
|
2017-03-06 16:35:30 +00:00
|
|
|
|
2019-09-05 13:48:22 +00:00
|
|
|
VariableWordWithoutNumber -> [a-zA-Z\u00C0-\u017F] [\-'a-zA-Z\u00C0-\u017F]:* {% d => d[0] + d[1].join('') %}
|
|
|
|
VariableWord -> [a-zA-Z\u00C0-\u017F0-9] [\-'a-zA-Z\u00C0-\u017F0-9]:* {% 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-16 13:58:30 +00:00
|
|
|
number -> [0-9]:+ ([\.] [0-9]:+):? {% number %}
|
2017-09-19 11:17:43 +00:00
|
|
|
|
2019-05-16 13:58:30 +00:00
|
|
|
percentage -> [0-9]:+ ([\.] [0-9]:+):? [\%] {% percentage %}
|
2018-08-07 18:46:26 +00:00
|
|
|
|
2019-05-16 13:58:30 +00:00
|
|
|
Boolean -> (
|
|
|
|
"oui"
|
|
|
|
| "non" ) {% boolean %}
|