diff --git a/source/engine/grammar.ne b/source/engine/grammar.ne index 7ac080ac9..385480366 100644 --- a/source/engine/grammar.ne +++ b/source/engine/grammar.ne @@ -6,10 +6,11 @@ # @preprocessor esmodule @{% -const {string, filteredVariable, variable, temporalVariable, binaryOperation, unaryOperation, boolean, number, numberWithUnit, percentage } = require('./grammarFunctions') +const {string, filteredVariable, date, variable, temporalVariable, binaryOperation, unaryOperation, boolean, number, numberWithUnit, percentage } = require('./grammarFunctions') const moo = require("moo"); +const dateRegexp = /(?:0?[1-9]|[12][0-9]|3[01])\/(?:0?[1-9]|1[012])\/\d{4}/ const letter = '[a-zA-Z\u00C0-\u017F]'; const letterOrNumber = '[a-zA-Z\u00C0-\u017F0-9\']'; const word = `${letter}(?:[\-']?${letterOrNumber}+)*`; @@ -18,6 +19,7 @@ const words = `${word}(?:[\\s]?${wordOrNumber}+)*` const numberRegExp = '-?(?:[1-9][0-9]+|[0-9])(?:\\.[0-9]+)?'; const percentageRegExp = numberRegExp + '\\%' const lexer = moo.compile({ + date: dateRegexp, percentage: new RegExp(percentageRegExp), '(': '(', ')': ')', @@ -46,6 +48,7 @@ main -> | Comparison {% id %} | NonNumericTerminal {% id %} | Negation {% id %} + | %date {% date %} NumericTerminal -> Variable {% id %} diff --git a/source/engine/grammarFunctions.js b/source/engine/grammarFunctions.js index ba9504118..ed3d53266 100644 --- a/source/engine/grammarFunctions.js +++ b/source/engine/grammarFunctions.js @@ -62,6 +62,13 @@ export let percentage = ([{ value }]) => ({ } }) +export let date = ([{ value }]) => ({ + constant: { + type: 'date', + nodeValue: value + } +}) + export let boolean = nodeValue => () => ({ constant: { type: 'boolean', diff --git a/test/mécanismes/date.yaml b/test/mécanismes/date.yaml new file mode 100644 index 000000000..f18b732ad --- /dev/null +++ b/test/mécanismes/date.yaml @@ -0,0 +1,5 @@ +- test: Dates + formule: 01/01/2015 + exemples: + - nom: Parse correctement les dates + valeur attendue: 01/01/2015