X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=JSDOC%2FTokenReader.vala;h=9827db3a2be260075bdae995f3cba2e8963e6045;hb=251d783938126e3d5b8e9f0d91ac2f03c9c2eef1;hp=eb187f191b28274935cfce22b0ea73f577a41fd5;hpb=098716d27123ad5c167e01a3e189889f36ee0c1e;p=gnome.introspection-doc-generator diff --git a/JSDOC/TokenReader.vala b/JSDOC/TokenReader.vala index eb187f1..9827db3 100644 --- a/JSDOC/TokenReader.vala +++ b/JSDOC/TokenReader.vala @@ -41,6 +41,9 @@ namespace JSDOC { public void push (Token t) { this.tokens.add(t); } + public Token get(int i) { + return this.tokens.get(i); + } } @@ -87,12 +90,9 @@ namespace JSDOC { var tokens = new TokenArray(); bool eof; - while (true) { + while (!stream.lookEOF()) { + - stream.look(0, out eof) - if (eof) { - break; - } if (this.read_mlcomment(stream, tokens)) continue; if (this.read_slcomment(stream, tokens)) continue; if (this.read_dbquote(stream, tokens)) continue; @@ -113,7 +113,7 @@ namespace JSDOC { return tokens; - }, + } /** * findPuncToken - find the id of a token (previous to current) @@ -124,21 +124,22 @@ namespace JSDOC { * @arg {Number} offset where to start reading from * @return {Number} position of token */ - public int findPuncToken(TokenArray tokens, string data, int n) { + public int findPuncToken(TokenArray tokens, string data, int n) + { n = n || tokens.length -1; var stack = 0; while (n > -1) { - if (!stack && tokens[n].data == data) { + if (!stack && tokens.get(n).data == data) { return n; } - if (tokens[n].data == ')' || tokens[n].data == '}') { + if (tokens.get(n).data == ')' || tokens.get(n).data == '}') { stack++; n--; continue; } - if (stack && (tokens[n].data == '{' || tokens[n].data == '(')) { + if (stack && (tokens.get(n).data == '{' || tokens.get(n).data == '(')) { stack--; n--; continue; @@ -148,7 +149,7 @@ namespace JSDOC { n--; } return -1; - }, + } /** * lastSym - find the last token symbol * need to back check syntax.. @@ -157,39 +158,47 @@ namespace JSDOC { * @arg {Number} offset where to start.. * @return {Token} the token */ - lastSym : function(tokens, n) { + public Token lastSym(TokenArray tokens, int n) + { for (var i = n-1; i >= 0; i--) { - if (!(tokens[i].is("WHIT") || tokens[i].is("COMM"))) return tokens[i]; + if (!(tokens.get(i).is("WHIT") || tokens.get(i).is("COMM"))) { + return tokens.get(i); + } } return null; - }, + } /** @returns {Boolean} Was the token found? */ - read_word : function(/**JSDOC.TokenStream*/stream, tokens) { - var found = ""; - while (!stream.look().eof && Lang.isWordChar(stream.look())) { + public bool read_word (TokenStream stream, TokenArray tokens) + { + string found = ""; + while (!stream.lookEOF() && Lang.isWordChar(stream.look())) { found += stream.next(); } - if (found === "") { + if (found == "") { return false; } - var name; - if ((name = Lang.keyword(found))) { - if (found == 'return' && tokens.lastSym().data == ')') { + var name = Lang.keyword(found); + if (name) { + + // look for () return ?? why ??? + + if (found == "return" && tokens.lastSym().data == ")") { //Seed.print('@' + tokens.length); - var n = this.findPuncToken(tokens, ')'); + var n = this.findPuncToken(tokens, ")"); //Seed.print(')@' + n); - n = this.findPuncToken(tokens, '(', n-1); + n = this.findPuncToken(tokens, "(", n-1); //Seed.print('(@' + n); var lt = this.lastSym(tokens, n); - print(JSON.stringify(lt)); + + //print(JSON.stringify(lt)); if (lt.type != 'KEYW' || ['IF', 'WHILE'].indexOf(lt.name) < -1) { if (!this.ignoreBadGrammer) { throw { @@ -223,7 +232,7 @@ namespace JSDOC { return true; - }, + } /** @returns {Boolean} Was the token found?