1 //<script type="text/javascript">
3 Walker2 = imports.Walker2.Walker2;
4 Symbol = imports.Symbol.Symbol;
5 SymbolSet = imports.SymbolSet.SymbolSet;
6 DocComment = imports.DocComment.DocComment;
7 Options = imports.Options.Options;
9 * Parser is a static instance..
20 walker : false, // will be JSDOC.Walker()
21 symbols : false, //will be JSDOC.SymbolSet()
31 if (this.conf.loaded) {
34 print("init parser conf!?");
37 //ignoreCode: Options.n,
38 ignoreAnonymous: true, // factory: true
39 treatUnderscoredAsPrivate: true, // factory: true
40 explain: false // factory: false
43 this.symbols = new SymbolSet();
44 //this.walker = new JSDOC.Walker();
45 //JSDOC.Parser.filesSymbols = {};
51 * Parse a token stream.
52 * @param {JSDOC.TokenStream} token stream
53 * @param {String} filename
58 parse : function(ts, srcFile)
63 // not a nice way to set stuff...
65 Symbol.srcFile = (srcFile || "");
66 DocComment.shared = ""; // shared comments don't cross file boundaries
72 this.filesSymbols[Symbol.srcFile] = new SymbolSet();
74 Options.LOG.inform("Parser - run walker");
75 this.walker = new Walker2(ts);
76 this.walker.buildSymbolTree();
80 //this.walker.walk(ts); // adds to our symbols
81 // throw "done sym tree";
82 Options.LOG.inform("Parser - checking symbols");
83 // filter symbols by option
84 for (p in this.symbols._index) {
85 var symbol = this.symbols.getSymbol(p);
87 print(JSON.stringify(symbol, null,4));
89 if (!symbol) continue;
91 if (symbol.is("FILE") || symbol.is("GLOBAL")) {
94 //else if (!Options.a && !symbol.comment.isUserComment) {
95 //print("Deleting Symbols (no a / user comment): " + symbol.alias);
96 //this.symbols.deleteSymbol(symbol.alias);
97 //this.filesSymbols[Symbol.srcFile].deleteSymbol(symbol.alias);
100 if (/#$/.test(symbol.alias)) { // we don't document prototypes - this should not happen..
101 // rename the symbol ??
102 /*if (!this.symbols.getSymbol(symbol.alias.substring(0,symbol.alias.length-1))) {
104 print("Renaming Symbol (got a #): " + symbol.alias);
105 var n = '' + symbol.alias;
106 this.symbols.renameSymbol( n ,n.substring(0,n-1));
107 this.filesSymbols[Symbol.srcFile].renameSymbol( n ,n.substring(0,n-1));
111 print("Deleting Symbols (got a #): " + symbol.alias);
113 this.symbols.deleteSymbol(symbol.alias);
114 this.filesSymbols[Symbol.srcFile].deleteSymbol(symbol.alias);
118 //print(prettyDump(toQDump(this.filesSymbols[Symbol.srcFile]._index,'{','}')));
119 //print("AfterParse: " + this.symbols.keys().toSource().split(",").join(",\n "));
120 return this.symbols.toArray();
124 addSymbol: function(symbol)
126 print("PARSER addSYMBOL : " + symbol.alias);
128 // if a symbol alias is documented more than once the last one with the user docs wins
129 if (this.symbols.hasSymbol(symbol.alias)) {
130 var oldSymbol = this.symbols.getSymbol(symbol.alias);
132 if (oldSymbol.comment.isUserComment && !oldSymbol.comment.hasTags) {
133 if (symbol.comment.isUserComment) { // old and new are both documented
134 Options.LOG.warn("The symbol '"+symbol.alias+"' is documented more than once.");
136 else { // old is documented but new isn't
142 // we don't document anonymous things
143 if (this.conf.ignoreAnonymous && symbol.name.match(/\$anonymous\b/)) return;
145 // uderscored things may be treated as if they were marked private, this cascades
146 if (this.conf.treatUnderscoredAsPrivate && symbol.name.match(/[.#-]_[^.#-]+$/)) {
147 symbol.isPrivate = true;
150 // -p flag is required to document private things
151 if ((symbol.isInner || symbol.isPrivate) && !Options.p) return;
153 // ignored things are not documented, this doesn't cascade
154 if (symbol.isIgnored) return;
155 // add it to the file's list... (for dumping later..)
156 if (Symbol.srcFile) {
157 this.filesSymbols[Symbol.srcFile].addSymbol(symbol);
160 this.symbols.addSymbol(symbol);
163 addBuiltin: function(name) {
165 var builtin = new Symbol(name, [], "CONSTRUCTOR", new DocComment(""));
166 builtin.isNamespace = false;
167 builtin.srcFile = "";
168 builtin.isPrivate = false;
169 this.addSymbol(builtin);
175 this.symbols.relate();
177 // make a litle report about what was found
178 if (this.conf.explain) {
179 var symbols = this.symbols.toArray();
181 for (var i = 0, l = symbols.length; i < l; i++) {
182 var symbol = symbols[i];
183 if (srcFile != symbol.srcFile) {
184 srcFile = symbol.srcFile;
185 print("\n"+srcFile+"\n-------------------");
187 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);
189 print("-------------------\n");