5 public class DocParser : Object
7 // options - should they bee in PackerRun?
8 static bool ignoreAnonymous = true;
9 static bool treatUnderscoredAsPrivate = true;
10 static bool explain= false;
13 static bool has_init = false;
14 static DocWalker walker ;
15 static SymbolSet symbols ;
17 public static string currentSourceFile;
19 static Gee.HashMap<string,SymbolSet> filesSymbols;
21 // no CTOR.. it's mostly static!!
23 private static void initStatic()
25 if (DocParser.has_init) {
28 DocParser.symbols = new SymbolSet();
29 DocParser.filesSymbols = new Gee.HashMap<string,SymbolSet>();
31 DocParser.has_init = true;
36 public static void parse(TokenStream ts, string srcFile)
39 DocParser.currentSourceFile = srcFile;
40 // not a nice way to set stuff...
42 DocComment.shared = ""; // shared comments don't cross file boundaries
45 this.filesSymbols.set(srcFile, new SymbolSet());
47 //Options.LOG.inform("Parser - run walker");
48 this.walker = new Walker2(ts);
49 this.walker.buildSymbolTree();
53 //this.walker.walk(ts); // adds to our symbols
54 // throw "done sym tree";
55 //Options.LOG.inform("Parser - checking symbols");
56 // filter symbols by option
57 for (p in DocParser.symbols._index) {
58 var symbol = DocParser.symbols.getSymbol(p);
60 // print(JSON.stringify(symbol, null,4));
62 if (!symbol) continue;
64 if (symbol.isPrivate) {
65 DocParser.symbols.deleteSymbol(symbol.alias);
66 DocParser.filesSymbols.get(srcFile).deleteSymbol(symbol.alias);
70 if (symbol.is("FILE") || symbol.is("GLOBAL")) {
75 if (symbol.alias.substring(symbol.alias-1) = "#")) { // we don't document prototypes - this should not happen..
77 print("Deleting Symbols (alias ends in #): " + symbol.alias);
79 DocParser.symbols.deleteSymbol(symbol.alias);
80 DocParser.filesSymbols.get(srcFile).deleteSymbol(symbol.alias);
84 //print(prettyDump(toQDump(this.filesSymbols[Symbol.srcFile]._index,'{','}')));
85 //print("AfterParse: " + this.symbols.keys().toSource().split(",").join(",\n "));
86 return; //this.symbols.toArray();
90 public static void addSymbol(Symbol symbol)
92 //print("PARSER addSYMBOL : " + symbol.alias);
94 // if a symbol alias is documented more than once the last one with the user docs wins
95 if (DocParser.symbols.hasSymbol(symbol.alias)) {
96 var oldSymbol = DocParser.symbols.getSymbol(symbol.alias);
98 if (oldSymbol.comment.isUserComment && !oldSymbol.comment.hasTags) {
99 if (symbol.comment.isUserComment) { // old and new are both documented
100 GLib.debug("The symbol '%s' is documented more than once.",symbol.alias);
101 // we use the new one???
102 } else { // old is documented but new isn't
108 // we don't document anonymous things
109 if (DocParser.ignoreAnonymous && symbol.name.index_of("$anonymous\b") > -1) {
113 // uderscored things may be treated as if they were marked private, this cascades
114 if (DocParser.treatUnderscoredAsPrivate && symbol.name.match(/[.#-]_[^.#-]+$/)) {
115 symbol.isPrivate = true;
118 // -p flag is required to document private things
119 if ((symbol.isInner || symbol.isPrivate) && !PackerRun.opt_doc_include_private) {
123 // ignored things are not documented, this doesn't cascade
124 if (symbol.isIgnored) {
127 // add it to the file's list... (for dumping later..)
128 if (Symbol.srcFile != null) {
129 DocParser.filesSymbols.get(Symbol.srcFile).addSymbol(symbol);
132 DocParser.symbols.addSymbol(symbol);
135 public static Symbol addBuiltin(string name)
137 var builtin = new Symbol.new_builtin(name);
138 DocParser.addSymbol(builtin);
143 public static void finish() {
144 this.symbols.relate();
146 // make a litle report about what was found
148 if (this.conf.explain) {
149 var symbols = this.symbols.toArray();
151 for (var i = 0, l = symbols.length; i < l; i++) {
152 var symbol = symbols[i];
153 if (srcFile != symbol.srcFile) {
154 srcFile = symbol.srcFile;
155 print("\n"+srcFile+"\n-------------------");
157 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);
159 print("-------------------\n");
164 * return symbols so they can be serialized.
166 symbolsToObject : function(srcFile)
168 //this.filesSymbols[srcFile] is a symbolset..
169 return this.filesSymbols[srcFile];
171 // Parser.filesSymbols[srcFile]._index