Permalink
Browse files

jsml

  • Loading branch information...
1 parent 680b448 commit 85711b000802309b308fd26ec06348c3377884a7 @jeffsu committed Mar 31, 2011
Showing with 183 additions and 95 deletions.
  1. +23 −12 dist/browser/js2-full.js
  2. +23 −12 dist/gem/lib/js2/js2.js
  3. +23 −12 dist/npm/lib/js2.js
  4. +23 −12 flavors/browser-full.js
  5. +23 −12 flavors/node.js
  6. +23 −12 flavors/ringo-full.js
  7. +23 −12 flavors/ruby.js
  8. +22 −11 src/Common/JSML.js2
View
@@ -1497,17 +1497,17 @@ JS2.Class.extend('JSML', function(KLASS, OO){
OO.addMember("initialize",function (txt) {
var lines = txt.split(/\n/);
this.root = new JS2.JSMLElement();
- this.current = this.root;
this.stack = [ this.root ];
for(var _i1=0,_c1=lines,_l1=_c1.length,l;(l=_c1[_i1])||(_i1<_l1);_i1++){
if (l.match(/^\s*$/)) continue;
this.processLine(l);
}
+ console.log(this.root);
});
OO.addMember("result",function () {
- return "hello";
+ return this.root.flatten().join('');
});
OO.addMember("processLine",function (line) {
@@ -1518,14 +1518,14 @@ JS2.Class.extend('JSML', function(KLASS, OO){
console.log('same');
this.stack.pop();
this.getLast().push(ele);
- } else if (ele.scope == scope+1) {
+ } else if (ele.scope > scope) {
console.log('greater');
this.getLast().push(ele);
this.stack.push(ele);
} else if (ele.scope < scope) {
console.log('less');
var diff = scope - ele.scope;
- while(diff-- != 0) {
+ while(diff-- > 0) {
this.stack.pop();
}
this.getLast().push(ele);
@@ -1534,7 +1534,7 @@ JS2.Class.extend('JSML', function(KLASS, OO){
OO.addMember("getScope",function () {
- return this.stack.length;
+ return this.stack.length - 1;
});
OO.addMember("getLast",function () {
@@ -1547,17 +1547,18 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
OO.addMember("TOKEN_REGEX",/^(\%|\#|\.)([\w-]+)/);
OO.addMember("JS_REGEX",/^(-|=)(.*)$/);
+ OO.addMember("SCOPE_OFFSET",2);
OO.addMember("initialize",function (line) {
this.children = [];
if (line == null) {
- this.scope = 0;
+ this.scope = this.SCOPE_OFFSET;
return;
}
var spaceMatch = line.match(this.SCOPE_REGEX);
- this.scope = spaceMatch[1].length / 2;
+ this.scope = spaceMatch[1].length / 2 + this.SCOPE_OFFSET;
this.classes = [];
this.nodeID = null;
@@ -1571,7 +1572,6 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("parse",function (line) {
var self = this;
- console.log(line);
line = line.replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) {
case '%': self.nodeType = name; break;
@@ -1588,17 +1588,28 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
return '';
});
+
+ if (!this.nodeType && (this.classes.length || this.nodeID)) {
+ this.nodeType = 'div';
+ }
});
- OO.addMember("toString",function () {
+ OO.addMember("flatten",function () {
var out = [];
+
for(var _i1=0,_c1=this.children,_l1=_c1.length,c;(c=_c1[_i1])||(_i1<_l1);_i1++){
- out.push(c.toString());
+ var arr = c.flatten();
+ for(var _i2=0,_c2=arr,_l2=_c2.length,item;(item=_c2[_i2])||(_i2<_l2);_i2++){
+ out.push(item);
+ }
}
- if (this.jsEQ) {
-
+ if (this.nodeType) {
+ out.unshift("<"+(this.nodeType)+">");
+ out.push("</"+(this.nodeType)+">");
}
+
+ return out;
});
});
View
@@ -1493,17 +1493,17 @@ JS2.Class.extend('JSML', function(KLASS, OO){
OO.addMember("initialize",function (txt) {
var lines = txt.split(/\n/);
this.root = new JS2.JSMLElement();
- this.current = this.root;
this.stack = [ this.root ];
for(var _i1=0,_c1=lines,_l1=_c1.length,l;(l=_c1[_i1])||(_i1<_l1);_i1++){
if (l.match(/^\s*$/)) continue;
this.processLine(l);
}
+ console.log(this.root);
});
OO.addMember("result",function () {
- return "hello";
+ return this.root.flatten().join('');
});
OO.addMember("processLine",function (line) {
@@ -1514,14 +1514,14 @@ JS2.Class.extend('JSML', function(KLASS, OO){
console.log('same');
this.stack.pop();
this.getLast().push(ele);
- } else if (ele.scope == scope+1) {
+ } else if (ele.scope > scope) {
console.log('greater');
this.getLast().push(ele);
this.stack.push(ele);
} else if (ele.scope < scope) {
console.log('less');
var diff = scope - ele.scope;
- while(diff-- != 0) {
+ while(diff-- > 0) {
this.stack.pop();
}
this.getLast().push(ele);
@@ -1530,7 +1530,7 @@ JS2.Class.extend('JSML', function(KLASS, OO){
OO.addMember("getScope",function () {
- return this.stack.length;
+ return this.stack.length - 1;
});
OO.addMember("getLast",function () {
@@ -1543,17 +1543,18 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
OO.addMember("TOKEN_REGEX",/^(\%|\#|\.)([\w-]+)/);
OO.addMember("JS_REGEX",/^(-|=)(.*)$/);
+ OO.addMember("SCOPE_OFFSET",2);
OO.addMember("initialize",function (line) {
this.children = [];
if (line == null) {
- this.scope = 0;
+ this.scope = this.SCOPE_OFFSET;
return;
}
var spaceMatch = line.match(this.SCOPE_REGEX);
- this.scope = spaceMatch[1].length / 2;
+ this.scope = spaceMatch[1].length / 2 + this.SCOPE_OFFSET;
this.classes = [];
this.nodeID = null;
@@ -1567,7 +1568,6 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("parse",function (line) {
var self = this;
- console.log(line);
line = line.replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) {
case '%': self.nodeType = name; break;
@@ -1584,17 +1584,28 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
return '';
});
+
+ if (!this.nodeType && (this.classes.length || this.nodeID)) {
+ this.nodeType = 'div';
+ }
});
- OO.addMember("toString",function () {
+ OO.addMember("flatten",function () {
var out = [];
+
for(var _i1=0,_c1=this.children,_l1=_c1.length,c;(c=_c1[_i1])||(_i1<_l1);_i1++){
- out.push(c.toString());
+ var arr = c.flatten();
+ for(var _i2=0,_c2=arr,_l2=_c2.length,item;(item=_c2[_i2])||(_i2<_l2);_i2++){
+ out.push(item);
+ }
}
- if (this.jsEQ) {
-
+ if (this.nodeType) {
+ out.unshift("<"+(this.nodeType)+">");
+ out.push("</"+(this.nodeType)+">");
}
+
+ return out;
});
});
View
@@ -1493,17 +1493,17 @@ JS2.Class.extend('JSML', function(KLASS, OO){
OO.addMember("initialize",function (txt) {
var lines = txt.split(/\n/);
this.root = new JS2.JSMLElement();
- this.current = this.root;
this.stack = [ this.root ];
for(var _i1=0,_c1=lines,_l1=_c1.length,l;(l=_c1[_i1])||(_i1<_l1);_i1++){
if (l.match(/^\s*$/)) continue;
this.processLine(l);
}
+ console.log(this.root);
});
OO.addMember("result",function () {
- return "hello";
+ return this.root.flatten().join('');
});
OO.addMember("processLine",function (line) {
@@ -1514,14 +1514,14 @@ JS2.Class.extend('JSML', function(KLASS, OO){
console.log('same');
this.stack.pop();
this.getLast().push(ele);
- } else if (ele.scope == scope+1) {
+ } else if (ele.scope > scope) {
console.log('greater');
this.getLast().push(ele);
this.stack.push(ele);
} else if (ele.scope < scope) {
console.log('less');
var diff = scope - ele.scope;
- while(diff-- != 0) {
+ while(diff-- > 0) {
this.stack.pop();
}
this.getLast().push(ele);
@@ -1530,7 +1530,7 @@ JS2.Class.extend('JSML', function(KLASS, OO){
OO.addMember("getScope",function () {
- return this.stack.length;
+ return this.stack.length - 1;
});
OO.addMember("getLast",function () {
@@ -1543,17 +1543,18 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("SCOPE_REGEX",/^(\s*)(.*)$/);
OO.addMember("TOKEN_REGEX",/^(\%|\#|\.)([\w-]+)/);
OO.addMember("JS_REGEX",/^(-|=)(.*)$/);
+ OO.addMember("SCOPE_OFFSET",2);
OO.addMember("initialize",function (line) {
this.children = [];
if (line == null) {
- this.scope = 0;
+ this.scope = this.SCOPE_OFFSET;
return;
}
var spaceMatch = line.match(this.SCOPE_REGEX);
- this.scope = spaceMatch[1].length / 2;
+ this.scope = spaceMatch[1].length / 2 + this.SCOPE_OFFSET;
this.classes = [];
this.nodeID = null;
@@ -1567,7 +1568,6 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
OO.addMember("parse",function (line) {
var self = this;
- console.log(line);
line = line.replace(this.TOKEN_REGEX, function(match, type, name){
switch(type) {
case '%': self.nodeType = name; break;
@@ -1584,17 +1584,28 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
}
return '';
});
+
+ if (!this.nodeType && (this.classes.length || this.nodeID)) {
+ this.nodeType = 'div';
+ }
});
- OO.addMember("toString",function () {
+ OO.addMember("flatten",function () {
var out = [];
+
for(var _i1=0,_c1=this.children,_l1=_c1.length,c;(c=_c1[_i1])||(_i1<_l1);_i1++){
- out.push(c.toString());
+ var arr = c.flatten();
+ for(var _i2=0,_c2=arr,_l2=_c2.length,item;(item=_c2[_i2])||(_i2<_l2);_i2++){
+ out.push(item);
+ }
}
- if (this.jsEQ) {
-
+ if (this.nodeType) {
+ out.unshift("<"+(this.nodeType)+">");
+ out.push("</"+(this.nodeType)+">");
}
+
+ return out;
});
});
Oops, something went wrong.

0 comments on commit 85711b0

Please sign in to comment.