Let's say you want to implement TypeScript with macros:
function foo(str: string) {
return str.toUpperCase()
// ^
// want to provide completion here
}
So we define the function
macro:
defaults write -app Skim SKAutoReloadFileUpdate -boolean true |
sed ' | |
s/^>// | |
t | |
s/^ *$// | |
t | |
s/^/-- / | |
' in.lhs > out.hs |
macro class { | |
case $className { constructor $constParam $constBody $rest ... } => { | |
function $className $constParam $constBody | |
class $className { $rest ... } | |
} | |
case $className { private_function $pMethodName $pMethodParam $pMethodBody $rest ...} => { | |
function $pMethodName $pMethodParam $pMethodBody | |
class $className { $rest ... } |
macro _match_cond { | |
case $o ($field) => { | |
(typeof $o.$field !== 'undefined') | |
} | |
case $o ($field $rest ...) => { | |
_match_cond $o ($field) && _match_cond $o ($rest ...) | |
} | |
} | |
macro _match_var { |
macro _arms { | |
case (default => $value:expr) => { | |
else { | |
return $value; | |
} | |
} | |
case (case $cond:expr => $value:expr) => { | |
if($cond) { | |
return $value; | |
} |
macro forThing { | |
case $val ($a:expr, $b:expr) => {(function($val){forEach.call($b, this)}).bind($a)} | |
case $val ($a:expr) => {(function($val){forEach.call(val,this)}).bind($a)} | |
} | |
function makeMutationObserver(tag){ | |
var queue= tag.queue, | |
put= queue.put.bind(queue), | |
mutationAddObserve= forThing val (put, val.getElementsByTagName(this.tag)), | |
mutationObserver= forThing val (mutationAddObserve, val.addedNodes), | |
mutationsObserver= forThing val (mutationObserver) |
Let's say you want to implement TypeScript with macros:
function foo(str: string) {
return str.toUpperCase()
// ^
// want to provide completion here
}
So we define the function
macro:
var random = function(seed) { /* ... */ } | |
let m = macro { | |
rule {()} => { | |
var n = random(42); // ... | |
} | |
} |
macro = { | |
rule { > { $body ... } } => { function foo() { $body ...} } | |
} | |
=> { return 42; } |
let let = macro { | |
rule { async $vars ... = $fname ... ($params ...); $rest ...} => { | |
$fname ... ($params ..., function (err, $vars ...) { | |
if (err) throw err; | |
$rest ... | |
}) | |
} | |
} | |
var buffer = new Buffer(1024); |