Skip to content

Instantly share code, notes, and snippets.

@SimonRichardson
Created September 17, 2013 09:43
Show Gist options
  • Select an option

  • Save SimonRichardson/6592225 to your computer and use it in GitHub Desktop.

Select an option

Save SimonRichardson/6592225 to your computer and use it in GitHub Desktop.
Create a string from a series of raw identifiers
macro $string {
case {_ ([$x $inner ...] $rest ...)} => {
var ctx = #{$x},
value = ctx[0].token.value,
str = makeValue(value, #{here});
return withSyntax($val = [str]) {
return #{'[' + $val + $string($inner ...) + ']' + $string($rest ...)}
}
}
case {_ ($x $rest ...) } => {
var ctx = #{$x},
value = ctx[0].token.value,
str = makeValue(value, #{here});
return withSyntax($val = [str]) {
return #{$val + $string($rest ...)}
}
}
case {_ ()} => {
return #{''};
}
}
@SimonRichardson
Copy link
Copy Markdown
Author

a.b.c[x + 1] becomes 'a.b.c[x + 1]'

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