Navigation Menu

Skip to content

Commit

Permalink
incremental
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffsu committed Apr 3, 2011
1 parent 2f4a15c commit 57ef10a
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 146 deletions.
47 changes: 29 additions & 18 deletions dist/browser/js2-full.js
Expand Up @@ -1513,7 +1513,6 @@ JS2.Class.extend('JSML', function(KLASS, OO){
}); });


OO.addMember("flatten",function () { OO.addMember("flatten",function () {
console.log(this.root);
return this.root.flatten(); return this.root.flatten();
}); });


Expand All @@ -1522,20 +1521,19 @@ JS2.Class.extend('JSML', function(KLASS, OO){
var scope = this.getScope(); var scope = this.getScope();


if (ele.scope == scope) { if (ele.scope == scope) {
console.log('same');
this.stack.pop(); this.stack.pop();
this.getLast().push(ele); this.getLast().push(ele);
this.stack.push(ele);
} else if (ele.scope > scope) { } else if (ele.scope > scope) {
console.log('greater');
this.getLast().push(ele); this.getLast().push(ele);
this.stack.push(ele); this.stack.push(ele);
} else if (ele.scope < scope) { } else if (ele.scope < scope) {
console.log('less'); var diff = scope - ele.scope + 1;
var diff = scope - ele.scope;
while(diff-- > 0) { while(diff-- > 0) {
this.stack.pop(); this.stack.pop();
} }
this.getLast().push(ele); this.getLast().push(ele);
this.stack.push(ele);
} }
}); });


Expand All @@ -1552,9 +1550,10 @@ JS2.Class.extend('JSML', function(KLASS, OO){


JS2.Class.extend('JSMLElement', function(KLASS, OO){ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/); OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
OO.addMember("TOKEN_REGEX",/^(\%|\#|\.)([\w-]+)/); OO.addMember("SPLIT_REGEX",/^([^=-\s]*)(=|-)?(?:\s*)(.*)$/);
OO.addMember("JS_REGEX",/^(-|=)(.*)$/); OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
OO.addMember("SCOPE_OFFSET",2); OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
OO.addMember("SCOPE_OFFSET",1);


OO.addMember("initialize",function (line) { OO.addMember("initialize",function (line) {
this.children = []; this.children = [];
Expand All @@ -1579,8 +1578,11 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){


OO.addMember("parse",function (line) { OO.addMember("parse",function (line) {
this.attributes = {}; this.attributes = {};
this.line = line;
var self = this; var self = this;
line = line.replace(this.TOKEN_REGEX, function(match, type, name){ var splitted = line.match(this.SPLIT_REGEX);

splitted[1].replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) { switch(type) {
case '%': self.nodeType = name; break; case '%': self.nodeType = name; break;
case '.': self.classes.push(name); break; case '.': self.classes.push(name); break;
Expand All @@ -1589,13 +1591,13 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
return ''; return '';
}); });


line = line.replace(this.JS_REGEX, function(match, type, content){ if (splitted[2] == '=') {
switch(type) { this.jsEQ = splitted[3];
case '=': self.jsEQ = content; break; } else if (splitted[2] == '-') {
case '-': self.jsExec = content; break; this.jsExec = splitted[3];
} } else {
return ''; this.content = splitted[3];
}); }


if (!this.nodeType && (this.classes.length || this.nodeID)) { if (!this.nodeType && (this.classes.length || this.nodeID)) {
this.nodeType = 'div'; this.nodeType = 'div';
Expand All @@ -1614,29 +1616,37 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){


if (this.nodeType) { if (this.nodeType) {
this.handleJsEQ(out); this.handleJsEQ(out);
this.handleContent(out);
out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n'); out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n'); out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else { } else {
this.handleJsExec(out); this.handleJsExec(out);
this.handleJsEQ(out); this.handleJsEQ(out);
this.handleContent(out);
} }


return out; return out;
}); });


OO.addMember("handleJsEQ",function (out) { OO.addMember("handleJsEQ",function (out) {
if (this.jsEQ) { if (this.jsEQ) {
this.jsEQ = this.jsEQ.replace(/;\s*$/, '');
out.unshift('out.push(' + this.jsEQ + ');\n'); out.unshift('out.push(' + this.jsEQ + ');\n');
} }
}); });


OO.addMember("handleContent",function (out) {
if (this.content != null && this.content.length > 0) {
out.unshift('out.push(' + JSON.stringify(this.content) + ');\n');
}
});



OO.addMember("handleJsExec",function (out) { OO.addMember("handleJsExec",function (out) {
if (this.jsExec) { if (this.jsExec) {
out.unshift(this.jsExec); out.unshift(this.jsExec);

if (this.jsExec.match(/\{\s*$/)) { if (this.jsExec.match(/\{\s*$/)) {
out.push('}'); out.push("}\n");
} }
} }
}); });
Expand All @@ -1655,6 +1665,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
out.push(k + '=' + JSON.stringify(attrs[k])); out.push(k + '=' + JSON.stringify(attrs[k]));
} }
} }

return (out.length ? ' ' : '') + out.join(' '); return (out.length ? ' ' : '') + out.join(' ');
}); });
}); });
Expand Down
47 changes: 29 additions & 18 deletions dist/gem/lib/js2/js2.js
Expand Up @@ -1509,7 +1509,6 @@ JS2.Class.extend('JSML', function(KLASS, OO){
}); });


OO.addMember("flatten",function () { OO.addMember("flatten",function () {
console.log(this.root);
return this.root.flatten(); return this.root.flatten();
}); });


Expand All @@ -1518,20 +1517,19 @@ JS2.Class.extend('JSML', function(KLASS, OO){
var scope = this.getScope(); var scope = this.getScope();


if (ele.scope == scope) { if (ele.scope == scope) {
console.log('same');
this.stack.pop(); this.stack.pop();
this.getLast().push(ele); this.getLast().push(ele);
this.stack.push(ele);
} else if (ele.scope > scope) { } else if (ele.scope > scope) {
console.log('greater');
this.getLast().push(ele); this.getLast().push(ele);
this.stack.push(ele); this.stack.push(ele);
} else if (ele.scope < scope) { } else if (ele.scope < scope) {
console.log('less'); var diff = scope - ele.scope + 1;
var diff = scope - ele.scope;
while(diff-- > 0) { while(diff-- > 0) {
this.stack.pop(); this.stack.pop();
} }
this.getLast().push(ele); this.getLast().push(ele);
this.stack.push(ele);
} }
}); });


Expand All @@ -1548,9 +1546,10 @@ JS2.Class.extend('JSML', function(KLASS, OO){


JS2.Class.extend('JSMLElement', function(KLASS, OO){ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/); OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
OO.addMember("TOKEN_REGEX",/^(\%|\#|\.)([\w-]+)/); OO.addMember("SPLIT_REGEX",/^([^=-\s]*)(=|-)?(?:\s*)(.*)$/);
OO.addMember("JS_REGEX",/^(-|=)(.*)$/); OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
OO.addMember("SCOPE_OFFSET",2); OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
OO.addMember("SCOPE_OFFSET",1);


OO.addMember("initialize",function (line) { OO.addMember("initialize",function (line) {
this.children = []; this.children = [];
Expand All @@ -1575,8 +1574,11 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){


OO.addMember("parse",function (line) { OO.addMember("parse",function (line) {
this.attributes = {}; this.attributes = {};
this.line = line;
var self = this; var self = this;
line = line.replace(this.TOKEN_REGEX, function(match, type, name){ var splitted = line.match(this.SPLIT_REGEX);

splitted[1].replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) { switch(type) {
case '%': self.nodeType = name; break; case '%': self.nodeType = name; break;
case '.': self.classes.push(name); break; case '.': self.classes.push(name); break;
Expand All @@ -1585,13 +1587,13 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
return ''; return '';
}); });


line = line.replace(this.JS_REGEX, function(match, type, content){ if (splitted[2] == '=') {
switch(type) { this.jsEQ = splitted[3];
case '=': self.jsEQ = content; break; } else if (splitted[2] == '-') {
case '-': self.jsExec = content; break; this.jsExec = splitted[3];
} } else {
return ''; this.content = splitted[3];
}); }


if (!this.nodeType && (this.classes.length || this.nodeID)) { if (!this.nodeType && (this.classes.length || this.nodeID)) {
this.nodeType = 'div'; this.nodeType = 'div';
Expand All @@ -1610,29 +1612,37 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){


if (this.nodeType) { if (this.nodeType) {
this.handleJsEQ(out); this.handleJsEQ(out);
this.handleContent(out);
out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n'); out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n'); out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else { } else {
this.handleJsExec(out); this.handleJsExec(out);
this.handleJsEQ(out); this.handleJsEQ(out);
this.handleContent(out);
} }


return out; return out;
}); });


OO.addMember("handleJsEQ",function (out) { OO.addMember("handleJsEQ",function (out) {
if (this.jsEQ) { if (this.jsEQ) {
this.jsEQ = this.jsEQ.replace(/;\s*$/, '');
out.unshift('out.push(' + this.jsEQ + ');\n'); out.unshift('out.push(' + this.jsEQ + ');\n');
} }
}); });


OO.addMember("handleContent",function (out) {
if (this.content != null && this.content.length > 0) {
out.unshift('out.push(' + JSON.stringify(this.content) + ');\n');
}
});



OO.addMember("handleJsExec",function (out) { OO.addMember("handleJsExec",function (out) {
if (this.jsExec) { if (this.jsExec) {
out.unshift(this.jsExec); out.unshift(this.jsExec);

if (this.jsExec.match(/\{\s*$/)) { if (this.jsExec.match(/\{\s*$/)) {
out.push('}'); out.push("}\n");
} }
} }
}); });
Expand All @@ -1651,6 +1661,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
out.push(k + '=' + JSON.stringify(attrs[k])); out.push(k + '=' + JSON.stringify(attrs[k]));
} }
} }

return (out.length ? ' ' : '') + out.join(' '); return (out.length ? ' ' : '') + out.join(' ');
}); });
}); });
Expand Down
47 changes: 29 additions & 18 deletions dist/npm/lib/js2.js
Expand Up @@ -1509,7 +1509,6 @@ JS2.Class.extend('JSML', function(KLASS, OO){
}); });


OO.addMember("flatten",function () { OO.addMember("flatten",function () {
console.log(this.root);
return this.root.flatten(); return this.root.flatten();
}); });


Expand All @@ -1518,20 +1517,19 @@ JS2.Class.extend('JSML', function(KLASS, OO){
var scope = this.getScope(); var scope = this.getScope();


if (ele.scope == scope) { if (ele.scope == scope) {
console.log('same');
this.stack.pop(); this.stack.pop();
this.getLast().push(ele); this.getLast().push(ele);
this.stack.push(ele);
} else if (ele.scope > scope) { } else if (ele.scope > scope) {
console.log('greater');
this.getLast().push(ele); this.getLast().push(ele);
this.stack.push(ele); this.stack.push(ele);
} else if (ele.scope < scope) { } else if (ele.scope < scope) {
console.log('less'); var diff = scope - ele.scope + 1;
var diff = scope - ele.scope;
while(diff-- > 0) { while(diff-- > 0) {
this.stack.pop(); this.stack.pop();
} }
this.getLast().push(ele); this.getLast().push(ele);
this.stack.push(ele);
} }
}); });


Expand All @@ -1548,9 +1546,10 @@ JS2.Class.extend('JSML', function(KLASS, OO){


JS2.Class.extend('JSMLElement', function(KLASS, OO){ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/); OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
OO.addMember("TOKEN_REGEX",/^(\%|\#|\.)([\w-]+)/); OO.addMember("SPLIT_REGEX",/^([^=-\s]*)(=|-)?(?:\s*)(.*)$/);
OO.addMember("JS_REGEX",/^(-|=)(.*)$/); OO.addMember("TOKEN_REGEX",/(\%|\#|\.)([\w-]+)/g);
OO.addMember("SCOPE_OFFSET",2); OO.addMember("JS_REGEX",/^(-|=)(.*)$/g);
OO.addMember("SCOPE_OFFSET",1);


OO.addMember("initialize",function (line) { OO.addMember("initialize",function (line) {
this.children = []; this.children = [];
Expand All @@ -1575,8 +1574,11 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){


OO.addMember("parse",function (line) { OO.addMember("parse",function (line) {
this.attributes = {}; this.attributes = {};
this.line = line;
var self = this; var self = this;
line = line.replace(this.TOKEN_REGEX, function(match, type, name){ var splitted = line.match(this.SPLIT_REGEX);

splitted[1].replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) { switch(type) {
case '%': self.nodeType = name; break; case '%': self.nodeType = name; break;
case '.': self.classes.push(name); break; case '.': self.classes.push(name); break;
Expand All @@ -1585,13 +1587,13 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
return ''; return '';
}); });


line = line.replace(this.JS_REGEX, function(match, type, content){ if (splitted[2] == '=') {
switch(type) { this.jsEQ = splitted[3];
case '=': self.jsEQ = content; break; } else if (splitted[2] == '-') {
case '-': self.jsExec = content; break; this.jsExec = splitted[3];
} } else {
return ''; this.content = splitted[3];
}); }


if (!this.nodeType && (this.classes.length || this.nodeID)) { if (!this.nodeType && (this.classes.length || this.nodeID)) {
this.nodeType = 'div'; this.nodeType = 'div';
Expand All @@ -1610,29 +1612,37 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){


if (this.nodeType) { if (this.nodeType) {
this.handleJsEQ(out); this.handleJsEQ(out);
this.handleContent(out);
out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n'); out.unshift('out.push(' + JSON.stringify("<"+(this.nodeType)+""+(this.getAttributes())+">") + ');\n');
out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n'); out.push('out.push(' + JSON.stringify("</"+(this.nodeType)+">") + ');\n');
} else { } else {
this.handleJsExec(out); this.handleJsExec(out);
this.handleJsEQ(out); this.handleJsEQ(out);
this.handleContent(out);
} }


return out; return out;
}); });


OO.addMember("handleJsEQ",function (out) { OO.addMember("handleJsEQ",function (out) {
if (this.jsEQ) { if (this.jsEQ) {
this.jsEQ = this.jsEQ.replace(/;\s*$/, '');
out.unshift('out.push(' + this.jsEQ + ');\n'); out.unshift('out.push(' + this.jsEQ + ');\n');
} }
}); });


OO.addMember("handleContent",function (out) {
if (this.content != null && this.content.length > 0) {
out.unshift('out.push(' + JSON.stringify(this.content) + ');\n');
}
});



OO.addMember("handleJsExec",function (out) { OO.addMember("handleJsExec",function (out) {
if (this.jsExec) { if (this.jsExec) {
out.unshift(this.jsExec); out.unshift(this.jsExec);

if (this.jsExec.match(/\{\s*$/)) { if (this.jsExec.match(/\{\s*$/)) {
out.push('}'); out.push("}\n");
} }
} }
}); });
Expand All @@ -1651,6 +1661,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
out.push(k + '=' + JSON.stringify(attrs[k])); out.push(k + '=' + JSON.stringify(attrs[k]));
} }
} }

return (out.length ? ' ' : '') + out.join(' '); return (out.length ? ' ' : '') + out.join(' ');
}); });
}); });
Expand Down

0 comments on commit 57ef10a

Please sign in to comment.