Arrow functions added.

This commit is contained in:
Onoshko Dan 2014-04-20 22:38:58 +07:00
parent 7bdb095cee
commit a8f26fdf33
3 changed files with 22 additions and 8 deletions

View File

@ -165,7 +165,7 @@ ColaScript is a language that compiles in JavaScript. This language is similar t
String str = r"\n \r"; // "\\n \\r"
- templating, status : done
- templating, status: done
String name = "dan";
@ -222,7 +222,7 @@ ColaScript is a language that compiles in JavaScript. This language is similar t
console.log('Hello World!');
}
- arrow functions
- arrow functions, status: done
print(str) => console.log(str);
@ -320,4 +320,4 @@ ColaScript is a language that compiles in JavaScript. This language is similar t
### Statistic
- 30 feature ( without classes )
- 15 done
- 18 done

View File

@ -139,8 +139,6 @@ main();</textarea>
} catch(e){
translationArea.value = '';
resultArea.value = '';
throw e;
}
}

View File

@ -705,6 +705,7 @@ Cola.Tokenizer.prototype.next_token = function (force_regexp) {
return this.token("punc", this.next());
}
if (!this.is_js && ch + this.peek(1) == '=>') return this.next(), this.next(), this.token("punc", "=>");
if (!this.is_js && ch == '@') return this.read_at();
if (Cola.OPERATOR_CHARS(ch)) return this.read_operator();
if (!this.is_js && ch == 'r' && (this.peek(1) == '"' || this.peek(1) == "'" || this.peek(1) == '`')) return this.next(), this.read_string(true);
@ -1010,7 +1011,7 @@ Cola.Parser.prototype.statement = Cola.Parser.embed_tokens(function() {
return balance == 0 || _this.is('eof');
});
isfun = (this.next(), this.is('punc','{'));
isfun = (this.next(), (this.is('punc','{') || this.is('punc','=>')));
}
this.restoreS();
@ -1238,7 +1239,22 @@ Cola.Parser.prototype.function_ = function(ctor, type) {
_this.S.in_directives = true;
_this.S.in_loop = 0;
_this.S.labels = [];
var a = _this.block_();
var tmp, a = !_this.is_js && _this.is("punc", "=>")
? (_this.next(), [new Cola.AST_Return({
start: new Cola.AST_Token({ nlb : false, type : 'keyword', value : 'return' }),
value: (function(){
tmp = _this.expression(true);
if ( ctor === Cola.AST_Defun ) {
_this.semicolon();
_this.next();
}
return tmp;
})(),
end : _this.prev()
})])
: _this.block_();
--_this.S.in_function;
_this.S.in_loop = loop;
_this.S.labels = labels;
@ -1504,7 +1520,7 @@ Cola.Parser.prototype.expr_atom = function(allow_calls) {
return balance == 0 || _this.is('eof');
});
isfun = (this.next(), this.is('punc','{'));
isfun = (this.next(), (this.is('punc','{') || this.is('punc','=>')));
this.restoreS();