1 //<script type="text/javascript">
3 Walker = imports.Walker2.Walker2;
4 Symbol = imports.Symbol.Symbol;
5 DocComment = imports.DocComment.DocComment;
6 Options = imports.Options.Options;
8 * Parser is a static instance..
19 walker : false, // will be JSDOC.Walker()
20 symbols : false, //will be JSDOC.SymbolSet()
30 if (this.conf.loaded) {
33 print("init parser conf!?");
36 ignoreCode: Options.n,
37 ignoreAnonymous: true, // factory: true
38 treatUnderscoredAsPrivate: true, // factory: true
39 explain: false // factory: false
42 this.symbols = new SymbolSet();
43 //this.walker = new JSDOC.Walker();
44 //JSDOC.Parser.filesSymbols = {};
50 * Parse a token stream.
51 * @param {JSDOC.TokenStream} token stream
52 * @param {String} filename
57 parse : function(ts, srcFile)
62 // not a nice way to set stuff...
64 Symbol.srcFile = (srcFile || "");
65 DocComment.shared = ""; // shared comments don't cross file boundaries
71 this.filesSymbols[Symbol.srcFile] = new SymbolSet();
73 this.walker = new Walker2(ts);
74 this.walker.buildSymbolTree()
75 //this.walker.walk(ts); // adds to our symbols
76 // throw "done sym tree";
78 // filter symbols by option
79 for (p in this.symbols._index) {
80 var symbol = this.symbols.getSymbol(p);
82 if (!symbol) continue;
84 if (symbol.is("FILE") || symbol.is("GLOBAL")) {
87 else if (!Options.a && !symbol.comment.isUserComment) {
88 //print("Deleting Symbols (no a / user comment): " + symbol.alias);
89 //this.symbols.deleteSymbol(symbol.alias);
90 //this.filesSymbols[Symbol.srcFile].deleteSymbol(symbol.alias);
93 if (/#$/.test(symbol.alias)) { // we don't document prototypes - this should not happen..
94 // rename the symbol ??
95 /*if (!this.symbols.getSymbol(symbol.alias.substring(0,symbol.alias.length-1))) {
97 print("Renaming Symbol (got a #): " + symbol.alias);
98 var n = '' + symbol.alias;
99 this.symbols.renameSymbol( n ,n.substring(0,n-1));
100 this.filesSymbols[Symbol.srcFile].renameSymbol( n ,n.substring(0,n-1));
104 print("Deleting Symbols (got a #): " + symbol.alias);
106 this.symbols.deleteSymbol(symbol.alias);
107 this.filesSymbols[Symbol.srcFile].deleteSymbol(symbol.alias);
111 //print(prettyDump(toQDump(this.filesSymbols[Symbol.srcFile]._index,'{','}')));
112 //print("AfterParse: " + this.symbols.keys().toSource().split(",").join(",\n "));
113 return this.symbols.toArray();
117 addSymbol: function(symbol)
119 print("PARSER addSYMBOL : " + symbol.alias);
121 // if a symbol alias is documented more than once the last one with the user docs wins
122 if (this.symbols.hasSymbol(symbol.alias)) {
123 var oldSymbol = this.symbols.getSymbol(symbol.alias);
125 if (oldSymbol.comment.isUserComment && !oldSymbol.comment.hasTags) {
126 if (symbol.comment.isUserComment) { // old and new are both documented
127 Options.LOG.warn("The symbol '"+symbol.alias+"' is documented more than once.");
129 else { // old is documented but new isn't
135 // we don't document anonymous things
136 if (this.conf.ignoreAnonymous && symbol.name.match(/\$anonymous\b/)) return;
138 // uderscored things may be treated as if they were marked private, this cascades
139 if (this.conf.treatUnderscoredAsPrivate && symbol.name.match(/[.#-]_[^.#-]+$/)) {
140 symbol.isPrivate = true;
143 // -p flag is required to document private things
144 if ((symbol.isInner || symbol.isPrivate) && !Options.p) return;
146 // ignored things are not documented, this doesn't cascade
147 if (symbol.isIgnored) return;
148 // add it to the file's list... (for dumping later..)
149 if (Symbol.srcFile) {
150 this.filesSymbols[Symbol.srcFile].addSymbol(symbol);
153 this.symbols.addSymbol(symbol);
156 addBuiltin: function(name) {
158 var builtin = new Symbol(name, [], "CONSTRUCTOR", new DocComment(""));
159 builtin.isNamespace = false;
160 builtin.srcFile = "";
161 builtin.isPrivate = false;
162 this.addSymbol(builtin);
168 this.symbols.relate();
170 // make a litle report about what was found
171 if (this.conf.explain) {
172 var symbols = this.symbols.toArray();
174 for (var i = 0, l = symbols.length; i < l; i++) {
175 var symbol = symbols[i];
176 if (srcFile != symbol.srcFile) {
177 srcFile = symbol.srcFile;
178 print("\n"+srcFile+"\n-------------------");
180 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);
182 print("-------------------\n");