Skip to content

Commit

Permalink
Merge pull request #9 from enyojs/ENYO-1036
Browse files Browse the repository at this point in the history
ENYO-1036: Add block information to kind parsing

Reviewed-By: Ben Combee (ben.combee@palm.com)
  • Loading branch information
unwiredben committed Sep 12, 2012
2 parents c12fd06 + c9494e8 commit 5414c4a
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 5 deletions.
68 changes: 68 additions & 0 deletions analyzer2/AnalyzerDebug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
enyo.kind({
name: "AnalyzerDebug",
kind: null,
debug: false,
_level: 0,
methodName: function(offset) {
var line = this.getStackInfo(3 + (offset || 0));
line = line.replace(/ .http:.*$/g, '');
line = line.replace(/^.*.enyo.kind/g, this.kindName);
line += ' ';
return line.substr(0, 30);
},
getCurrentStackInfo: function(offset) {
return " current: " + this.getStackInfo(3 + (offset || 0));
},
getPreviousStackInfo: function(offset) {
return " previous: " + this.getStackInfo(4 + (offset || 0));
},
getStackInfo: function(level) {
try {
throw new Error();
} catch(error) {
var stack = error.stack;
var lines = stack.split('\n');
return lines[level];
}
},
showLevel: function() {
return "#####################################".substr(0, this._level) + " ";
},
incremLevel: function() {
this._level++;
return this.showLevel() + " --> ";
},
decremLevel: function() {
var value = this.showLevel() + " <-- ";
this._level--;
return value;
},
showIterator: function(it) {
if (it) {
return "[" + it.ID + "/" + it.i + "] ";
} else {
return "";
}
},
logMethodEntry: function(it, msg) {
msg = msg || "";
enyo.log(this.methodName(1) + this.incremLevel() + this.showIterator(it) + msg + this.getPreviousStackInfo(1));
},
logMethodExit: function(it, msg) {
msg = msg || "";
enyo.log(this.methodName(1) + this.decremLevel() + this.showIterator(it) + msg + this.getCurrentStackInfo(1));
},
logProcessing: function(it, node) {
enyo.log(this.methodName(1) + this.showLevel() + this.showIterator(it) + "PROCESSING kind: " + node.kind + " >>" + node.token
+ "<< line: " + node.line + this.getCurrentStackInfo(1));
},
logIterMsg: function(it, msg) {
enyo.log(this.methodName(1) + this.showLevel() + this.showIterator(it) + msg + this.getPreviousStackInfo(1));
},
logMsg: function(msg) {
enyo.log(this.methodName(1) + this.showLevel() + msg + this.getPreviousStackInfo(1));
},
statics: {
_debugEnabled: false
}
});
44 changes: 41 additions & 3 deletions analyzer2/Documentor.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
enyo.kind({
name: "Documentor",
kind: null,
kind: "AnalyzerDebug",
group: "public",
constructor: function(inTokens) {
this.comment = [];
// Debug mode is off by default. Could be dynamically turn on by calling AnalyzerDebug._debugEnabled = true;
this.debug = AnalyzerDebug._debugEnabled;
return this.parse(inTokens);
},
parse: function(inTokens) {
Expand All @@ -12,8 +14,10 @@ enyo.kind({
},
walk: function(it, inState) {
var objects = [], node, obj;
if (this.debug) this.logMethodEntry(it, "inState " + inState + " >>" + JSON.stringify(it.value) + "<<");
while (it.next()) {
node = it.value;
if (this.debug) this.logProcessing(it, node);
if (node.kind == "comment") {
this.cook_comment(node.token);
}
Expand Down Expand Up @@ -43,9 +47,11 @@ enyo.kind({
obj = null;
}
}
if (this.debug) this.logMethodExit(it);
return objects;
},
cook_kind: function(it) {
if (this.debug) this.logMethodEntry(it, ">>" + JSON.stringify(it.value) + "<<");
// Get inProps[name].value[0].token
var val = function(inProps, inName) {
var i = Documentor.indexByName(inProps, inName), p;
Expand Down Expand Up @@ -81,43 +87,64 @@ enyo.kind({
if (obj.superkind == "null") {
obj.superkind = null;
}
// Store block information for the kind
obj.block = { start: args[0].start, end: args[0].end };
// remove excess value nodes
//flatten(obj.properties, "published");
}
if (this.debug) this.logMethodExit(it);
return obj;
},
cook_block: function(inNodes) {
if (this.debug) this.logMethodEntry();
var props = [];
for (var i=0, n; n=inNodes[i]; i++) {
if (this.debug) this.logProcessing(null, n);
if (n.kind == "comment") {
this.cook_comment(n.token);
}
else if (n.kind == "assignment") {
var prop = this.make("property", n);
if (n.children) {
prop.value = [this.walkValue(new Iterator(n.children))];
if (n.commaTerminated === undefined) {
prop.commaTerminated = n.children[0].commaTerminated || false;
if (n.children[0].commaTerminated === undefined) {
if (this.debug) this.logMsg("NO COMMA TERMINATED INFO");
}
} else {
prop.commaTerminated = n.commaTerminated;
}
}
props.push(prop);
}
}
if (this.debug) this.logMethodExit();
return props;
},
walkValue: function(it, inState) {
if (this.debug) this.logMethodEntry(it, "inState: " + inState + " >>" + JSON.stringify(it.value) + "<<");
while (it.next()) {
var node = it.value, obj;
if (this.debug) this.logProcessing(it, node);
if (node.kind == "comment") {
this.cook_comment(node.token);
}
else if (node.kind == "block") {
obj = this.make("block", node);
obj.properties = this.cook_block(node.children);
if (this.debug) this.logMethodExit(it, "inState: " + inState + " >>" + JSON.stringify(it.value) + "<<");
return obj;
}
else if (node.kind == "array") {
return this.cook_array(it);
obj = this.cook_array(it);
if (this.debug) this.logMethodExit(it);
return obj;
}
else if (node.kind == "function") {
return this.cook_function(it);
obj = this.cook_function(it);
if (this.debug) this.logMethodExit(it, "inState: " + inState + " >>" + JSON.stringify(it.value) + "<<");
return obj;
}
else {
obj = this.make("expression", node);
Expand All @@ -126,17 +153,23 @@ enyo.kind({
t += it.value.token;
}
obj.token = t;
if (this.debug) this.logMethodExit(it);
return obj;
}
}
if (this.debug) this.logMethodExit(it);
},
cook_function: function(it) {
if (this.debug) this.logMethodEntry(it, ">>" + JSON.stringify(it.value) + "<<");
var node = it.value;
var obj = this.make("expression", node);
obj.commaTerminated = node.commaTerminated;
obj['arguments'] = enyo.map(node.children[0].children, function(n) { return n.token; });
if (this.debug) this.logMethodExit(it);
return obj;
},
cook_array: function(it) {
if (this.debug) this.logMethodEntry(it, ">>" + JSON.stringify(it.value) + "<<");
var node = it.value;
var obj = this.make("array", node);
var nodes = node.children;
Expand All @@ -152,9 +185,11 @@ enyo.kind({
}
obj.properties = elts;
}
if (this.debug) this.logMethodExit(it);
return obj;
},
cook_assignment: function(it) {
if (this.debug) this.logMethodEntry(it, ">>" + JSON.stringify(it.value) + "<<");
var node = it.value;
var obj = this.make("global", node);
if (node.children) {
Expand All @@ -163,6 +198,7 @@ enyo.kind({
}
obj.value = [this.walkValue(new Iterator(node.children))];
}
if (this.debug) this.logMethodExit();
return obj;
},
make: function(inType, inNode) {
Expand All @@ -188,6 +224,7 @@ enyo.kind({
// * some are pragmas are read and acted on
// * other comments are collected and attached to the next emitted node
cook_comment: function(inToken) {
if (this.debug) this.logMethodEntry();
var m = inToken.match(this.commentRx);
if (m) {
m = m[1] ? m[1] : m[2];
Expand All @@ -196,6 +233,7 @@ enyo.kind({
// act on pragmas
this.honorPragmas(p);
}
if (this.debug) this.logMethodExit();
},
extractPragmas: function(inString) {
var pragmaRx = /^[*\s]*@[\S\s]*/g,
Expand Down
5 changes: 5 additions & 0 deletions analyzer2/Iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ enyo.kind({
i: -1,
nodes: null,
constructor: function(inStream) {
// Assign a unique ID to each Iterator
this.ID = Iterator._objectCount++;
this.stream = inStream;
},
statics: {
_objectCount: 0 // For debugging purpose
},
next: function() {
this.i++;
return this._read();
Expand Down
Loading

0 comments on commit 5414c4a

Please sign in to comment.