2014-04-15 12:22:58 +00:00

2013-10-04 10:17:25 +00:00
2014-04-15 12:22:58 +00:00
ColaScript is a language that compiles in JavaScript. This language is similar to Dart, CoffeeScript, Python and PHP, with some original ideas. Compiler based on [UglifyJS2 ](https://github.com/mishoo/UglifyJS2 ). In present time compiler in development. Play with language you can in `lib/index.html` .
2013-10-04 10:17:25 +00:00
2014-04-15 12:22:58 +00:00
# to do:
2013-10-04 10:17:25 +00:00
2014-04-15 12:22:58 +00:00
- semicolon is always required, status: done
2013-10-04 10:17:25 +00:00
2014-04-15 12:22:58 +00:00
## Operators:
2013-10-04 10:17:25 +00:00
2014-04-15 12:22:58 +00:00
### Unary
2014-04-18 18:27:47 +00:00
- `varname??` and alternative `isset varname` - which is better? status: done
2013-10-04 10:17:25 +00:00
2014-04-18 18:27:47 +00:00
bool exist = SOME??;
bool exist2 = isset SOME;
2014-04-19 18:04:21 +00:00
2014-04-20 07:31:03 +00:00
- `clone` , status: done
2014-04-19 18:04:21 +00:00
a = [];
b = [];
Array b = clone a;
b[0] = 584; // a == []
2014-04-20 07:31:03 +00:00
if object have method `__clone__` , object will be copied with it.
2013-10-04 10:17:25 +00:00
2014-04-15 12:22:58 +00:00
### Binary
- `**` , status: done
2013-10-04 10:17:25 +00:00
2014-04-15 12:22:58 +00:00
int pow = 5 ** 2; // 25
- `%%` , status: done
2013-10-04 10:17:25 +00:00
2014-04-15 12:22:58 +00:00
int modulo = 5 %% 3; // 2
- `?=` , status: done
2013-10-04 10:17:25 +00:00
2014-04-15 12:22:58 +00:00
var undef, def = 5;
def ?= undef; // def == 5
undef = 6;
def ?= undef; // def == 6
2014-04-18 18:27:47 +00:00
- `a ? b` , status: done
2013-10-04 10:17:25 +00:00
2014-04-18 18:27:47 +00:00
var a = undefined, b = 3;
2014-04-15 12:22:58 +00:00
2014-04-18 18:27:47 +00:00
a ? b == 3;
2014-04-15 12:22:58 +00:00
a = 11;
2014-04-18 18:27:47 +00:00
a ? b == 1;
2014-04-15 12:22:58 +00:00
- `is` , status: done
bool isRegExp = /[^\d]+/g is RegExp; // true
- `isnt` , status: done
bool isntString = 3.14 isnt String; // true
### Multiple
- `..:`
Object profile = {
name : "dan",
nick : "dan",
friends : [
{ name : "eric", nick : "eric" }
],
"info" : "coder"
}
..name += "iil"
..nick += "green"
..friends[0]:
..name = profile.friends[0].name.capitalize()
..nick += "bro";
..info += ", student";
- `a > b > c`
if( 0 < x < 100 ) console . log ( " x E ( 0 ; 100 ) " ) ;
2014-04-15 12:31:15 +00:00
### Compiler
2014-04-15 12:22:58 +00:00
- `@require`
@require "./library/jquery.js", "./library/underscore.js"
- `@use`
@use strict, typing
@use asmjs
- `@if @end_if @else`
@if target == 'web'
@require './main.cola'
@else
@require './mobile/main.cola'
@end_if
2014-04-15 12:31:57 +00:00
## Expressions
2014-04-15 12:22:58 +00:00
- `switch` assigmention
String weather = switch(temperature){
case -10: 'cold';
case 20: 'normal';
case 35: 'hot';
};
2014-04-15 12:25:32 +00:00
- `with` scoping, status: it need??
2014-04-15 12:22:58 +00:00
2014-04-15 12:27:24 +00:00
with(document.body.querySelectorAll('ul').childNodes){
2014-04-15 12:22:58 +00:00
var txt = 'text';
forEach((li){
li.innerHTML = txt;
});
}
console.log(txt); // undefined
## Vars
2014-04-18 18:27:47 +00:00
- declaration with type, status: done, only declaration
2014-04-15 12:22:58 +00:00
int b = 584;
Array arr = [];
Object obj = {};
String str = "";
- multiple assigment
[a, b, c] = [b, c, a];
{poet: {String name, address: [street, city]}} = futurists;
[a, ..., b] = someArray;
### bool
- aliases, status: done
yes === on === true;
no === off === false;
### String
- \` new string \`, status: done
String name = `dangreen` ;
- multiline, status: done
String ml = "
Lorem ipsum,
Lorem ipsum.
";
- raw, status: done
String str = r"\n \r"; // "\\n \\r"
2014-04-20 15:38:58 +00:00
- templating, status: done
2014-04-15 12:22:58 +00:00
String name = "dan";
console.log("My name is @name ."); // My name is dan.
name = "eric";
console.log("My name is @name ."); // My name is eric.
console.log("My name is @{name.capitalize()} or {{name.capitalize()}}"); // My name is Eric.
### RegExp
- multiline ( and x flag ), status: done
RegExp re = /
([^\d]+)-
(\w+)
/gx;
### Arrays
2014-04-20 18:56:47 +00:00
- pushing and getting last, status: done
2014-04-15 12:22:58 +00:00
var arr = [3, 5, 6, 7];
arr[] = 4; // [3, 5, 6, 7, 4]
2014-04-20 18:56:47 +00:00
console.log(arr[]); // 4
2014-04-15 12:22:58 +00:00
2014-04-22 13:33:43 +00:00
- part assigment, status: done
2014-04-15 12:22:58 +00:00
arr[0..2] = [0,1]; // [0, 1, 7, 4]
2014-04-22 13:33:43 +00:00
arr[0..2] = []; // [7, 4]
- slice, status: done
arr = arr[0..2];
2014-04-15 12:22:58 +00:00
2014-04-22 13:33:43 +00:00
- inline array ranging, status: done
2014-04-15 12:22:58 +00:00
arr = [10..1]; // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
arr = [1..10]; // [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
### Functions
2014-04-19 18:04:21 +00:00
- without `function` keyword, status: done
2014-04-15 12:22:58 +00:00
void main(){
console.log('Hello World!');
}
2014-04-23 17:05:34 +00:00
- binding toplevel `main` functions to onload event, status: done
2014-04-15 12:22:58 +00:00
// lib.cola
main(){
console.log('Hello World from lib.cola!');
}
// main.cola
require "./lib.cola";
main(){
console.log('Hello World!');
}
2014-04-20 15:38:58 +00:00
- arrow functions, status: done
2014-04-15 12:22:58 +00:00
print(str) => console.log(str);
2014-04-27 20:30:25 +00:00
- named arguments, status: done
2014-04-15 12:22:58 +00:00
hello(String name:) => console.log("Hello @name !");
hello(name: 'dangreen'); // Hello dangreen!
hello(name: "World") => console.log("Hello @name !");
hello(); // Hello World!
2014-04-27 20:30:25 +00:00
- defaults for positional arguments, status: done
2014-04-15 12:22:58 +00:00
2014-04-27 20:30:25 +00:00
hello(String name = "World") => console.log("Hello @name !");
2014-04-15 12:22:58 +00:00
hello('dangreen'); // Hello dangreen!
hello(); // Hello World!
2014-04-27 20:30:25 +00:00
- some arguments into array, status: done
2014-04-15 12:22:58 +00:00
main(name, skills...){
console.log("My name is @name , my skills:");
skills.forEach((skill) => console.log("@skill,"));
}
## Classes
- classes
- singletones
- injectors
class A {
private int a = 123;
protected var o = {};
readonly String about = "class";
A(a){
about = "some else";
}
static Hello() => "hello!";
public String about() => about;
}
class B extends A {
B(){
parent();
about += "!";
}
B.anotherConstructor(){
about = "ups!";
}
get some => "some " + about;
set some(val) => about += val;
}
singleton S { // in fact this is object
int x = 45;
String s = "txt";
say(some){
alert(some);
}
int operator[](int index) => index + 584;
operator[]=(int index, int val) => x = index + val;
String operator.(String key) => key + "!";
operator.(String key, String value) => s = "@key @value ";
}
injector String {
String replaceAll(a, b){
String res = this;
while(res.indexOf(a) != -1) res = res.replace(a, b);
return res;
}
}
// or
String String::replaceAll(a, b){
String res = this;
while(res.indexOf(a) != -1) res = res.replace(a, b);
return res;
}
### Statistic
2014-04-22 13:33:43 +00:00
- 34 feature ( without classes )
2014-04-23 17:05:34 +00:00
- 23 done