Merge: Callref syntax
authorJean Privat <jean@pryen.org>
Wed, 14 Aug 2019 15:22:26 +0000 (11:22 -0400)
committerJean Privat <jean@pryen.org>
Wed, 14 Aug 2019 15:22:26 +0000 (11:22 -0400)
commitf89c5e271b33d71c69b24a2325f6ee82212745b2
tree1ac948626bc52400829399b5c90100a154fe59c7
parent72681ae381a89d97b15c1cb7e2a32f411c7d525f
parente0676b69994c4b1c266cf79c80e8e7518eec3d41
Merge: Callref syntax

Note: I forgot to independently PR the syntax for callrefs (used by #2774), so here it is.

Introduce the `&` syntax to capture and reference calls.
This is used to provide a simple *function pointer* construction that will be used later to implement full lambdas. However, this is not expected to be used by lambda programmers :)

```nit
var ref = &recv.foo
```

Currently, the syntax is analogous to a simple call (recv.foo) with a prefix `&`.

On chains, only the last call is captured (`.` have a higer precedence than `&`)

```nit
var r = &foo.bar.baz
# is equivalent with
var x = foo.bar
var r = &x.baz
```

Since the syntax is analogous to a call (except the &), there is always a receiver (including the implicit self or sys) and arguments are accepted by the parser.

```nit
var r = &foo
# is equivalent with
var r = &self.foo
```

There is no clear syntax proposal to avoid the capture of a receiver since a receiver is statically expected to resolve the method name.

Pull-Request: #2775
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>