X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=JSDOC%2FTokenReader.js;h=f9aa83109eaf78eef1506976044c429d9a596a54;hb=05141d13558c377a970de1e5771865a567ac2526;hp=9c95240eaafb86a1094f28a8e04cb862a220591a;hpb=5e6ab0028dedcf2b592fde432c87850f10793f53;p=gnome.introspection-doc-generator diff --git a/JSDOC/TokenReader.js b/JSDOC/TokenReader.js index 9c95240..f9aa831 100644 --- a/JSDOC/TokenReader.js +++ b/JSDOC/TokenReader.js @@ -14,17 +14,24 @@ Lang = imports.Lang.Lang; TokenReader = XObject.define( function(o) { - this.keepDocs = true; - this.keepWhite = false; - this.keepComments = false; - this.sepIdents = false; // seperate '.' in identifiers.. XObject.extend(this, o || {}); }, Object, { + /** @cfg {Boolean} collapseWhite merge multiple whitespace/comments into a single token **/ collapseWhite : false, // only reduces white space... - + /** @cfg {Boolean} keepDocs keep JSDOC comments **/ + keepDocs : true, + /** @cfg {Boolean} keepWhite keep White space **/ + keepWhite : false, + /** @cfg {Boolean} keepComments keep all comments **/ + keepComments : false, + /** @cfg {Boolean} sepIdents seperate identifiers (eg. a.b.c into ['a', '.', 'b', '.', 'c'] ) **/ + sepIdents : false, + /** @cfg {String} filename name of file being parsed. **/ + filename : '', + /** * tokenize a stream * @return {Array} of tokens @@ -40,8 +47,10 @@ TokenReader = XObject.define( tokenize : function(/**JSDOC.TextStream*/stream) { this.line =1; var tokens = []; - /**@ignore*/ tokens.last = function() { return tokens[tokens.length-1]; } - /**@ignore*/ tokens.lastSym = function() { + /**@ignore*/ + tokens.last = function() { return tokens[tokens.length-1]; } + /**@ignore*/ + tokens.lastSym = function() { for (var i = tokens.length-1; i >= 0; i--) { if (!(tokens[i].is("WHIT") || tokens[i].is("COMM"))) return tokens[i]; } @@ -80,29 +89,36 @@ TokenReader = XObject.define( if (found === "") { return false; } - else { - var name; - if ((name = Lang.keyword(found))) { - tokens.push(new Token(found, "KEYW", name, this.line)); - return true; - } - if (!this.sepIdents || found.indexOf('.') < 0 ) { - tokens.push(new Token(found, "NAME", "NAME", this.line)); - return true; - } - var n = found.split('.'); - var p = false; - var _this = this; - n.forEach(function(nm) { - if (p) { - tokens.push(new Token('.', "PUNC", "DOT", _this.line)); - } - p=true; - tokens.push(new Token(nm, "NAME", "NAME", _this.line)); - }); - return true; + + var name; + if ((name = Lang.keyword(found))) { + if (found == 'return' && tokens.lastSym().data == ')') { + throw { + name : "ArgumentError", + message: "\n" + this.filename + ':' + this.line + " Error - return found after )" + } + + tokens.push(new Token(found, "KEYW", name, this.line)); + return true; } + if (!this.sepIdents || found.indexOf('.') < 0 ) { + tokens.push(new Token(found, "NAME", "NAME", this.line)); + return true; + } + var n = found.split('.'); + var p = false; + var _this = this; + n.forEach(function(nm) { + if (p) { + tokens.push(new Token('.', "PUNC", "DOT", _this.line)); + } + p=true; + tokens.push(new Token(nm, "NAME", "NAME", _this.line)); + }); + return true; + + }, /** @@ -115,13 +131,23 @@ TokenReader = XObject.define( found += stream.next(); } + if (found === "") { return false; } - else { - tokens.push(new Token(found, "PUNC", Lang.punc(found), this.line)); - return true; + + if ((found == '}' || found == ']') && tokens.lastSym().data == ',') { + //print("Error - comma found before " + found); + //print(JSON.stringify(tokens.lastSym(), null,4)); + throw { + name : "ArgumentError", + message: "\n" + this.filename + ':' + this.line + " Error - comma found before " + found + } } + + tokens.push(new Token(found, "PUNC", Lang.punc(found), this.line)); + return true; + }, /** @@ -164,7 +190,7 @@ TokenReader = XObject.define( } if (this.keepWhite) { var last = tokens.pop(); - if (last.name != "WHIT") { + if (last && last.name != "WHIT") { tokens.push(last); }