:: prototype accessor done. npm published.

This commit is contained in:
Onoshko Dan 2014-05-23 17:14:16 +07:00
parent 00623e5e4c
commit 1382b1c8e9
7 changed files with 99 additions and 24 deletions

View File

@ -2,6 +2,26 @@
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 [here](http://develop.trigen.pro/cola/). 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 [here](http://develop.trigen.pro/cola/).
# Install
First make sure you have installed the latest version of [node.js](http://nodejs.org/)
(You may need to restart your computer after this step).
From NPM for use as a command line app:
npm install cola-script -g
From NPM for programmatic use:
npm install cola-script
From Git:
git clone git://github.com/TrigenSoftware/ColaScript.git
cd ColaScript
npm link .
# to do: # to do:
- semicolon is always required, status: done - semicolon is always required, status: done
@ -93,7 +113,7 @@ ColaScript is a language that compiles in JavaScript. This language is similar t
@include "./app/my.js" @include "./app/my.js"
- `@use` - `@use`, status: done
@use strict @use strict
@use asmjs @use asmjs
@ -311,4 +331,4 @@ ColaScript is a language that compiles in JavaScript. This language is similar t
### Statistic ### Statistic
- 33 features ( without classes ) - 33 features ( without classes )
- 30 done - 33 done

8
cola.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -687,6 +687,15 @@ Cola.AST_Dot = Cola.DEFNODE("Dot", null, {
} }
}, Cola.AST_PropAccess); }, Cola.AST_PropAccess);
Cola.AST_Proto = Cola.DEFNODE("Proto", null, {
$documentation: "Accessor to prototype",
_walk: function(visitor) {
return visitor._visit(this, function(){
this.expression._walk(visitor);
});
}
}, Cola.AST_PropAccess);
Cola.AST_Cascade = Cola.DEFNODE("Cascade", "expression subexpressions", { Cola.AST_Cascade = Cola.DEFNODE("Cascade", "expression subexpressions", {
$documentation: "Base class for properties access expressions, i.e. `a..foo..bar`", $documentation: "Base class for properties access expressions, i.e. `a..foo..bar`",
$propdoc: { $propdoc: {

View File

@ -2,8 +2,17 @@
<html> <html>
<head> <head>
<title>ColaScript Playground</title> <title>ColaScript Playground</title>
<script src="../cola.js"></script> <script src="./utils.js"></script>
<script src="../demo.cola" type="text/colascript"></script> <script src="./ast.js"></script>
<script src="./parse.js"></script>
<script src="./transform.js"></script>
<script src="./scope.js"></script>
<script src="./output.js"></script>
<script src="./compress.js"></script>
<script src="./sourcemap.js"></script>
<script src="./mozilla-ast.js"></script>
<script src="./translate.js"></script>
<script src="./std.js"></script>
<style> <style>
body { body {

View File

@ -146,6 +146,7 @@ Cola.COMPARISON = Cola.makePredicate("< > <= >= == === != !==");
Cola.WHITESPACE_CHARS = Cola.makePredicate(Cola.characters(" \u00a0\n\r\t\f\u000b\u200b\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000")); Cola.WHITESPACE_CHARS = Cola.makePredicate(Cola.characters(" \u00a0\n\r\t\f\u000b\u200b\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000"));
Cola.cPUNC_BEFORE_EXPRESSION = Cola.makePredicate(Cola.characters("[{(,.;:").concat(["::"]));
Cola.PUNC_BEFORE_EXPRESSION = Cola.makePredicate(Cola.characters("[{(,.;:")); Cola.PUNC_BEFORE_EXPRESSION = Cola.makePredicate(Cola.characters("[{(,.;:"));
Cola.PUNC_CHARS = Cola.makePredicate(Cola.characters("[]{}(),;:")); Cola.PUNC_CHARS = Cola.makePredicate(Cola.characters("[]{}(),;:"));
@ -274,12 +275,14 @@ Cola.Tokenizer = function ($TEXT, filename, is_js, html5_comments) {
this.OPERATORS = Cola.OPERATORS; this.OPERATORS = Cola.OPERATORS;
this.UNARY_POSTFIX = Cola.UNARY_POSTFIX; this.UNARY_POSTFIX = Cola.UNARY_POSTFIX;
this.KEYWORDS_BEFORE_EXPRESSION = Cola.KEYWORDS_BEFORE_EXPRESSION; this.KEYWORDS_BEFORE_EXPRESSION = Cola.KEYWORDS_BEFORE_EXPRESSION;
this.PUNC_BEFORE_EXPRESSION = Cola.PUNC_BEFORE_EXPRESSION;
} else { } else {
this.KEYWORDS = Cola.cKEYWORDS; this.KEYWORDS = Cola.cKEYWORDS;
this.KEYWORDS_ATOM = Cola.cKEYWORDS_ATOM; this.KEYWORDS_ATOM = Cola.cKEYWORDS_ATOM;
this.OPERATORS = Cola.cOPERATORS; this.OPERATORS = Cola.cOPERATORS;
this.UNARY_POSTFIX = Cola.cUNARY_POSTFIX; this.UNARY_POSTFIX = Cola.cUNARY_POSTFIX;
this.KEYWORDS_BEFORE_EXPRESSION = Cola.cKEYWORDS_BEFORE_EXPRESSION; this.KEYWORDS_BEFORE_EXPRESSION = Cola.cKEYWORDS_BEFORE_EXPRESSION;
this.PUNC_BEFORE_EXPRESSION = Cola.cPUNC_BEFORE_EXPRESSION;
} }
this.is_js = !!is_js; this.is_js = !!is_js;
@ -356,8 +359,8 @@ Cola.Tokenizer.prototype.start_token = function () {
Cola.Tokenizer.prototype.token = function (type, value, is_comment) { Cola.Tokenizer.prototype.token = function (type, value, is_comment) {
this.S.regex_allowed = ((type == "operator" && !this.UNARY_POSTFIX(value)) || this.S.regex_allowed = ((type == "operator" && !this.UNARY_POSTFIX(value)) ||
(type == "keyword" && this.KEYWORDS_BEFORE_EXPRESSION(value)) || (type == "keyword" && this.KEYWORDS_BEFORE_EXPRESSION(value)) ||
(type == "punc" && Cola.PUNC_BEFORE_EXPRESSION(value))); (type == "punc" && this.PUNC_BEFORE_EXPRESSION(value)));
this.prev_was_dot = (type == "punc" && value == "."); this.prev_was_dot = (type == "punc" && value == ".") || (!this.is_js && type == "punc" && value == "::");
var ret = { var ret = {
type : type, type : type,
value : value, value : value,
@ -704,6 +707,9 @@ Cola.Tokenizer.prototype.next_token = function (force_regexp) {
} }
if (Cola.is_digit(code)) return this.read_num(); if (Cola.is_digit(code)) return this.read_num();
if (Cola.PUNC_CHARS(ch)){ if (Cola.PUNC_CHARS(ch)){
if (!this.is_js && ch == ":" && this.peek(1) == ":") return this.next(), this.next(), this.token("punc", "::");
if (!this.is_js && this.S.string.at[this.S.string.level].inside && (this.S.string.at[this.S.string.level].inside_at || this.S.string.at[this.S.string.level].inside_braces)) { if (!this.is_js && this.S.string.at[this.S.string.level].inside && (this.S.string.at[this.S.string.level].inside_at || this.S.string.at[this.S.string.level].inside_braces)) {
if (ch == '{') this.S.string.at[this.S.string.level].balance++; if (ch == '{') this.S.string.at[this.S.string.level].balance++;
else if (ch == '}') this.S.string.at[this.S.string.level].balance--; else if (ch == '}') this.S.string.at[this.S.string.level].balance--;
@ -2004,6 +2010,15 @@ Cola.Parser.prototype.subscripts = function(expr, allow_calls) {
end : this.prev() end : this.prev()
}), allow_calls); }), allow_calls);
} }
if (this.is("punc", "::") && !this.is_js) {
this.next();
return this.subscripts(new Cola.AST_Proto({
start : start,
expression : expr,
property : this.as_name(),
end : this.prev()
}), allow_calls);
}
if (this.is("punc", "[")) { if (this.is("punc", "[")) {
this.next(); this.next();

View File

@ -1678,7 +1678,7 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
if(node instanceof Cola.AST_When){ if(node instanceof Cola.AST_When){
node = new Cola.AST_Case(node); node = new Cola.AST_Case(node);
node.body.push(new Cola.AST_Break); node.body.push(new Cola.AST_Break);
} } else
/* /*
switch (g) { switch (g) {
@ -1706,7 +1706,26 @@ Cola.AST_Toplevel.prototype.toJavaScript = function(options){
} }
node = branches; node = branches;
} } else
/*
MyClass::prop = (){
};
to
MyClass.prototype.prop = (){
};
*/
if(node instanceof Cola.AST_Proto){
props = new Cola.AST_Dot(node);
props.expression = new Cola.AST_Dot(node);
props.expression.property = "prototype";
node = props;
} else
/* /*
"test @a @{b} {{c}}" "test @a @{b} {{c}}"

View File

@ -1,30 +1,25 @@
{ {
"name": "uglify-js", "name": "cola-script",
"description": "JavaScript parser, mangler/compressor and beautifier toolkit", "description": "ColaScript translator / parser / mangler / compressor / beautifier toolkit",
"homepage": "http://lisperator.net/uglifyjs", "homepage": "https://github.com/TrigenSoftware/ColaScript",
"main": "tools/node.js", "main": "tools/node.js",
"version": "2.4.12", "version": "0.5.0",
"engines": { "node" : ">=0.4.0" }, "engines": { "node" : ">=0.4.0" },
"maintainers": [{ "maintainers": [{
"name": "Mihai Bazon", "name": "Dan Onoshko (dangreen)",
"email": "mihai.bazon@gmail.com", "email": "danpn0404@gmail.com",
"web": "http://lisperator.net/" "web": "http://trigen.pro/"
}], }],
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/mishoo/UglifyJS2.git" "url": "https://github.com/TrigenSoftware/ColaScript.git"
}, },
"dependencies": { "dependencies": {
"async" : "~0.2.6", "async" : "~0.2.6",
"source-map" : "~0.1.33", "source-map" : "~0.1.33",
"optimist" : "~0.3.5", "optimist" : "~0.3.5"
"uglify-to-browserify": "~1.0.0"
},
"browserify": {
"transform": [ "uglify-to-browserify" ]
}, },
"bin": { "bin": {
"uglifyjs" : "bin/uglifyjs" "cola" : "bin/cola"
}, }
"scripts": {"test": "node test/run-tests.js"}
} }