Last active
August 29, 2015 14:02
-
-
Save kl0tl/26aa760c3b4f1b629c5a to your computer and use it in GitHub Desktop.
Coffeescript like `do` expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Immediately invoke a block with scopped variables | |
| ``` | |
| do (foo = 'bar') { | |
| ... | |
| } | |
| ``` | |
| The block can be optionally named | |
| */ | |
| let do = macro { | |
| rule { () => $body:expr } => { | |
| (function () { return $body }()) | |
| } | |
| rule { ($($symbol:ident = $value:expr) (,) ...) => $body:expr } => { | |
| (function ($symbol (,) ...) { return $body }($value (,) ...)) | |
| } | |
| rule { () $body } => { | |
| (function () $body ()) | |
| } | |
| rule { $name:ident () $body } => { | |
| (function $name() $body ()) | |
| } | |
| rule { ($($symbol:ident = $value:expr) (,) ...) $body } => { | |
| (function ($symbol (,) ...) $body ($value (,) ...)) | |
| } | |
| rule { $name:ident ($($symbol:ident = $value:expr) (,) ...) $body } => { | |
| (function $name($symbol (,) ...) $body ($value (,) ...)) | |
| } | |
| rule { $body } => { do $body } | |
| } | |
| export do; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment