Skip to content

Instantly share code, notes, and snippets.

@cmcculloh
Created September 24, 2013 19:22
Show Gist options
  • Select an option

  • Save cmcculloh/6689909 to your computer and use it in GitHub Desktop.

Select an option

Save cmcculloh/6689909 to your computer and use it in GitHub Desktop.
JS to CS translation utilities
#take an object definition and translate it's member function wrappers into coffee script
#
#eg:
# {
# blah: function(whatevs){
# var buncha = 'stuff here';
# }
# }
#
#becomes:
# {
# blah = (whatevs) ->
# var buncha = 'stuff here';
# }
#
([a-zA-Z0-9\_]+)\:\ ?function\ ?[a-zA-Z0-9\_]*\(([a-zA-Z0-9\,\ \_]*)\)\{([\w\W]+?)\}{1}(?!\))\,?
#rewrite var decs in a CS manner
#rewrite boilerplate for loops in CS
#eg:
#for (var i = 0; i < list.length; i++) {
# var buf = list[i];
# length += buf.length;
#}
#becomes:
# for i in list
# var buf = list[i];
# length += buf.length
#
for\ ?\(var\ ([a-zA-Z0-9\_]+)\ ?\=\ ?[0-9]+\;\ ?[a-zA-Z0-9\_\.]+\ ?\<\ ?([a-zA-Z0-9\.\_]+)\.length\;\ ?[a-zA-Z0-9\_\.]+\+\+\)\ {([\w\W])+\}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment