X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=JSDOC%2FScopeParser.js;h=1b315b0b6c5c87a40c9109f8ddf8d4d0579a33c4;hb=f131b6a92a53fe3263680c51f6e99405ddc3c07f;hp=671082931e5fba8ab050bc8c4bb7673030ac0533;hpb=9bacc432155ca2aee3ed7ae3d58848ec982e87f2;p=gnome.introspection-doc-generator diff --git a/JSDOC/ScopeParser.js b/JSDOC/ScopeParser.js index 6710829..1b315b0 100644 --- a/JSDOC/ScopeParser.js +++ b/JSDOC/ScopeParser.js @@ -14,7 +14,7 @@ ScopeParser = function(ts) { this.scopes = []; this.indexedScopes = {}; this.timer = new Date() * 1; - + this.debug = false; } // list of keywords that should not be used in object literals. @@ -98,6 +98,7 @@ ScopeParser.prototype = { }, warn: function(s) { + //print('****************' + s); this.warnings.push(s); //println("WARNING:" + htmlescape(s) + "
"); }, @@ -131,6 +132,9 @@ ScopeParser.prototype = { this.mode = 'BUILDING_SYMBOL_TREE'; this.parseScope(this.globalScope); + + //print("---------------END PASS 1 ---------------- "); + }, mungeSymboltree : function() { @@ -163,7 +167,7 @@ ScopeParser.prototype = { this.ts.rewind(); this.braceNesting = 0; this.scopes= []; - this.mode = 'CHECKING_SYMBOL_TREE'; + this.mode = 'PASS2_SYMBOL_TREE'; //println("MUNGING?"); @@ -174,7 +178,9 @@ ScopeParser.prototype = { log : function(str) { - //println("LOG:" + htmlescape(str) + "
\n"); + print (" ".substring(0, this.braceNesting*2) + str); + + //println("LOG:" + htmlescape(str) + "
\n"); }, logR : function(str) { @@ -189,23 +195,27 @@ ScopeParser.prototype = { parseScope : function(scope) // parse a token stream.. { //this.timerPrint("parseScope EnterScope"); + //this.log(">>> ENTER SCOPE" + this.scopes.length); var symbol; var token; var identifier; var expressionBraceNesting = this.braceNesting; - var bracketNesting = 0; + var parensNesting = 0; var isObjectLitAr = [ false ]; - + var isInObjectLitAr; this.scopes.push(scope); token = this.ts.lookTok(1); while (token) { // this.timerPrint("parseScope AFTER lookT: " + token.toString()); - this.debug|| print(token.type + '.' + token.name+ ":" + token.data); + //this.log(token.data); + if (token.type == 'NAME') { + // print('*' + token.data); + } switch(token.type + '.' + token.name) { case "KEYW.VAR": case "KEYW.CONST": // not really relivant as it's only mozzy that does this. @@ -213,17 +223,20 @@ ScopeParser.prototype = { //this.log("parseScope GOT VAR/CONST : " + token.toString()); while (true) { token = this.ts.nextTok(); - this.debug|| print( token.toString()); + !this.debug|| print( token.toString()); if (!token) { // can return false at EOF! break; } - if (token.name == "VAR") { // kludge.. + if (token.name == "VAR" || token.data == ',') { // kludge.. continue; } //this.logR("parseScope GOT VAR : " + token.toString() + ""); if (token.type !="NAME") { - print(token.toString()); + for(var i = Math.max(this.ts.cursor-10,0); i < this.ts.cursor+1; i++) { + print(this.ts.tokens[i].toString()); + } + print( "var without ident"); Seed.quit() } @@ -236,12 +249,12 @@ ScopeParser.prototype = { scope.declareIdentifier(token.data, token); } else { token.identifier = identifier; - this.warn("The variable " + token.data + ' (line:' + token.line + ") has already been declared in the same scope..."); + this.warn("(SCOPE) The variable " + token.data + ' (line:' + token.line + ") has already been declared in the same scope..."); } } token = this.ts.nextTok(); - this.debug|| print(token.toString()); + !this.debug|| print(token.toString()); /* assert token.getType() == Token.SEMI || token.getType() == Token.ASSIGN || @@ -251,11 +264,13 @@ ScopeParser.prototype = { if (token.name == "IN") { break; } else { + //var bn = this.braceNesting; this.parseExpression(); + //this.braceNesting = bn; //this.logR("parseScope DONE : ParseExpression - tok is:" + this.ts.lookT(0).toString()); token = this.ts.lookTok(1); - this.debug|| print("AFTER EXP: " + token.toString()); + !this.debug|| print("AFTER EXP: " + token.toString()); if (token.data == ';') { break; } @@ -264,23 +279,35 @@ ScopeParser.prototype = { break; case "KEYW.FUNCTION": //println(""+token.data+""); + var bn = this.braceNesting; this.parseFunctionDeclaration(); + this.braceNesting = bn; break; - case "KEYW.LEFT_CURLY": // { + case "PUNC.LEFT_CURLY": // { //println(""+token.data+""); isObjectLitAr.push(false); this.braceNesting++; + + //print(">>>>>> OBJLIT PUSH(false)" + this.braceNesting); break; - case "KEYW.RIGHT_CURLY": // } + case "PUNC.RIGHT_CURLY": // } //println(""+token.data+""); this.braceNesting--; isObjectLitAr.pop(); - //assert braceNesting >= scope.getBraceNesting(); - if (this.braceNesting == scope.braceN) { + //print(">>>>>> OBJLIT POP"+ this.braceNesting); + //assert braceNesting >= scope.getBra ceNesting(); + + if (this.braceNesting < expressionBraceNesting) { var ls = this.scopes.pop(); ls.getUsedSymbols(); + // eat symbol if we are currently at { + if (this.ts.look(0).data == '{') { + this.ts.nextTok(); + } + + //print("<<<<<< we need to flag the brace as such... isObjectLitAr.pop(); isObjectLitAr.push(true); + //print(">>>>>> OBJLIT REPUSH(true)"); } - var isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1]; + isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1]; if (isInObjectLitAr && this.ts.lookTok(1).data == ':' && ( this.ts.lookTok(-1).data == '{' || this.ts.lookTok(-1).data == ':' )) { @@ -348,11 +376,12 @@ ScopeParser.prototype = { if ((this.ts.lookTok(-1).data == "{") && (this.ts.lookTok(1).data == ":")) { isObjectLitAr.pop(); isObjectLitAr.push(true); + //print(">>>>>> OBJLIT REPUSH(true)"); //println(""+token.data+""); break; } // print("DEAL WITH obj lit:"); - var isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1]; + isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1]; if (isInObjectLitAr && (this.ts.lookTok(1).data == ":") && (this.ts.lookTok(-1).data == ",")) { // skip, it's an object lit key.. @@ -369,11 +398,11 @@ ScopeParser.prototype = { break; } symbol = token.data; - if (this.mode == 'CHECKING_SYMBOL_TREE') { + if (this.mode == 'PASS2_SYMBOL_TREE') { //println("GOT IDENT: -2 : " + this.ts.lookT(-2).toString() + "
..... -1 : " + this.ts.lookT(-1).toString() + "
"); - + //print ("MUNGE?" + symbol); //println("GOT IDENT: " + symbol + "
"); @@ -448,6 +477,7 @@ ScopeParser.prototype = { //if (this.ts.nextT()) break; } + //print("<<<<<<EXP
"); - print("PARSE EXPR"); + !this.debug || print("PARSE EXPR"); var symbol; var token; var currentScope; @@ -466,7 +496,7 @@ ScopeParser.prototype = { var expressionBraceNesting = this.braceNesting; var bracketNesting = 0; var parensNesting = 0; - + var isInObjectLitAr; var isObjectLitAr = [ false ]; while (token = this.ts.lookTok()) { @@ -475,7 +505,7 @@ ScopeParser.prototype = { currentScope = this.scopes[this.scopes.length-1]; //println(""+token.data+""); - print ("EXP" + token.toString()); + //this.log("EXP:" + token.data); switch (token.type) { case 'PUNC': switch(token.data) { @@ -496,12 +526,13 @@ ScopeParser.prototype = { isObjectLitAr.push(false); this.braceNesting++; + ///print(">>>>> EXP PUSH(false)"+this.braceNesting); break; case '}': //Token.RC: this.braceNesting--; isObjectLitAr.pop(); - + //print(">>>>> EXP POP" + this.braceNesting); // assert braceNesting >= expressionBraceNesting; break; @@ -528,11 +559,12 @@ ScopeParser.prototype = { // then we are in an object lit.. -> we need to flag the brace as such... isObjectLitAr.pop(); isObjectLitAr.push(true); + //print(">>>>> EXP PUSH(true)"); } - var isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1]; + isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1]; if (isInObjectLitAr && this.ts.lookTok(1).data == ":" && ( this.ts.lookTok(-1).data == "{" || this.ts.lookTok(-1).data == "," )) { // see if we can replace.. @@ -553,23 +585,25 @@ ScopeParser.prototype = { case 'NAME': symbol = token.data; - if (this.ts.lookTok(-1).data == "{" && this.ts.lookTok(1).data == ":") { + + if (this.ts.look(0).data == "{" && this.ts.lookTok(2).data == ":") { // then we are in an object lit.. -> we need to flag the brace as such... isObjectLitAr.pop(); isObjectLitAr.push(true); + //print(">>>>> EXP PUSH(true)"); break; } - var isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1]; - if (isInObjectLitAr && this.ts.lookTok(-1).data == "," && this.ts.lookTok(1).data == ":") { + isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1]; + if (isInObjectLitAr && this.ts.lookTok(0).data == "," && this.ts.lookTok(2).data == ":") { break; } - - if (this.ts.lookTok(-1).data == ".") { + //print(this.ts.lookTok(0).data); + if (this.ts.lookTok(0).data == ".") { //skip '.' break; } - if (this.mode == 'CHECKING_SYMBOL_TREE') { + if (this.mode == 'PASS2_SYMBOL_TREE') { identifier = this.getIdentifier(symbol, currentScope); //println("??"); @@ -678,7 +712,7 @@ ScopeParser.prototype = { parseFunctionDeclaration : function() { - + // print("PARSE FUNCTION"); var symbol; var token; var currentScope = false; @@ -709,15 +743,16 @@ ScopeParser.prototype = { this.indexedScopes[this.ts.cursor] = fnScope; } else { - //println("FETCHING SCOPE" + this.ts.cursor); + //qln("FETCHING SCOPE" + this.ts.cursor); fnScope = this.indexedScopes[this.ts.cursor]; + } // Parse function arguments. var argpos = 0; - while (!this.ts.lookTok().data == ')') { //(token = consumeToken()).getType() != Token.RP) { + while (this.ts.lookTok().data != ')') { //(token = consumeToken()).getType() != Token.RP) { token = this.ts.nextTok(); - + // print ("FUNC ARGS: " + token.toString()) //assert token.getType() == Token.NAME || // token.getType() == Token.COMMA; if (token.type == 'NAME' && this.mode == 'BUILDING_SYMBOL_TREE') {