enso/docs/parser/operator-resolution.md

1.8 KiB

layout title category tags order
developer-doc Operator Resolution parser
parser
operator
resolution
5

Operator Resolution

Operator resolution is the process of resolving applications of operators into specific nodes on the AST.

The actionables for this section are:

  • Work out how to ensure that precedence and associativity isn't broken by the macro resolution phase.
  • Work out how to handle the special case for ,. We don't want comma to be subject to the variable precedence functionality, as conventional spacing for defining lists goes [x, y, z] and that should be allowed without the variable precedence happening.
  • Work out how to handle the special case for -. The expression -n should be treated as an application of the unary operator negate, while - n should be treated as part of a larger expression (e.g. a section, subtraction).
  • As Enso has no syntactic marker for the introduction of a lambda, we need to have a special case for -> so that it has appropriate precedence on its left and right sides. Ideally, map.fold 0 $ y -> foo $ y is resolved as (map.fold 0) $ (y -> (foo $ y)). This makes writing code much more natural.

Resolution Algorithm

The operator resolution process uses a version of the classic shunting-yard algorithm with modifications to support operator sections.

The actionables for this section are:

  • Work out how to formulate this functionality efficiently in rust. The scala implementation can be found here.