However, isn't perfect. Indeed, when a rule name is a subset of an other rule name it causes trouble.
For example, the expression tasse de café * café substituting the rule café by its corresponding constant value it will produces the new invalid expression tasse de 42 * 42.
The solution
To avoid this errors, we need to be aware of the semantic of the expression: to parse the AST.
@laem already open a PR to expose the function parseExpression from the publicodes package.
The problem
Currently, the variable substitution is done via a regular expression:
https://github.com/incubateur-ademe/publiopti/blob/92dd9b2354b1b2b231ab7909ce23b85b61fcd935/source/constantFolding.ts#L131-L142
However, isn't perfect. Indeed, when a rule name is a subset of an other rule name it causes trouble.
For example, the expression
tasse de café * café
substituting the rulecafé
by its corresponding constant value it will produces the new invalid expressiontasse de 42 * 42
.The solution
To avoid this errors, we need to be aware of the semantic of the expression: to parse the AST.
@laem already open a PR to expose the function
parseExpression
from the publicodes package.