Skip to content

Instantly share code, notes, and snippets.

@scribu
Created August 6, 2011 22:02
Show Gist options
  • Save scribu/1129798 to your computer and use it in GitHub Desktop.
Save scribu/1129798 to your computer and use it in GitHub Desktop.
Javascript To Coco
# remove useless punctuation
s/;$//g
s/,$//g
# comments start with #
s:// :# :g
# var is out
s/var //g
/var$/d
# function definitions
s/function *(\(.*\)) {/(\1) ->/g
s/() ->/->/g
# if statements
s/if ( \(.*\) ) {/if \1/g
s/if ( \(.*\) )/if \1/g
/}$/d
# object literals don't even need brackets
s/, {$/,/g
s/({$/(/g
s/})$/)/g
# instance properties
s/this\./@/g
s/self\./@/g
@scribu
Copy link
Author

scribu commented Aug 6, 2011

This script can be used to convert regular Javascript into Coco.

Usage example:

sed --file=coco.sed script.js > script.co

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