Skip to content

Instantly share code, notes, and snippets.

@kl0tl
Last active August 29, 2015 14:02
Show Gist options
  • Save kl0tl/b26a6541d7f9e8c36945 to your computer and use it in GitHub Desktop.
Save kl0tl/b26a6541d7f9e8c36945 to your computer and use it in GitHub Desktop.
Cascade operator
/*
```
foo
..method()
..property = value
..method()
```
*/
macro function_arguments {
rule { ($arg:expr (,) ...) }
}
let . = macro {
rule infix { $expression:expr | . $symbol:ident $arguments:function_arguments } => {
(function (ref) {
return ref . $symbol $arguments , ref;
}($expression))
}
rule infix { $expression:expr | . $symbol:ident = $value } => {
(function (ref) {
return ref . $symbol = $value , ref;
}($expression))
}
rule { $rest ... } => { . $rest ... }
}
export .;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment