Skip to content

Instantly share code, notes, and snippets.

@geelen
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geelen/9868228 to your computer and use it in GitHub Desktop.
Save geelen/9868228 to your computer and use it in GitHub Desktop.
react sweetjs early steps
macro _string {
case { _ $x } => {
var stx = #{$x};
var val = stx[0].token.value;
return [makeValue(val, #{_})];
}
}
macro foo {
rule { $x } => {
_string $x
}
}
foo bar; // -> 'bar'
macro H1 {
rule { #$id } => {
React.DOM.h1({id: $id})
}
rule { .$classes (.) ... } => {
React.DOM.h1({className: [_string $classes (,) ...].join(' ') })
}
rule {} => {
React.DOM.h1
}
}
H1();
H1.single_class_ok;
H1.one.two.three;
H1#id;
H1.'this'.'works'.'though';
H1#'this';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment