Last active
August 29, 2015 13:56
-
-
Save wilmoore/8811399 to your computer and use it in GitHub Desktop.
First Attempt at SweetJS macro development.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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