@@ -11,17 +11,49 @@ var console = require("system").log;
11
11
@requires DocComment
12
12
*/
13
13
var Parser = exports . Parser = function Parser ( options ) {
14
- this . conf = options ;
15
- this . init ( ) ;
14
+ if ( ! ( this instanceof Parser ) ) return new Parser ( options ) ;
15
+ for ( var key in options ) this [ key ] = options [ key ] ;
16
+ this . symbols = new SymbolSet ( this ) ;
17
+ this . walker = new Walker ( this ) ;
16
18
} ;
17
19
Parser . prototype = {
18
20
constructor : Parser ,
19
- init : function init ( ) {
20
- this . symbols = new SymbolSet ( this ) ;
21
- this . walker = new Walker ( this ) ;
22
- } ,
21
+ /**
22
+ * Identify secure modules while parseing source code
23
+ * @type {Boolean }
24
+ */
25
+ securemodules : true ,
26
+ /**
27
+ * If true will include all functions, even anonymus ones.
28
+ * @type {Boolean }
29
+ */
30
+ ignoreAnonymous : true ,
31
+ /**
32
+ * Treat properties starting with underscore as privates.
33
+ * @type {Boolean }
34
+ */
35
+ treatUnderscoredAsPrivate : true ,
36
+ /**
37
+ * Include symbols tagged as private, underscored and inner symbols.
38
+ * @type {Boolean }
39
+ */
40
+ includePrivates : true ,
41
+ /**
42
+ * Dump detail on found symbols
43
+ * @type {Boolean }
44
+ */
45
+ explain : false ,
46
+ /**
47
+ * Include all functions, even undocumented ones.
48
+ * @type {Boolean }
49
+ */
50
+ allfunctions : false ,
51
+ /**
52
+ * Ignore all code, only document comments with @name tags.
53
+ * @type {Boolean }
54
+ */
55
+ ignoreCode : false ,
23
56
addSymbol : function addSymbol ( symbol ) {
24
- var conf = this . conf ;
25
57
var rename = this . rename ;
26
58
if ( rename ) {
27
59
for ( var name in rename ) {
@@ -33,7 +65,7 @@ Parser.prototype = {
33
65
}
34
66
}
35
67
}
36
- if ( conf . securemodules ) {
68
+ if ( this . securemodules ) {
37
69
if ( typeof this . secureModules == "undefined" ) this . secureModules = { } ;
38
70
if ( / ^ e x p o r t s \. / . test ( symbol . alias ) ) {
39
71
symbol . srcFile . match ( / ( ^ | [ \\ \/ ] ) ( [ ^ \\ \/ ] + ) \. j s / i) ;
@@ -62,27 +94,26 @@ Parser.prototype = {
62
94
// if a symbol alias is documented more than once the last one with the user docs wins
63
95
var symbols = this . symbols ;
64
96
if ( symbols . hasSymbol ( symbol . alias ) ) {
65
- var oldSymbol = symbols . getSymbol ( symbol . alias ) ;
97
+ var oldSymbol = symbols . getSymbol ( symbol . alias ) ;
66
98
if ( oldSymbol . comment . isUserComment ) {
67
99
if ( symbol . comment . isUserComment ) { // old and new are both documented
68
100
console . warn ( "The symbol '" + symbol . alias + "' is documented more than once." ) ;
69
- }
70
- else { // old is documented but new isn't
101
+ } else { // old is documented but new isn't
71
102
return ;
72
103
}
73
104
}
74
105
}
75
106
76
107
// we don't document anonymous things
77
- if ( conf . ignoreAnonymous && symbol . name . match ( / \$ a n o n y m o u s \b / ) ) return ;
108
+ if ( this . ignoreAnonymous && symbol . name . match ( / \$ a n o n y m o u s \b / ) ) return ;
78
109
79
110
// uderscored things may be treated as if they were marked private, this cascades
80
- if ( conf . treatUnderscoredAsPrivate && symbol . name . match ( / [ . # - ] _ [ ^ . # - ] + $ / ) ) {
111
+ if ( this . treatUnderscoredAsPrivate && symbol . name . match ( / [ . # - ] _ [ ^ . # - ] + $ / ) ) {
81
112
if ( ! symbol . comment . getTag ( "public" ) . length > 0 ) symbol . isPrivate = true ;
82
113
}
83
114
84
115
// -p flag is required to document private things
85
- if ( ! conf . includePrivates && symbol . isPrivate ) return ; // issue #161 fixed by mcbain.asm
116
+ if ( ! this . includePrivates && symbol . isPrivate ) return ; // issue #161 fixed by mcbain.asm
86
117
87
118
// ignored things are not documented, this doesn't cascade
88
119
if ( symbol . isIgnored ) return ;
@@ -101,7 +132,7 @@ Parser.prototype = {
101
132
symbolsSet . relate ( ) ;
102
133
103
134
// make a litle report about what was found
104
- if ( this . conf . explain ) {
135
+ if ( this . explain ) {
105
136
var symbols = symbolsSet . toArray ( ) ;
106
137
var srcFile = "" ;
107
138
for ( var i = 0 , l = symbols . length ; i < l ; i ++ ) {
@@ -115,14 +146,15 @@ Parser.prototype = {
115
146
print ( "-------------------\n" ) ;
116
147
}
117
148
} ,
149
+ /**
150
+ * Parses specified source. Optionally specidies source uri.
151
+ */
118
152
parse : function pase ( /**TokenStream*/ ts , /**String*/ srcPath ) {
119
- var conf = this . conf ;
120
153
var symbols = this . symbols ;
121
154
// TODO: Check why we need to add this to the calsses
122
155
Symbol . srcFile = ( srcPath || "" ) ;
123
156
DocComment . shared = "" ; // shared comments don't cross file boundaries
124
157
125
- if ( ! this . walker ) this . init ( ) ;
126
158
this . walker . walk ( ts ) ; // adds to our symbols
127
159
128
160
// filter symbols by option
@@ -132,7 +164,7 @@ Parser.prototype = {
132
164
if ( symbol . is ( "FILE" ) || symbol . is ( "GLOBAL" ) ) {
133
165
continue ;
134
166
}
135
- else if ( ! conf . allfunctions && ! symbol . comment . isUserComment ) {
167
+ else if ( ! this . allfunctions && ! symbol . comment . isUserComment ) {
136
168
symbols . deleteSymbol ( symbol . alias ) ;
137
169
}
138
170
if ( / # $ / . test ( symbol . alias ) ) { // we don't document prototypes
0 commit comments