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 Walker walker ;
15 private static SymbolSet? _symbols = null;
17 public static SymbolSet symbols() {
18 if (DocParser._symbols == null) {
19 GLib.debug("init symbols?");
20 DocParser._symbols = new SymbolSet();
21 //DocParser._symbols.ref(); // not sure why, by symbols keeps getting blanked.?
23 return DocParser._symbols;
25 static Gee.HashMap<string,SymbolSet>? _filesSymbols = null;
27 static Gee.HashMap<string,SymbolSet> filesSymbols()
29 if (DocParser._filesSymbols == null) {
30 GLib.debug("init _filesSymbols?");
31 DocParser._filesSymbols = new Gee.HashMap<string,SymbolSet>();
33 return DocParser._filesSymbols;
37 public static string currentSourceFile;
44 public static void parse(TokenStream ts, string srcFile)
47 DocParser.currentSourceFile = srcFile;
48 // not a nice way to set stuff...
50 DocComment.shared = ""; // shared comments don't cross file boundaries
52 DocParser.filesSymbols().set(srcFile, new SymbolSet());
54 //Options.LOG.inform("Parser - run walker");
55 walker = new Walker(ts);
56 walker.buildSymbolTree();
60 //this.walker.walk(ts); // adds to our symbols
61 // throw "done sym tree";
62 //Options.LOG.inform("Parser - checking symbols");
63 // filter symbols by option
64 foreach (var p in DocParser.symbols().keys()) {
65 var symbol = DocParser.symbols().getSymbol(p);
67 // print(JSON.stringify(symbol, null,4));
69 if (symbol == null) continue;
71 if (symbol.isPrivate) {
72 DocParser.symbols().deleteSymbol(symbol.alias);
73 DocParser.filesSymbols().get(srcFile).deleteSymbol(symbol.alias);
77 if (symbol.is("FILE") || symbol.is("GLOBAL")) {
82 if (symbol.alias.substring(symbol.alias.length-1) == "#") { // we don't document prototypes - this should not happen..
84 print("Deleting Symbols (alias ends in #): " + symbol.alias);
86 DocParser.symbols().deleteSymbol(symbol.alias);
87 DocParser.filesSymbols().get(srcFile).deleteSymbol(symbol.alias);
91 //print(prettyDump(toQDump(this.filesSymbols[Symbol.srcFile]._index,'{','}')));
92 //print("AfterParse: " + this.symbols.keys().toSource().split(",").join(",\n "));
93 return; //this.symbols.toArray();
97 public static void addSymbol(Symbol symbol)
99 //print("PARSER addSYMBOL : " + symbol.alias);
101 // if a symbol alias is documented more than once the last one with the user docs wins
102 if (DocParser.symbols().hasSymbol(symbol.alias)) {
103 var oldSymbol = DocParser.symbols().getSymbol(symbol.alias);
105 if (oldSymbol.comment.isUserComment && !oldSymbol.comment.hasTags) {
106 if (symbol.comment.isUserComment) { // old and new are both documented
107 GLib.debug("The symbol '%s' is documented more than once.",symbol.alias);
108 // we use the new one???
109 } else { // old is documented but new isn't
115 // we don't document anonymous things
116 if (DocParser.ignoreAnonymous && symbol.name.index_of("$anonymous\b") > -1) {
120 // uderscored things may be treated as if they were marked private, this cascades
121 //if (DocParser.treatUnderscoredAsPrivate && symbol.name.match(/[.#-]_[^.#-]+$/)) {
122 // symbol.isPrivate = true;
125 // -p flag is required to document private things
126 if ((symbol.isInner || symbol.isPrivate) && !PackerRun.singleton().opt_doc_include_private) {
130 // ignored things are not documented, this doesn't cascade
131 if (symbol.isIgnored) {
134 // add it to the file's list... (for dumping later..)
135 if (DocParser.currentSourceFile != null) {
136 DocParser.filesSymbols().get(DocParser.currentSourceFile).addSymbol(symbol);
139 DocParser.symbols().addSymbol(symbol);
142 public static Symbol addBuiltin(string name)
144 var builtin = new Symbol.new_builtin(name);
145 DocParser.addSymbol(builtin);
150 public static void finish() {
153 DocParser.symbols().relate();
155 // make a litle report about what was found
157 if (this.conf.explain) {
158 var symbols = this.symbols.toArray();
160 for (var i = 0, l = symbols.length; i < l; i++) {
161 var symbol = symbols[i];
162 if (srcFile != symbol.srcFile) {
163 srcFile = symbol.srcFile;
164 print("\n"+srcFile+"\n-------------------");
166 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);
168 print("-------------------\n");
173 * return symbols so they can be serialized.
175 SymbolSet symbolsToObject(string srcFile)
178 return DocParser.filesSymbols().get(srcFile);