Skip to content

Instantly share code, notes, and snippets.

@batiste
Last active August 29, 2015 14:08
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 batiste/dd8494e61203952f22d8 to your computer and use it in GitHub Desktop.
Save batiste/dd8494e61203952f22d8 to your computer and use it in GitHub Desktop.
A proposition for some simple syntactic sugar that compiles to Javascript
Goal:
1. Not reinventing JavaScript. Minimalistic sugar.
2. Aleviate the verbosness of the language especially with function definition, semicolon, and the var keyword
3. Avoid CoffeScript error http://lucumr.pocoo.org/2011/12/22/implicit-scoping-in-coffeescript/
Features? Implicit return?
Implementation? PEG.js http://pegjs.majda.cz/online
> means sugar in
< means Js out
> list = [1, 2, 3, 4, 5]
< var list = [1, 2, 3, 4, 5];
>
for key, value in list
console.log(key, value)
<
for (var key in list) {
if(!list.hasOwnProperty(key)){
continue;
}
var value = list[key];
console.log(key, value);
}
>
if 1 == 1
alert(1)
elseif 1 == 2
alert(2)
else
alert(3)
<
if(1 == 1) {
alert(1);
} else if (1 == 2) {
alert(2);
} else {
alert(3);
}
>
def myFunction(a, b, c)
alert(a, b, c)
variable = a
<
function myFunction(a, b, c) {
alert(a, b, c);
var variable = a;
}
>
fun = def() return 1 + 1
>
fun = def
return 1 + 1;
< all give this
var fun = function() {
return 1 + 1;
}
>
[1,2,3].map(def(x) return x * x)
<
[1,2,3].map(function(x) {
return x * x;
})
>
def f1()
a = 1
c = 5
def f2()
a = 2
c <- 4
<
function f1() {
var a = 1;
var c = 5;
function f2() {
var a = 2;
c = 4;
}
}
>
class Test(a)
def init(a)
this.a = a
obj = Test(1)
<
function Test(a) {
this.a = a;
}
obj = new Test(1);
>
str = "hello
world"
<
var str = "hello\
world";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment