Open jdunkerley opened 3 days ago
My idea would be to introduce another precedence level in parser. I don't think this involves any part of engine beside parser (please correct me if I'm wrong). Now, we hierarchical precedence discovery - first level is "spaced" and "non-spaced". Then in these groups we apply precedences of operators. We could add another group to the top level, so we will have "spaced", "non-spaced", "math" and then just resolve precedences in these groups. Just my idea, might not be the best one, but I shared it because maybe it will be useful to someone :)
Expression | Interpretation (current) | Interpretation (Solution 1) | Interpretation (Solution 2) |
---|---|---|---|
`a * b+c . floor` | `a * ((b + c) . floor)` | `((a * b) + c) . floor`[^1] | |
`a * b+c.floor` | `a * (b + (c . floor))` | `((a * b) + (c . floor))`[^1] | |
`x+y * z` | `(x + y) * z` | `x + (y * z)`[^1] | |
`f x+y * z` | `(f (x + y)) * z` | `f (x + (y * z))`[^1] | *unchanged* |
`f x + y` | `(f x) + y` | `f (x + y)`[^2] | *unchanged* |
`f +y` | `f (+y)` | *unchanged* | |
`f x +y` | `((f x) (+y))` | *unchanged* |
[^1]: In this case a warning may be emitted that spacing is inconsistent with effective precedence. [^2]: The interpretation of this expression has changed, but no warning is emitted. This may take some getting used to for library developers.
Maintain the uniform application of space-precedence rules, but warn if the result is inconsistent with mathematical precedence.
Place math operators in a precedence level between unspaced non-math and spaced non-math.
Current logic:
New logic:
X (F X)+
(regex notation), where X
is a non-operator term and F
is a binary mathematical operator.Redefine the effect of spacing in terms of precedence-modification.
Current logic (after refactoring):
New logic:
parse_all_enso_files.sh
can be used to detect expressions whose interpretation have been changed. If there are few they could be updated by hand; if there are many, I could add refactoring suggestions to the warnings, and create a tool that can apply them (2 points).
Want to evaluate the complexity of making it so whitespace not affect the precedence of mathematical operators (arithmetic, bitwise and logical ops).
We would keep the space precedence for the other operators like
.
and->
.a + b>4 . floor
==((a+b)>4).floor
NOT(a+(b>4)).floor
a-> b-> a+b
Goal is to understand how hard to change on the engine/parser side and how hard to update all the library code needed.