catala
catala copied to clipboard
Impossible to write tuple (0,0)
Writing this tuple currently yields the error:
┌─[ERROR (2/2)]─
│
│ Syntax error at "0":
│ » expected binary operator
│ Those are valid at this point: ".", ">", "=", ")", "+", "-", "*", "/", "++", "!=", ">=", "<=", "jour", "mois", "an", "mais en remplaçant", "ou bien", "ou", "et",
│ "pour", "sous forme", "contient", "de"
│
├─➤ src/1-filtrage.catala_fr:353.17-353.18:
│ │
│ 353 │ puis (0, 0)
│ │ ‾
│
│ Maybe you wanted to write: ".", ">", "=", ")", "+", "-", "*" or "/"?
I can get around by let binding 0 to a variable but not very elegant.
You can work around it by writing (0 , 0), otherwise yes, the first element is parsed as the decimal 0.0
Possible solutions:
- require the space above, although that's ugly
- require decimals to have at least a digit after the decimal separator. Not sure it's a good solution here, but that might be a good idea for the readability of the code anyways (e.g. always require the user to write
12,0rather than12,for the decimal twelve -- that's what I prefer to do in examples anyway). It remains fragile because(12,0)and(12, 0)then are valid syntax for completely different things (a decimal singleton a pair of integers, respectively) - change the separator in tuples to
;, making them closer in appearance to lists, but avoiding the clash with the french decimal separator
I would be in favor of keeping the current behavior as is but throwing out a warning in the parser if it detects in the French language an instance of LEFTPARENT NUMBER COMMA NUMBER RIGHTPAREN suggesting the user that they're mistaking the tuple for the decimal and showing the workarounds mentionned aboved. Do you think it's doable @AltGr?
The warning should be output from here: https://github.com/CatalaLang/catala/blob/master/compiler/surface/parser.mly#L191