Last active
August 29, 2015 14:02
-
-
Save kl0tl/879218efd6c55585c069 to your computer and use it in GitHub Desktop.
Parens free `if` statement
This file contains 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
/* | |
`if cond {}` | |
Brackets are mandatory, except when `if` is followed by specials keywords (return, break and continue) | |
``` | |
if cond return | |
if cond break [label] | |
if cond continue [label] | |
``` | |
*/ | |
let if = macro { | |
rule { $cond:expr { $body ... } } => { | |
if ($cond) { $body ... } | |
} | |
rule { $cond:expr ; } => { | |
if ($cond); | |
} | |
rule { $cond:expr return $return:expr } => { | |
if ($cond) return $return | |
} | |
rule { $cond:expr return } => { | |
if ($cond) return | |
} | |
rule { $cond:expr continue $label:ident } => { | |
if ($cond) continue $label | |
} | |
rule { $cond:expr continue } => { | |
if ($cond) continue | |
} | |
rule { $cond:expr break $label:ident } => { | |
if ($cond) break $label | |
} | |
rule { $cond:expr break } => { | |
if ($cond) break | |
} | |
rule { $cond:expr do $body } => { | |
if ($cond) do $body | |
} | |
} | |
export if; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment