Tentative de déplacement de treatString dans grammar.ne
parent
ced2a37490
commit
a7d88e8514
|
@ -29,7 +29,7 @@
|
|||
"i18next": "^14.1.1",
|
||||
"iframe-resizer": "^3.6.2",
|
||||
"marked": "^0.3.17",
|
||||
"nearley": "^2.13.0",
|
||||
"nearley": "^2.16.0",
|
||||
"ramda": "^0.25.0",
|
||||
"raven-for-redux": "^1.3.1",
|
||||
"raven-js": "^3.26.4",
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
# Pour éditer ou comprendre ce fichier, utilisez l'éditeur web Nearley : https://omrelli.ug/nearley-playground/
|
||||
@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/
|
||||
|
||||
|
||||
main ->
|
||||
|
@ -18,12 +25,7 @@ P -> "(" _ AS _ ")" {% function(d) {return {category:'parentheses', explanation:
|
|||
| NumericTerminal {% id %}
|
||||
|
||||
|
||||
Comparison -> Comparable _ ComparisonOperator _ Comparable {% d => ({
|
||||
category: 'comparison',
|
||||
type: 'boolean',
|
||||
operator: d[2][0],
|
||||
explanation: [d[0], d[4]]
|
||||
}) %}
|
||||
Comparison -> Comparable _ ComparisonOperator _ Comparable {% yo => maSuperFonction(yo) %}
|
||||
|
||||
Comparable -> ( AS | NonNumericTerminal) {% d => d[0][0] %}
|
||||
|
||||
|
@ -81,10 +83,9 @@ Term -> Variable {% id %}
|
|||
| number {% id %}
|
||||
| percentage {% id %}
|
||||
|
||||
Variable -> VariableFragment (_ Dot _ VariableFragment {% d => d[3] %}):* {% d => ({
|
||||
category: 'variable',
|
||||
fragments: [d[0], ...d[1]],
|
||||
type: 'numeric | boolean'
|
||||
Variable -> VariableFragment (_ Dot _ VariableFragment {% [,,,fragment] => fragment %}):*
|
||||
{% ([firstFragment, nextFragments]) => treatVariableTransforms({
|
||||
fragments: [firstFragment, ...nextFragments],
|
||||
}) %}
|
||||
|
||||
String -> "'" [ .'a-zA-Z\-\u00C0-\u017F ]:+ "'" {% d => ({
|
||||
|
@ -105,7 +106,7 @@ _ -> [\s] {% d => null %}
|
|||
|
||||
number -> [0-9]:+ ([\.] [0-9]:+):? {% d => ({category: 'value', nodeValue: parseFloat(d[0].join("")+(d[1]?(d[1][0]+d[1][1].join("")):""))}) %}
|
||||
|
||||
percentage -> [0-9]:+ ([\.] [0-9]:+):? [\%] {% d => ({category: 'percentage', nodeValue: parseFloat(d[0].join("")+(d[1]?(d[1][0]+d[1][1].join("")):""))/100}) %}
|
||||
percentage -> [0-9]:+ ([\.] [0-9]:+):? [\%] {% d => percentage(d)%}
|
||||
|
||||
Boolean -> "oui" {% d=> ({category: 'boolean', nodeValue: true}) %}
|
||||
| "non" {% d=> ({category: 'boolean', nodeValue: false}) %}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
import React from 'react'
|
||||
|
||||
export let boolean = nodeValue => ({
|
||||
category: 'boolean',
|
||||
nodeValue: nodeValue,
|
||||
// eslint-disable-next-line
|
||||
jsx: () => <span className="boolean">{rawNode}</span>
|
||||
})
|
||||
|
||||
export let percentage = d => ({
|
||||
// We don't need to handle category == 'value' because YAML then returns it as
|
||||
// numerical value, not a String: it goes to treatNumber
|
||||
nodeValue:
|
||||
parseFloat(d[0].join('') + (d[1] ? d[1][0] + d[1][1].join('') : '')) / 100,
|
||||
category: 'percentage',
|
||||
// eslint-disable-next-line
|
||||
jsx: () => <span className="value">{rawNode.split('%')[0]} %</span>
|
||||
//on ajoute l'espace nécessaire en français avant le pourcentage
|
||||
})
|
|
@ -0,0 +1,6 @@
|
|||
export default d => ({
|
||||
category: 'comparison',
|
||||
type: 'boolean',
|
||||
operator: d[2][0],
|
||||
explanation: [d[0], d[4]]
|
||||
})
|
|
@ -78,21 +78,6 @@ export let treatString = (rules, rule) => rawNode => {
|
|||
)
|
||||
}
|
||||
|
||||
if (
|
||||
!contains(parseResult.category)([
|
||||
'variable',
|
||||
'calcExpression',
|
||||
'filteredVariable',
|
||||
'comparison',
|
||||
'negatedVariable',
|
||||
'percentage',
|
||||
'boolean'
|
||||
])
|
||||
)
|
||||
throw new Error(
|
||||
"Attention ! Erreur de traitement de l'expression : " + rawNode
|
||||
)
|
||||
|
||||
if (parseResult.category == 'variable')
|
||||
return treatVariableTransforms(rules, rule)(parseResult)
|
||||
if (parseResult.category == 'negatedVariable')
|
||||
|
@ -100,25 +85,6 @@ export let treatString = (rules, rule) => rawNode => {
|
|||
treatVariable(rules, rule)(parseResult.variable)
|
||||
)
|
||||
|
||||
if (parseResult.category == 'boolean') {
|
||||
return {
|
||||
nodeValue: parseResult.nodeValue,
|
||||
// eslint-disable-next-line
|
||||
jsx: () => <span className="boolean">{rawNode}</span>
|
||||
}
|
||||
}
|
||||
|
||||
// We don't need to handle category == 'value' because YAML then returns it as
|
||||
// numerical value, not a String: it goes to treatNumber
|
||||
if (parseResult.category == 'percentage')
|
||||
return {
|
||||
nodeValue: parseResult.nodeValue,
|
||||
category: 'percentage',
|
||||
// eslint-disable-next-line
|
||||
jsx: () => <span className="value">{rawNode.split('%')[0]} %</span>
|
||||
//on ajoute l'espace nécessaire en français avant le pourcentage
|
||||
}
|
||||
|
||||
if (
|
||||
parseResult.category == 'calcExpression' ||
|
||||
parseResult.category == 'comparison'
|
||||
|
@ -234,6 +200,7 @@ export let treatOther = rawNode => {
|
|||
'Cette donnée : ' + rawNode + ' doit être un Number, String ou Object'
|
||||
)
|
||||
}
|
||||
|
||||
export let treatObject = (rules, rule, treatOptions) => rawNode => {
|
||||
let mecanisms = intersection(keys(rawNode), keys(knownMecanisms))
|
||||
|
||||
|
|
|
@ -13,6 +13,11 @@
|
|||
exemples:
|
||||
- valeur attendue: 29.1
|
||||
|
||||
- test: addition de plusieurs nombres
|
||||
formule: 27 + 1.1 + 0.9
|
||||
exemples:
|
||||
- valeur attendue: 29
|
||||
|
||||
- nom: salaire de base
|
||||
- nom: contrat . salaire de base
|
||||
|
||||
|
|
|
@ -6186,7 +6186,7 @@ nearley-loader@^2.0.0:
|
|||
resolved "https://registry.yarnpkg.com/nearley-loader/-/nearley-loader-2.0.0.tgz#8d75fd2ab3ca9f6153ae099b2bf18f8d5605d203"
|
||||
integrity sha512-kkUlMrkLWMoQPlOVmv7a8aHFEiTOShPb1H+CkvJrDMYpMCqnQUpfJgViGFlh0wufMQlGcawPzebcng6KnDJEdg==
|
||||
|
||||
nearley@^2.13.0, nearley@^2.7.10:
|
||||
nearley@^2.16.0, nearley@^2.7.10:
|
||||
version "2.16.0"
|
||||
resolved "https://registry.yarnpkg.com/nearley/-/nearley-2.16.0.tgz#77c297d041941d268290ec84b739d0ee297e83a7"
|
||||
integrity sha512-Tr9XD3Vt/EujXbZBv6UAHYoLUSMQAxSsTnm9K3koXzjzNWY195NqALeyrzLZBKzAkL3gl92BcSogqrHjD8QuUg==
|
||||
|
|
Loading…
Reference in New Issue