Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
First Attempt at SweetJS macro development.
macro makeString {
case { _ $tok } => {
return [makeValue(#{$tok}[0].token.value, #{here})]
}
}
macro qw {
rule { ($delimited ...) } => { [$(makeString $delimited) (,) ...] }
}
macro %w {
rule { ($delimited ...) } => { [$(makeString $delimited) (,) ...] }
}
%w(ruby like %w syntax);
qw(perl like qw function);
// thanks to: andreypopp in #sweet.js on freenode -- he made this happen.
// http://sweetjs.org/browser/editor.html#macro%20makeString%20%7B%0A%20%20case%20%7B%20_%20$tok%20%7D%20=%3E%20%7B%0A%09return%20%5BmakeValue(#%7B$tok%7D%5B0%5D.token.value,%20#%7Bhere%7D)%5D%0A%20%20%7D%0A%7D%0A%0Amacro%20qw%20%7B%0A%20%20rule%20%7B%20($delimited%20...)%20%7D%20=%3E%20%7B%20%5B$(makeString%20$delimited)%20(,)%20...%5D%20%7D%0A%7D%0A%0Amacro%20%25w%20%7B%0A%20%20rule%20%7B%20($delimited%20...)%20%7D%20=%3E%20%7B%20%5B$(makeString%20$delimited)%20(,)%20...%5D%20%7D%0A%7D%0A%0A%25w(ruby%20like%20%25w%20syntax);%0A%0Aqw(perl%20like%20qw%20function);%0A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.