Skip to content

Instantly share code, notes, and snippets.

@nsmaciej
Created February 27, 2014 23:53
Show Gist options
  • Save nsmaciej/9262303 to your computer and use it in GitHub Desktop.
Save nsmaciej/9262303 to your computer and use it in GitHub Desktop.
Messing around with sweet.js (sweetjs.org)
macro $ttos {
case {_ $x} => {
var pattern = #{$x};
var tokenString = pattern[0].token.value.toString();
var stringValue = makeValue(tokenString, #{$here});
return withSyntax($val = [stringValue]) {
return #{$val};
}
}
}
macro < {
rule { $sel $($attr=$val) (,) ... > } => {
"<"+($ttos $sel)+" "+$(($ttos $attr)+"="+($ttos $val))...+">"
}
}
console.log(<a href='/'>);
@AndersDJohnson
Copy link

Any way to make this repeating and/or recursive? Multi-line?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment