X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=JSDOC%2FScopeParser.vala;h=a6c181b1e34d85fbcab366eb9ee999a1d1d6ca97;hb=6e248ccf55375a678357d1874740caa66bc2b637;hp=8053427eaae401b578b59f297c39f02bd2dedceb;hpb=1c4475c57f654121588c476b1934cbb08b21ae24;p=gnome.introspection-doc-generator diff --git a/JSDOC/ScopeParser.vala b/JSDOC/ScopeParser.vala index 8053427..a6c181b 100644 --- a/JSDOC/ScopeParser.vala +++ b/JSDOC/ScopeParser.vala @@ -24,7 +24,7 @@ namespace JSDOC { Gee.HashMap indexedScopes; bool munge = true; - + int expN = 0; public ScopeParser(TokenStream ts) { this.ts = ts; // {TokenStream} @@ -184,36 +184,34 @@ namespace JSDOC { } - log : function(str) + void log(string str) { - print (" ".substring(0, this.braceNesting*2) + str); + print(str); + //print (" ".substring(0, this.braceNesting*2) + str); //println("LOG:" + htmlescape(str) + "
\n"); - }, - logR : function(str) + } + void logR (string str) { //println("LOG:" + str + "
"); - }, + } - parseScope : function(scope) // parse a token stream.. + void parseScope(Scope 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 + 0; var parensNesting = 0; - var isObjectLitAr = [ false ]; - var isInObjectLitAr; + var isObjectLitAr = new Gee.ArrayList(); + isObjectLitAr.add(false); + //var scopeIndent = ''; @@ -225,8 +223,8 @@ namespace JSDOC { - token = this.ts.lookTok(1); - while (token) { + var token = this.ts.lookTok(1); + while (token != null) { // this.timerPrint("parseScope AFTER lookT: " + token.toString()); //this.dumpToken(token , this.scopes, this.braceNesting); //print('SCOPE:' + token.toString()); @@ -245,36 +243,37 @@ namespace JSDOC { token = this.ts.nextTok(); //!this.debug|| print( token.toString()); // print('SCOPE-VAR-VAL:' + JSON.stringify(token, null, 4)); - if (!token) { // can return false at EOF! + if (token == null) { // can return false at EOF! break; } - if (token.name == "VAR" || token.data == ',') { // kludge.. + if (token.name == "VAR" || token.data == ",") { // kludge.. continue; } //this.logR("parseScope GOT VAR : " + token.toString() + ""); if (token.type != "NAME") { - for(var i = Math.max(this.ts.cursor-10,0); i < this.ts.cursor+1; i++) { + + for(var i = int.max(this.ts.cursor-10,0); i < this.ts.cursor+1; i++) { print(this.ts.tokens[i].toString()); } print( "var without ident"); - Seed.quit() + GLib.Process.exit (0); } - if (this.mode == "BUILDING_SYMBOL_TREE") { - identifier = scope.getIdentifier(token.data,token) ; + if (this.mode == ScopeParserMode.BUILDING_SYMBOL_TREE) { + var identifier = scope.getIdentifier(token.data,token) ; if (identifier == false) { scope.declareIdentifier(token.data, token); } else { token.identifier = identifier; - this.warn("(SCOPE) 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 || @@ -286,15 +285,15 @@ namespace JSDOC { } else { //var bn = this.braceNesting; var bn = this.braceNesting; - var nts = []; + var nts = new Gee.ArrayList(); while (true) { - if (!token || token.type == 'VOID' || token.data == ',') { + if (!token || token.type == "VOID" || token.data == ",") { break; } - nts.push(token); + nts.add(token); token = this.ts.nextTok(); } - if (nts.length) { + if (nts.size > 0) { var TS = this.ts; this.ts = new TokenStream(nts); this.parseExpression(scope); @@ -308,7 +307,7 @@ namespace JSDOC { token = this.ts.lookTok(1); //!this.debug|| // print("AFTER EXP: " + token.toString()); - if (token.data == ';') { + if (token.data == ";") { break; } } @@ -335,17 +334,20 @@ namespace JSDOC { //print('SCOPE-CURLY/PAREN:' + token.toString()); //println(""+token.data+""); var curTS = this.ts; - if (token.props) { + if (token.props.size() > 0) { // { a : ... , c : .... } + var iter = token.props.map_iterator(); - for (var prop in token.props) { + while(iter.next()) { + + TokenKeyMap val = iter.get_value(); // TokenKeyMap // print('SCOPE-PROPS:' + JSON.stringify(token.props[prop],null,4)); - if (token.props[prop].val[0].data == 'function') { + if (val.vals.get(0).data == "function") { // parse a function.. - this.ts = new TokenStream(token.props[prop].val); + this.ts = new TokenStream(val.vals); this.ts.nextTok(); this.parseFunctionDeclaration(scope); @@ -353,7 +355,7 @@ namespace JSDOC { } // key value.. - this.ts = new TokenStream(token.props[prop].val); + this.ts = new TokenStream(val.vals); this.parseExpression(scope); } @@ -366,14 +368,14 @@ namespace JSDOC { // ( ... ) or { .... } not object literals.. - var _this = this; - for (var xx =0; xx < token.items.length; xx++) { - expr = token.items[xx]; + + for (var xx =0; xx < token.items.size; xx++) { + expr = token.items.get(xx); //token.items.forEach(function(expr) { //print(expr.toString()); - _this.ts = new TokenStream(expr); + this.ts = new TokenStream(expr); //if (curTS.data == '(') { - _this.parseScope(scope) + this.parseScope(scope); //} else { // _this.parseExpression(scope) //} @@ -395,7 +397,7 @@ namespace JSDOC { case "KEYW.WITH": //print('SCOPE-WITH:' + token.toString()); //println(""+token.data+""); - if (this.mode == "BUILDING_SYMBOL_TREE") { + if (this.mode == ScopeParserMode.BUILDING_SYMBOL_TREE) { // Inside a 'with' block, it is impossible to figure out // statically whether a symbol is a local variable or an // object member. As a consequence, the only thing we can @@ -417,21 +419,22 @@ namespace JSDOC { // print('SCOPE-STRING:' + token.toString()); //println(""+token.data+""); - if (this.ts.lookTok(-1).data == '{' && this.ts.lookTok(1).data == ':') { + if (this.ts.lookTok(-1).data == "{" && this.ts.lookTok(1).data == ":") { // then we are in an object lit.. -> we need to flag the brace as such... - isObjectLitAr.pop(); - isObjectLitAr.push(true); + isObjectLitAr.remove_at(isObjectLitAr.size-1); + isObjectLitAr.add(true); //print(">>>>>> OBJLIT REPUSH(true)"); } - isInObjectLitAr = isObjectLitAr[isObjectLitAr.length-1]; + isInObjectLitAr = isObjectLitAr.get(isObjectLitAr.size-1); - if (isInObjectLitAr && this.ts.lookTok(1).data == ':' && - ( this.ts.lookTok(-1).data == '{' || this.ts.lookTok(-1).data == ':' )) { + if (isInObjectLitAr && this.ts.lookTok(1).data == ":" && + ( this.ts.lookTok(-1).data == "{" || this.ts.lookTok(-1).data == ":" )) { // see if we can replace.. // remove the quotes.. // should do a bit more checking!!!! (what about wierd char's in the string.. var str = token.data.substring(1,token.data.length-1); - if (/^[a-z_]+$/i.test(str) && ScopeParser.idents.indexOf(str) < 0) { + + if (Regex.match_simple ("^[a-z_]+$", str) && this.idents.index_of(str) < 0) { token.outData = str; } @@ -456,10 +459,11 @@ namespace JSDOC { //print("SYMBOL: " + token.toString()); symbol = token.data; - if (symbol == 'this') { + if (symbol == "this") { break; } - if (this.mode == 'PASS2_SYMBOL_TREE') { + + if (this.mode == ScopeParserMode.PASS2_SYMBOL_TREE) { //println("GOT IDENT: -2 : " + this.ts.lookT(-2).toString() + "
..... -1 : " + this.ts.lookT(-1).toString() + "
"); @@ -478,7 +482,7 @@ namespace JSDOC { // We don't need to declare longer symbols since they won't cause // any conflict with other munged symbols. this.globalScope.declareIdentifier(symbol, token); - this.warn("Found an undeclared symbol: " + symbol + ' (line:' + token.line + ')', true); + this.warn("Found an undeclared symbol: " + symbol + " (line:" + token.line + ")", true); } //println("GOT IDENT IGNORE(3): " + symbol + "
"); @@ -491,7 +495,7 @@ namespace JSDOC { break; //println("SID"); default: - if (token.type != 'KEYW') { + if (token.type != "KEYW") { break; } //print('SCOPE-KEYW:' + token.toString()); @@ -499,7 +503,7 @@ namespace JSDOC { symbol = token.data; - if (this.mode == 'BUILDING_SYMBOL_TREE') { + if (this.mode == ScopeParserMode.BUILDING_SYMBOL_TREE) { if (token.name == "EVAL") { @@ -510,6 +514,8 @@ namespace JSDOC { // look for eval:var:noreplace\n //print("MATCH!?"); var _t = this; + + token.prefix.replace(/eval:var:([a-z_]+)/ig, function(m, a) { //print("GOT: " + a); var hi = _t.getIdentifier(a, scope, token); @@ -546,38 +552,37 @@ namespace JSDOC { } //print("<<< EXIT SCOPE"); //print("<<<<<<EXP
"); - !this.debug || print("PARSE EXPR"); + //!this.debug || print("PARSE EXPR"); this.expN++; // for printing stuff.. - var symbol; - var token; - - var identifier; var expressionBraceNesting = this.braceNesting + 0; var bracketNesting = 0; var parensNesting = 0; var isInObjectLitAr; - var isObjectLitAr = [ false ]; + var isObjectLitAr = new Gee.ArrayList(); + isObjectLitAr.add( false); //print(scopeIndent + ">> ENTER EXPRESSION" + this.expN); - while ((token = this.ts.nextTok())) { + while (null != (token = this.ts.nextTok())) { @@ -598,23 +603,23 @@ namespace JSDOC { //println(""+token.data+""); //this.log("EXP:" + token.data); switch (token.type) { - case 'PUNC': + case "PUNC": //print("EXPR-PUNC:" + token.toString()); switch(token.data) { - case ';': + case ";": //print("<< EXIT EXPRESSION"); break; - case ',': + case ",": break; - case '(': //Token.LP: - case '{': //Token.LC: - case '[': //Token.LB: + case "(": //Token.LP: + case "{": //Token.LC: + case "[": //Token.LB: //print('SCOPE-CURLY/PAREN/BRACE:' + token.toString()); // print('SCOPE-CURLY/PAREN/BRACE:' + JSON.stringify(token, null,4)); //println(""+token.data+"");