1 //<script type="text/javascript">
2 XObject = imports.XObject.XObject;
4 Symbol = imports.Symbol.Symbol;
5 SymbolSet = imports.SymbolSet.SymbolSet;
6 DocComment = imports.DocComment.DocComment;
10 * Manages and builds the symbolsets by calling walker to create all of the symols
12 Parser = XObject.define(
15 * @param {Object} opts The configuration
22 XObject.extend(this, opts);
27 //ignoreCode: Options.n,
28 ignoreAnonymous: true, // factory: true
29 treatUnderscoredAsPrivate: true, // factory: true
30 explain: false // factory: false
32 this.symbols = new SymbolSet();
33 SymbolSet.parser = this;
40 // cfg.. document me..
45 walker : false, // will be JSDOC.Walker()
46 symbols : false, //will be JSDOC.SymbolSet()
68 * Parse a token stream.
69 * @param {JSDOC.TokenStream} token stream
70 * @param {String} filename
75 parse : function(ts, srcFile)
80 // not a nice way to set stuff...
82 Symbol.srcFile = (srcFile || "");
83 DocComment.shared = ""; // shared comments don't cross file boundaries
89 this.filesSymbols[Symbol.srcFile] = new SymbolSet();
91 //Options.LOG.inform("Parser - run walker");
92 this.walker = new imports.Walker2.Walker2( {
96 this.walker.buildSymbolTree();
100 //this.walker.walk(ts); // adds to our symbols
101 // throw "done sym tree";
102 //Options.LOG.inform("Parser - checking symbols");
103 // filter symbols by option
104 for (p in this.symbols._index) {
105 var symbol = this.symbols.getSymbol(p);
107 // print(JSON.stringify(symbol, null,4));
109 if (!symbol) continue;
111 if (symbol.isPrivate) {
112 this.symbols.deleteSymbol(symbol.alias);
116 if (symbol.is("FILE") || symbol.is("GLOBAL")) {
119 //else if (!Options.a && !symbol.comment.isUserComment) {
120 //print("Deleting Symbols (no a / user comment): " + symbol.alias);
121 //this.symbols.deleteSymbol(symbol.alias);
122 //this.filesSymbols[Symbol.srcFile].deleteSymbol(symbol.alias);
125 if (/#$/.test(symbol.alias)) { // we don't document prototypes - this should not happen..
126 // rename the symbol ??
127 /*if (!this.symbols.getSymbol(symbol.alias.substring(0,symbol.alias.length-1))) {
129 print("Renaming Symbol (got a #): " + symbol.alias);
130 var n = '' + symbol.alias;
131 this.symbols.renameSymbol( n ,n.substring(0,n-1));
132 this.filesSymbols[Symbol.srcFile].renameSymbol( n ,n.substring(0,n-1));
136 print("Deleting Symbols (got a #): " + symbol.alias);
138 this.symbols.deleteSymbol(symbol.alias);
139 this.filesSymbols[Symbol.srcFile].deleteSymbol(symbol.alias);
143 //print(prettyDump(toQDump(this.filesSymbols[Symbol.srcFile]._index,'{','}')));
144 //print("AfterParse: " + this.symbols.keys().toSource().split(",").join(",\n "));
145 return this.symbols.toArray();
149 addSymbol: function(symbol)
151 print("+symbol : " + symbol.alias);
153 // if a symbol alias is documented more than once the last one with the user docs wins
154 if (this.symbols.hasSymbol(symbol.alias)) {
155 var oldSymbol = this.symbols.getSymbol(symbol.alias);
157 if (oldSymbol.comment.isUserComment && !oldSymbol.comment.hasTags) {
158 if (symbol.comment.isUserComment) { // old and new are both documented
159 this.LOG.warn("The symbol '"+symbol.alias+"' is documented more than once.");
161 else { // old is documented but new isn't
167 // we don't document anonymous things
168 if (this.conf.ignoreAnonymous && symbol.name.match(/\$anonymous\b/)) return;
170 // uderscored things may be treated as if they were marked private, this cascades
171 if (this.conf.treatUnderscoredAsPrivate && symbol.name.match(/[.#-]_[^.#-]+$/)) {
172 symbol.isPrivate = true;
175 // -p flag is required to document private things
176 if ((symbol.isInner || symbol.isPrivate) && !this.docPrivate) return;
178 // ignored things are not documented, this doesn't cascade
179 if (symbol.isIgnored) return;
180 // add it to the file's list... (for dumping later..)
181 if (Symbol.srcFile) {
182 this.filesSymbols[Symbol.srcFile].addSymbol(symbol);
185 this.symbols.addSymbol(symbol);
188 addBuiltin: function(name)
191 var builtin = new Symbol(name, [], "CONSTRUCTOR", new DocComment(""));
192 builtin.isNamespace = false;
193 builtin.srcFile = "";
194 builtin.isPrivate = false;
195 this.addSymbol(builtin);
202 this.symbols.relate();
204 // make a litle report about what was found
205 if (this.conf.explain) {
206 var symbols = this.symbols.toArray();
208 for (var i = 0, l = symbols.length; i < l; i++) {
209 var symbol = symbols[i];
210 if (srcFile != symbol.srcFile) {
211 srcFile = symbol.srcFile;
212 print("\n"+srcFile+"\n-------------------");
214 print(i+":\n alias => "+symbol.alias + "\n name => "+symbol.name+ "\n isa => "+symbol.isa + "\n memberOf => " + symbol.memberOf + "\n isStatic => " + symbol.isStatic + ", isInner => " + symbol.isInner);
216 print("-------------------\n");
220 * return symbols so they can be serialized.
222 symbolsToObject : function(srcFile)
224 //this.filesSymbols[srcFile] is a symbolset..
225 return this.filesSymbols[srcFile];
227 // Parser.filesSymbols[srcFile]._index