sc-docs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/.gitignore +4 -0
  2. data/.gitmodules +3 -0
  3. data/Gemfile +5 -0
  4. data/Gemfile.lock +48 -0
  5. data/LICENSE +21 -0
  6. data/README.md +59 -0
  7. data/bin/sc-docs +5 -0
  8. data/lib/sc_docs.rb +3 -0
  9. data/lib/sc_docs/cli.rb +54 -0
  10. data/lib/sc_docs/docs/Buildfile +8 -0
  11. data/lib/sc_docs/docs/README +8 -0
  12. data/lib/sc_docs/docs/apps/docs/Buildfile +15 -0
  13. data/lib/sc_docs/docs/apps/docs/controllers/classes.js +27 -0
  14. data/lib/sc_docs/docs/apps/docs/controllers/search_controller.js +62 -0
  15. data/lib/sc_docs/docs/apps/docs/controllers/selected_class.js +143 -0
  16. data/lib/sc_docs/docs/apps/docs/core.js +148 -0
  17. data/lib/sc_docs/docs/apps/docs/main.js +41 -0
  18. data/lib/sc_docs/docs/apps/docs/models/class.js +63 -0
  19. data/lib/sc_docs/docs/apps/docs/models/entity.js +29 -0
  20. data/lib/sc_docs/docs/apps/docs/models/method.js +79 -0
  21. data/lib/sc_docs/docs/apps/docs/models/property.js +48 -0
  22. data/lib/sc_docs/docs/apps/docs/resources/images/method_icon.png +0 -0
  23. data/lib/sc_docs/docs/apps/docs/resources/images/property_icon.png +0 -0
  24. data/lib/sc_docs/docs/apps/docs/resources/loading.rhtml +9 -0
  25. data/lib/sc_docs/docs/apps/docs/resources/main_page.css +156 -0
  26. data/lib/sc_docs/docs/apps/docs/resources/main_page.js +91 -0
  27. data/lib/sc_docs/docs/apps/docs/resources/templates/details.handlebars +81 -0
  28. data/lib/sc_docs/docs/apps/docs/resources/templates/extensions/signature.js +0 -0
  29. data/lib/sc_docs/docs/apps/docs/system/jquery_ui.js +62 -0
  30. data/lib/sc_docs/docs/apps/docs/system/showdown.js +1297 -0
  31. data/lib/sc_docs/docs/apps/docs/theme.js +29 -0
  32. data/lib/sc_docs/docs/apps/docs/views/detail_list.js +24 -0
  33. data/lib/sc_docs/docs/apps/docs/views/master_list.js +35 -0
  34. data/lib/sc_docs/docs/apps/docs/views/methods_collection.js +80 -0
  35. data/lib/sc_docs/docs/apps/docs/views/properties_collection.js +9 -0
  36. data/lib/sc_docs/generator.rb +145 -0
  37. data/lib/sc_docs/server.rb +21 -0
  38. data/lib/sc_docs/templates/docs.sproutcore.com/allclasses.tmpl +31 -0
  39. data/lib/sc_docs/templates/docs.sproutcore.com/allfiles.tmpl +66 -0
  40. data/lib/sc_docs/templates/docs.sproutcore.com/class.tmpl +437 -0
  41. data/lib/sc_docs/templates/docs.sproutcore.com/index.tmpl +52 -0
  42. data/lib/sc_docs/templates/docs.sproutcore.com/output/css/api.css +619 -0
  43. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/apidocs.jpg +0 -0
  44. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/apidocs.png +0 -0
  45. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/clearinput.png +0 -0
  46. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/cross.png +0 -0
  47. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/ddiagonal.png +0 -0
  48. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/diagonal.png +0 -0
  49. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/docbullet.jpg +0 -0
  50. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/docbullet.png +0 -0
  51. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/glow.png +0 -0
  52. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/logo.png +0 -0
  53. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/pixels.png +0 -0
  54. data/lib/sc_docs/templates/docs.sproutcore.com/output/img/search.png +0 -0
  55. data/lib/sc_docs/templates/docs.sproutcore.com/output/js/api.js +134 -0
  56. data/lib/sc_docs/templates/docs.sproutcore.com/output/js/jquery-bbq.js +18 -0
  57. data/lib/sc_docs/templates/docs.sproutcore.com/output/js/lib/jquery-1.5.1.min.js +16 -0
  58. data/lib/sc_docs/templates/docs.sproutcore.com/output/js/lib/modernizr-1.7.min.js +2 -0
  59. data/lib/sc_docs/templates/docs.sproutcore.com/output/js/plugin.js +1 -0
  60. data/lib/sc_docs/templates/docs.sproutcore.com/output/js/script.js +5 -0
  61. data/lib/sc_docs/templates/docs.sproutcore.com/publish.js +200 -0
  62. data/lib/sc_docs/templates/docs.sproutcore.com/static/default.css +300 -0
  63. data/lib/sc_docs/templates/docs.sproutcore.com/static/header.html +19 -0
  64. data/lib/sc_docs/templates/docs.sproutcore.com/static/index.html +19 -0
  65. data/lib/sc_docs/templates/docs.sproutcore.com/symbol.tmpl +35 -0
  66. data/lib/sc_docs/templates/sc_fixture/publish.js +632 -0
  67. data/lib/sc_docs/version.rb +4 -0
  68. data/sc_docs.gemspec +27 -0
  69. data/vendor/jsdoc/README.txt +109 -0
  70. data/vendor/jsdoc/app/frame.js +33 -0
  71. data/vendor/jsdoc/app/frame/Chain.js +102 -0
  72. data/vendor/jsdoc/app/frame/Dumper.js +144 -0
  73. data/vendor/jsdoc/app/frame/Hash.js +84 -0
  74. data/vendor/jsdoc/app/frame/Link.js +173 -0
  75. data/vendor/jsdoc/app/frame/Namespace.js +10 -0
  76. data/vendor/jsdoc/app/frame/Opt.js +134 -0
  77. data/vendor/jsdoc/app/frame/Reflection.js +26 -0
  78. data/vendor/jsdoc/app/frame/String.js +93 -0
  79. data/vendor/jsdoc/app/frame/Testrun.js +129 -0
  80. data/vendor/jsdoc/app/handlers/FOODOC.js +26 -0
  81. data/vendor/jsdoc/app/handlers/XMLDOC.js +26 -0
  82. data/vendor/jsdoc/app/handlers/XMLDOC/DomReader.js +159 -0
  83. data/vendor/jsdoc/app/handlers/XMLDOC/XMLDoc.js +16 -0
  84. data/vendor/jsdoc/app/handlers/XMLDOC/XMLParse.js +292 -0
  85. data/vendor/jsdoc/app/lib/JSDOC.js +106 -0
  86. data/vendor/jsdoc/app/lib/JSDOC/DocComment.js +204 -0
  87. data/vendor/jsdoc/app/lib/JSDOC/DocTag.js +294 -0
  88. data/vendor/jsdoc/app/lib/JSDOC/JsDoc.js +140 -0
  89. data/vendor/jsdoc/app/lib/JSDOC/JsPlate.js +109 -0
  90. data/vendor/jsdoc/app/lib/JSDOC/Lang.js +144 -0
  91. data/vendor/jsdoc/app/lib/JSDOC/Parser.js +146 -0
  92. data/vendor/jsdoc/app/lib/JSDOC/PluginManager.js +33 -0
  93. data/vendor/jsdoc/app/lib/JSDOC/Symbol.js +644 -0
  94. data/vendor/jsdoc/app/lib/JSDOC/SymbolSet.js +243 -0
  95. data/vendor/jsdoc/app/lib/JSDOC/TextStream.js +41 -0
  96. data/vendor/jsdoc/app/lib/JSDOC/Token.js +18 -0
  97. data/vendor/jsdoc/app/lib/JSDOC/TokenReader.js +332 -0
  98. data/vendor/jsdoc/app/lib/JSDOC/TokenStream.js +133 -0
  99. data/vendor/jsdoc/app/lib/JSDOC/Util.js +32 -0
  100. data/vendor/jsdoc/app/lib/JSDOC/Walker.js +507 -0
  101. data/vendor/jsdoc/app/main.js +111 -0
  102. data/vendor/jsdoc/app/plugins/commentSrcJson.js +20 -0
  103. data/vendor/jsdoc/app/plugins/frameworkPrototype.js +16 -0
  104. data/vendor/jsdoc/app/plugins/functionCall.js +10 -0
  105. data/vendor/jsdoc/app/plugins/publishSrcHilite.js +62 -0
  106. data/vendor/jsdoc/app/plugins/symbolLink.js +10 -0
  107. data/vendor/jsdoc/app/plugins/tagParamConfig.js +31 -0
  108. data/vendor/jsdoc/app/plugins/tagSynonyms.js +43 -0
  109. data/vendor/jsdoc/app/run.js +297 -0
  110. data/vendor/jsdoc/app/t/TestDoc.js +144 -0
  111. data/vendor/jsdoc/app/t/runner.js +13 -0
  112. data/vendor/jsdoc/app/test.js +342 -0
  113. data/vendor/jsdoc/app/test/addon.js +24 -0
  114. data/vendor/jsdoc/app/test/anon_inner.js +14 -0
  115. data/vendor/jsdoc/app/test/augments.js +31 -0
  116. data/vendor/jsdoc/app/test/augments2.js +26 -0
  117. data/vendor/jsdoc/app/test/borrows.js +46 -0
  118. data/vendor/jsdoc/app/test/borrows2.js +23 -0
  119. data/vendor/jsdoc/app/test/config.js +22 -0
  120. data/vendor/jsdoc/app/test/constructs.js +18 -0
  121. data/vendor/jsdoc/app/test/encoding.js +10 -0
  122. data/vendor/jsdoc/app/test/encoding_other.js +12 -0
  123. data/vendor/jsdoc/app/test/event.js +54 -0
  124. data/vendor/jsdoc/app/test/exports.js +14 -0
  125. data/vendor/jsdoc/app/test/functions_anon.js +39 -0
  126. data/vendor/jsdoc/app/test/functions_nested.js +33 -0
  127. data/vendor/jsdoc/app/test/global.js +13 -0
  128. data/vendor/jsdoc/app/test/globals.js +25 -0
  129. data/vendor/jsdoc/app/test/ignore.js +10 -0
  130. data/vendor/jsdoc/app/test/inner.js +16 -0
  131. data/vendor/jsdoc/app/test/jsdoc_test.js +477 -0
  132. data/vendor/jsdoc/app/test/lend.js +33 -0
  133. data/vendor/jsdoc/app/test/memberof.js +19 -0
  134. data/vendor/jsdoc/app/test/memberof2.js +38 -0
  135. data/vendor/jsdoc/app/test/memberof3.js +33 -0
  136. data/vendor/jsdoc/app/test/memberof_constructor.js +17 -0
  137. data/vendor/jsdoc/app/test/module.js +17 -0
  138. data/vendor/jsdoc/app/test/multi_methods.js +25 -0
  139. data/vendor/jsdoc/app/test/name.js +19 -0
  140. data/vendor/jsdoc/app/test/namespace_nested.js +23 -0
  141. data/vendor/jsdoc/app/test/nocode.js +13 -0
  142. data/vendor/jsdoc/app/test/oblit_anon.js +20 -0
  143. data/vendor/jsdoc/app/test/overview.js +20 -0
  144. data/vendor/jsdoc/app/test/param_inline.js +37 -0
  145. data/vendor/jsdoc/app/test/params_optional.js +8 -0
  146. data/vendor/jsdoc/app/test/prototype.js +17 -0
  147. data/vendor/jsdoc/app/test/prototype_nested.js +9 -0
  148. data/vendor/jsdoc/app/test/prototype_oblit.js +13 -0
  149. data/vendor/jsdoc/app/test/prototype_oblit_constructor.js +24 -0
  150. data/vendor/jsdoc/app/test/public.js +10 -0
  151. data/vendor/jsdoc/app/test/scripts/code.js +5 -0
  152. data/vendor/jsdoc/app/test/scripts/notcode.txt +5 -0
  153. data/vendor/jsdoc/app/test/shared.js +42 -0
  154. data/vendor/jsdoc/app/test/shared2.js +2 -0
  155. data/vendor/jsdoc/app/test/shortcuts.js +22 -0
  156. data/vendor/jsdoc/app/test/static_this.js +13 -0
  157. data/vendor/jsdoc/app/test/synonyms.js +31 -0
  158. data/vendor/jsdoc/app/test/tosource.js +23 -0
  159. data/vendor/jsdoc/app/test/variable_redefine.js +14 -0
  160. data/vendor/jsdoc/changes.txt +127 -0
  161. data/vendor/jsdoc/conf/sample.conf +31 -0
  162. metadata +240 -0
@@ -0,0 +1,243 @@
1
+ /** @constructor */
2
+ JSDOC.SymbolSet = function() {
3
+ this.init();
4
+ }
5
+
6
+ JSDOC.SymbolSet.prototype.init = function() {
7
+ this._index = new Hash();
8
+ }
9
+
10
+ JSDOC.SymbolSet.prototype.keys = function() {
11
+ return this._index.keys();
12
+ }
13
+
14
+ JSDOC.SymbolSet.prototype.hasSymbol = function(alias) {
15
+ return this._index.hasKey(alias);
16
+ }
17
+
18
+ JSDOC.SymbolSet.prototype.addSymbol = function(symbol) {
19
+ if (JSDOC.opt.a && this.hasSymbol(symbol.alias)) {
20
+ LOG.warn("Overwriting symbol documentation for: " + symbol.alias + ".");
21
+ this.deleteSymbol(symbol.alias);
22
+ }
23
+ this._index.set(symbol.alias, symbol);
24
+ }
25
+
26
+ JSDOC.SymbolSet.prototype.getSymbol = function(alias) {
27
+ if (this.hasSymbol(alias)) return this._index.get(alias);
28
+ }
29
+
30
+ JSDOC.SymbolSet.prototype.getSymbolByName = function(name) {
31
+ for (var p = this._index.first(); p; p = this._index.next()) {
32
+ var symbol = p.value;
33
+ if (symbol.name == name) return symbol;
34
+ }
35
+ }
36
+
37
+ JSDOC.SymbolSet.prototype.toArray = function() {
38
+ return this._index.values();
39
+ }
40
+
41
+ JSDOC.SymbolSet.prototype.deleteSymbol = function(alias) {
42
+ if (!this.hasSymbol(alias)) return;
43
+ this._index.drop(alias);
44
+ }
45
+
46
+ JSDOC.SymbolSet.prototype.renameSymbol = function(oldName, newName) {
47
+ // todo: should check if oldname or newname already exist
48
+ this._index.replace(oldName, newName);
49
+ this._index.get(newName).alias = newName;
50
+ return newName;
51
+ }
52
+
53
+ JSDOC.SymbolSet.prototype.relate = function() {
54
+ this.resolveBorrows();
55
+ this.resolveMemberOf();
56
+ this.resolveAugments();
57
+ }
58
+
59
+ JSDOC.SymbolSet.prototype.resolveBorrows = function() {
60
+ for (var p = this._index.first(); p; p = this._index.next()) {
61
+ var symbol = p.value;
62
+ if (symbol.is("FILE") || symbol.is("GLOBAL")) continue;
63
+
64
+ var borrows = symbol.inherits;
65
+ for (var i = 0; i < borrows.length; i++) {
66
+
67
+ if (/#$/.test(borrows[i].alias)) {
68
+ LOG.warn("Attempted to borrow entire instance of "+borrows[i].alias+" but that feature is not yet implemented.");
69
+ return;
70
+ }
71
+ var borrowed = this.getSymbol(borrows[i].alias);
72
+
73
+ if (!borrowed) {
74
+ LOG.warn("Can't borrow undocumented "+borrows[i].alias+".");
75
+ continue;
76
+ }
77
+
78
+ if (borrows[i].as == borrowed.alias) {
79
+ var assumedName = borrowed.name.split(/([#.-])/).pop();
80
+ borrows[i].as = symbol.name+RegExp.$1+assumedName;
81
+ LOG.inform("Assuming borrowed as name is "+borrows[i].as+" but that feature is experimental.");
82
+ }
83
+
84
+ var borrowAsName = borrows[i].as;
85
+ var borrowAsAlias = borrowAsName;
86
+ if (!borrowAsName) {
87
+ LOG.warn("Malformed @borrow, 'as' is required.");
88
+ continue;
89
+ }
90
+
91
+ if (borrowAsName.length > symbol.alias.length && borrowAsName.indexOf(symbol.alias) == 0) {
92
+ borrowAsName = borrowAsName.replace(borrowed.alias, "")
93
+ }
94
+ else {
95
+ var joiner = "";
96
+ if (borrowAsName.charAt(0) != "#") joiner = ".";
97
+ borrowAsAlias = borrowed.alias + joiner + borrowAsName;
98
+ }
99
+
100
+ borrowAsName = borrowAsName.replace(/^[#.]/, "");
101
+
102
+ if (this.hasSymbol(borrowAsAlias)) continue;
103
+
104
+ var clone = borrowed.clone();
105
+ clone.name = borrowAsName;
106
+ clone.alias = borrowAsAlias;
107
+ this.addSymbol(clone);
108
+ }
109
+ }
110
+ }
111
+
112
+ JSDOC.SymbolSet.prototype.resolveMemberOf = function() {
113
+ for (var p = this._index.first(); p; p = this._index.next()) {
114
+ var symbol = p.value;
115
+
116
+ if (symbol.is("FILE") || symbol.is("GLOBAL")) continue;
117
+
118
+ // the memberOf value was provided in the @memberOf tag
119
+ else if (symbol.memberOf) {
120
+ // like foo.bar is a memberOf foo
121
+ if (symbol.alias.indexOf(symbol.memberOf) == 0) {
122
+ var memberMatch = new RegExp("^("+symbol.memberOf+")[.#-]?(.+)$");
123
+ var aliasParts = symbol.alias.match(memberMatch);
124
+
125
+ if (aliasParts) {
126
+ symbol.memberOf = aliasParts[1];
127
+ symbol.name = aliasParts[2];
128
+ }
129
+
130
+ var nameParts = symbol.name.match(memberMatch);
131
+
132
+ if (nameParts) {
133
+ symbol.name = nameParts[2];
134
+ }
135
+ }
136
+ // like bar is a memberOf foo
137
+ else {
138
+ var joiner = symbol.memberOf.charAt(symbol.memberOf.length-1);
139
+ if (!/[.#-]/.test(joiner)) symbol.memberOf += ".";
140
+ this.renameSymbol(symbol.alias, symbol.memberOf + symbol.name);
141
+ }
142
+ }
143
+ // the memberOf must be calculated
144
+ else {
145
+ var parts = symbol.alias.match(/^(.*[.#-])([^.#-]+)$/);
146
+
147
+ if (parts) {
148
+ symbol.memberOf = parts[1];
149
+ symbol.name = parts[2];
150
+ }
151
+ }
152
+
153
+ // set isStatic, isInner
154
+ if (symbol.memberOf) {
155
+ switch (symbol.memberOf.charAt(symbol.memberOf.length-1)) {
156
+ case '#' :
157
+ symbol.isStatic = false;
158
+ symbol.isInner = false;
159
+ break;
160
+ case '.' :
161
+ symbol.isStatic = true;
162
+ symbol.isInner = false;
163
+ break;
164
+ case '-' :
165
+ symbol.isStatic = false;
166
+ symbol.isInner = true;
167
+ break;
168
+ default: // memberOf ends in none of the above
169
+ symbol.isStatic = true;
170
+ break;
171
+ }
172
+ }
173
+
174
+ // unowned methods and fields belong to the global object
175
+ if (!symbol.is("CONSTRUCTOR") && !symbol.isNamespace && symbol.memberOf == "") {
176
+ symbol.memberOf = "_global_";
177
+ }
178
+
179
+ // clean up
180
+ if (symbol.memberOf.match(/[.#-]$/)) {
181
+ symbol.memberOf = symbol.memberOf.substr(0, symbol.memberOf.length-1);
182
+ }
183
+ // add to parent's methods or properties list
184
+ if (symbol.memberOf) {
185
+
186
+ var container = this.getSymbol(symbol.memberOf);
187
+ if (!container) {
188
+ if (JSDOC.Lang.isBuiltin(symbol.memberOf)) container = JSDOC.Parser.addBuiltin(symbol.memberOf);
189
+ else {
190
+ LOG.warn("Trying to document "+symbol.name +" as a member of undocumented symbol "+symbol.memberOf+".");
191
+ }
192
+ }
193
+
194
+ if (container) container.addMember(symbol);
195
+ }
196
+ }
197
+ }
198
+
199
+ JSDOC.SymbolSet.prototype.resolveAugments = function() {
200
+ for (var p = this._index.first(); p; p = this._index.next()) {
201
+ var symbol = p.value;
202
+
203
+ if (symbol.alias == "_global_" || symbol.is("FILE")) continue;
204
+ JSDOC.SymbolSet.prototype.walk.apply(this, [symbol]);
205
+ }
206
+ }
207
+
208
+ JSDOC.SymbolSet.prototype.walk = function(symbol) {
209
+ var augments = symbol.augments;
210
+ for(var i = 0; i < augments.length; i++) {
211
+ var contributer = this.getSymbol(augments[i]);
212
+ if (!contributer && JSDOC.Lang.isBuiltin(''+augments[i])) {
213
+ contributer = new JSDOC.Symbol("_global_."+augments[i], [], augments[i], new JSDOC.DocComment("Built in."));
214
+ contributer.isNamespace = true;
215
+ contributer.srcFile = "";
216
+ contributer.isPrivate = false;
217
+ JSDOC.Parser.addSymbol(contributer);
218
+ }
219
+
220
+ if (contributer) {
221
+ if (contributer.augments.length) {
222
+ JSDOC.SymbolSet.prototype.walk.apply(this, [contributer]);
223
+ }
224
+
225
+ symbol.inheritsFrom.push(contributer.alias);
226
+ //if (!isUnique(symbol.inheritsFrom)) {
227
+ // LOG.warn("Can't resolve augments: Circular reference: "+symbol.alias+" inherits from "+contributer.alias+" more than once.");
228
+ //}
229
+ //else {
230
+ var cmethods = contributer.methods;
231
+ var cproperties = contributer.properties;
232
+
233
+ for (var ci = 0, cl = cmethods.length; ci < cl; ci++) {
234
+ if (!cmethods[ci].isStatic) symbol.inherit(cmethods[ci]);
235
+ }
236
+ for (var ci = 0, cl = cproperties.length; ci < cl; ci++) {
237
+ if (!cproperties[ci].isStatic) symbol.inherit(cproperties[ci]);
238
+ }
239
+ //}
240
+ }
241
+ else LOG.warn("Can't augment contributer: "+augments[i]+", not found.");
242
+ }
243
+ }
@@ -0,0 +1,41 @@
1
+
2
+ /**
3
+ @constructor
4
+ */
5
+ JSDOC.TextStream = function(text) {
6
+ if (typeof(text) == "undefined") text = "";
7
+ text = ""+text;
8
+ this.text = text;
9
+ this.cursor = 0;
10
+ }
11
+
12
+ JSDOC.TextStream.prototype.look = function(n) {
13
+ if (typeof n == "undefined") n = 0;
14
+
15
+ if (this.cursor+n < 0 || this.cursor+n >= this.text.length) {
16
+ var result = new String("");
17
+ result.eof = true;
18
+ return result;
19
+ }
20
+ return this.text.charAt(this.cursor+n);
21
+ }
22
+
23
+ JSDOC.TextStream.prototype.next = function(n) {
24
+ if (typeof n == "undefined") n = 1;
25
+ if (n < 1) return null;
26
+
27
+ var pulled = "";
28
+ for (var i = 0; i < n; i++) {
29
+ if (this.cursor+i < this.text.length) {
30
+ pulled += this.text.charAt(this.cursor+i);
31
+ }
32
+ else {
33
+ var result = new String("");
34
+ result.eof = true;
35
+ return result;
36
+ }
37
+ }
38
+
39
+ this.cursor += n;
40
+ return pulled;
41
+ }
@@ -0,0 +1,18 @@
1
+ if (typeof JSDOC == "undefined") JSDOC = {};
2
+
3
+ /**
4
+ @constructor
5
+ */
6
+ JSDOC.Token = function(data, type, name) {
7
+ this.data = data;
8
+ this.type = type;
9
+ this.name = name;
10
+ }
11
+
12
+ JSDOC.Token.prototype.toString = function() {
13
+ return "<"+this.type+" name=\""+this.name+"\">"+this.data+"</"+this.type+">";
14
+ }
15
+
16
+ JSDOC.Token.prototype.is = function(what) {
17
+ return this.name === what || this.type === what;
18
+ }
@@ -0,0 +1,332 @@
1
+ if (typeof JSDOC == "undefined") JSDOC = {};
2
+
3
+ /**
4
+ @class Search a {@link JSDOC.TextStream} for language tokens.
5
+ */
6
+ JSDOC.TokenReader = function() {
7
+ this.keepDocs = true;
8
+ this.keepWhite = false;
9
+ this.keepComments = false;
10
+ }
11
+
12
+ /**
13
+ @type {JSDOC.Token[]}
14
+ */
15
+ JSDOC.TokenReader.prototype.tokenize = function(/**JSDOC.TextStream*/stream) {
16
+ var tokens = [];
17
+ /**@ignore*/ tokens.last = function() { return tokens[tokens.length-1]; }
18
+ /**@ignore*/ tokens.lastSym = function() {
19
+ for (var i = tokens.length-1; i >= 0; i--) {
20
+ if (!(tokens[i].is("WHIT") || tokens[i].is("COMM"))) return tokens[i];
21
+ }
22
+ }
23
+
24
+ while (!stream.look().eof) {
25
+ if (this.read_mlcomment(stream, tokens)) continue;
26
+ if (this.read_slcomment(stream, tokens)) continue;
27
+ if (this.read_dbquote(stream, tokens)) continue;
28
+ if (this.read_snquote(stream, tokens)) continue;
29
+ if (this.read_regx(stream, tokens)) continue;
30
+ if (this.read_numb(stream, tokens)) continue;
31
+ if (this.read_punc(stream, tokens)) continue;
32
+ if (this.read_newline(stream, tokens)) continue;
33
+ if (this.read_space(stream, tokens)) continue;
34
+ if (this.read_word(stream, tokens)) continue;
35
+
36
+ // if execution reaches here then an error has happened
37
+ tokens.push(new JSDOC.Token(stream.next(), "TOKN", "UNKNOWN_TOKEN"));
38
+ }
39
+ return tokens;
40
+ }
41
+
42
+ /**
43
+ @returns {Boolean} Was the token found?
44
+ */
45
+ JSDOC.TokenReader.prototype.read_word = function(/**JSDOC.TokenStream*/stream, tokens) {
46
+ var found = "";
47
+ while (!stream.look().eof && JSDOC.Lang.isWordChar(stream.look())) {
48
+ found += stream.next();
49
+ }
50
+
51
+ if (found === "") {
52
+ return false;
53
+ }
54
+ else {
55
+ var name;
56
+ if ((name = JSDOC.Lang.keyword(found))) tokens.push(new JSDOC.Token(found, "KEYW", name));
57
+ else tokens.push(new JSDOC.Token(found, "NAME", "NAME"));
58
+ return true;
59
+ }
60
+ }
61
+
62
+ /**
63
+ @returns {Boolean} Was the token found?
64
+ */
65
+ JSDOC.TokenReader.prototype.read_punc = function(/**JSDOC.TokenStream*/stream, tokens) {
66
+ var found = "";
67
+ var name;
68
+ while (!stream.look().eof && JSDOC.Lang.punc(found+stream.look())) {
69
+ found += stream.next();
70
+ }
71
+
72
+ if (found === "") {
73
+ return false;
74
+ }
75
+ else {
76
+ tokens.push(new JSDOC.Token(found, "PUNC", JSDOC.Lang.punc(found)));
77
+ return true;
78
+ }
79
+ }
80
+
81
+ /**
82
+ @returns {Boolean} Was the token found?
83
+ */
84
+ JSDOC.TokenReader.prototype.read_space = function(/**JSDOC.TokenStream*/stream, tokens) {
85
+ var found = "";
86
+
87
+ while (!stream.look().eof && JSDOC.Lang.isSpace(stream.look())) {
88
+ found += stream.next();
89
+ }
90
+
91
+ if (found === "") {
92
+ return false;
93
+ }
94
+ else {
95
+ if (this.collapseWhite) found = " ";
96
+ if (this.keepWhite) tokens.push(new JSDOC.Token(found, "WHIT", "SPACE"));
97
+ return true;
98
+ }
99
+ }
100
+
101
+ /**
102
+ @returns {Boolean} Was the token found?
103
+ */
104
+ JSDOC.TokenReader.prototype.read_newline = function(/**JSDOC.TokenStream*/stream, tokens) {
105
+ var found = "";
106
+
107
+ while (!stream.look().eof && JSDOC.Lang.isNewline(stream.look())) {
108
+ found += stream.next();
109
+ }
110
+
111
+ if (found === "") {
112
+ return false;
113
+ }
114
+ else {
115
+ if (this.collapseWhite) found = "\n";
116
+ if (this.keepWhite) tokens.push(new JSDOC.Token(found, "WHIT", "NEWLINE"));
117
+ return true;
118
+ }
119
+ }
120
+
121
+ /**
122
+ @returns {Boolean} Was the token found?
123
+ */
124
+ JSDOC.TokenReader.prototype.read_mlcomment = function(/**JSDOC.TokenStream*/stream, tokens) {
125
+ if (stream.look() == "/" && stream.look(1) == "*") {
126
+ var found = stream.next(2);
127
+
128
+ while (!stream.look().eof && !(stream.look(-1) == "/" && stream.look(-2) == "*")) {
129
+ found += stream.next();
130
+ }
131
+
132
+ // to start doclet we allow /** or /*** but not /**/ or /****
133
+ if (/^\/\*\*([^\/]|\*[^*])/.test(found) && this.keepDocs) tokens.push(new JSDOC.Token(found, "COMM", "JSDOC"));
134
+ else if (this.keepComments) tokens.push(new JSDOC.Token(found, "COMM", "MULTI_LINE_COMM"));
135
+ return true;
136
+ }
137
+ return false;
138
+ }
139
+
140
+ /**
141
+ @returns {Boolean} Was the token found?
142
+ */
143
+ JSDOC.TokenReader.prototype.read_slcomment = function(/**JSDOC.TokenStream*/stream, tokens) {
144
+ var found;
145
+ if (
146
+ (stream.look() == "/" && stream.look(1) == "/" && (found=stream.next(2)))
147
+ ||
148
+ (stream.look() == "<" && stream.look(1) == "!" && stream.look(2) == "-" && stream.look(3) == "-" && (found=stream.next(4)))
149
+ ) {
150
+
151
+ while (!stream.look().eof && !JSDOC.Lang.isNewline(stream.look())) {
152
+ found += stream.next();
153
+ }
154
+
155
+ if (this.keepComments) {
156
+ tokens.push(new JSDOC.Token(found, "COMM", "SINGLE_LINE_COMM"));
157
+ }
158
+ return true;
159
+ }
160
+ return false;
161
+ }
162
+
163
+ /**
164
+ @returns {Boolean} Was the token found?
165
+ */
166
+ JSDOC.TokenReader.prototype.read_dbquote = function(/**JSDOC.TokenStream*/stream, tokens) {
167
+ if (stream.look() == "\"") {
168
+ // find terminator
169
+ var string = stream.next();
170
+
171
+ while (!stream.look().eof) {
172
+ if (stream.look() == "\\") {
173
+ if (JSDOC.Lang.isNewline(stream.look(1))) {
174
+ do {
175
+ stream.next();
176
+ } while (!stream.look().eof && JSDOC.Lang.isNewline(stream.look()));
177
+ string += "\\\n";
178
+ }
179
+ else {
180
+ string += stream.next(2);
181
+ }
182
+ }
183
+ else if (stream.look() == "\"") {
184
+ string += stream.next();
185
+ tokens.push(new JSDOC.Token(string, "STRN", "DOUBLE_QUOTE"));
186
+ return true;
187
+ }
188
+ else {
189
+ string += stream.next();
190
+ }
191
+ }
192
+ }
193
+ return false; // error! unterminated string
194
+ }
195
+
196
+ /**
197
+ @returns {Boolean} Was the token found?
198
+ */
199
+ JSDOC.TokenReader.prototype.read_snquote = function(/**JSDOC.TokenStream*/stream, tokens) {
200
+ if (stream.look() == "'") {
201
+ // find terminator
202
+ var string = stream.next();
203
+
204
+ while (!stream.look().eof) {
205
+ if (stream.look() == "\\") { // escape sequence
206
+ string += stream.next(2);
207
+ }
208
+ else if (stream.look() == "'") {
209
+ string += stream.next();
210
+ tokens.push(new JSDOC.Token(string, "STRN", "SINGLE_QUOTE"));
211
+ return true;
212
+ }
213
+ else {
214
+ string += stream.next();
215
+ }
216
+ }
217
+ }
218
+ return false; // error! unterminated string
219
+ }
220
+
221
+ /**
222
+ @returns {Boolean} Was the token found?
223
+ */
224
+ JSDOC.TokenReader.prototype.read_numb = function(/**JSDOC.TokenStream*/stream, tokens) {
225
+ if (stream.look() === "0" && stream.look(1) == "x") {
226
+ return this.read_hex(stream, tokens);
227
+ }
228
+
229
+ var found = "";
230
+
231
+ while (!stream.look().eof && JSDOC.Lang.isNumber(found+stream.look())){
232
+ found += stream.next();
233
+ }
234
+
235
+ if (found === "") {
236
+ return false;
237
+ }
238
+ else {
239
+ if (/^0[0-7]/.test(found)) tokens.push(new JSDOC.Token(found, "NUMB", "OCTAL"));
240
+ else tokens.push(new JSDOC.Token(found, "NUMB", "DECIMAL"));
241
+ return true;
242
+ }
243
+ }
244
+ /*t:
245
+ requires("../lib/JSDOC/TextStream.js");
246
+ requires("../lib/JSDOC/Token.js");
247
+ requires("../lib/JSDOC/Lang.js");
248
+
249
+ plan(3, "testing JSDOC.TokenReader.prototype.read_numb");
250
+
251
+ //// setup
252
+ var src = "function foo(num){while (num+8.0 >= 0x20 && num < 0777){}}";
253
+ var tr = new JSDOC.TokenReader();
254
+ var tokens = tr.tokenize(new JSDOC.TextStream(src));
255
+
256
+ var hexToken, octToken, decToken;
257
+ for (var i = 0; i < tokens.length; i++) {
258
+ if (tokens[i].name == "HEX_DEC") hexToken = tokens[i];
259
+ if (tokens[i].name == "OCTAL") octToken = tokens[i];
260
+ if (tokens[i].name == "DECIMAL") decToken = tokens[i];
261
+ }
262
+ ////
263
+
264
+ is(decToken.data, "8.0", "decimal number is found in source.");
265
+ is(hexToken.data, "0x20", "hexdec number is found in source (issue #99).");
266
+ is(octToken.data, "0777", "octal number is found in source.");
267
+ */
268
+
269
+ /**
270
+ @returns {Boolean} Was the token found?
271
+ */
272
+ JSDOC.TokenReader.prototype.read_hex = function(/**JSDOC.TokenStream*/stream, tokens) {
273
+ var found = stream.next(2);
274
+
275
+ while (!stream.look().eof) {
276
+ if (JSDOC.Lang.isHexDec(found) && !JSDOC.Lang.isHexDec(found+stream.look())) { // done
277
+ tokens.push(new JSDOC.Token(found, "NUMB", "HEX_DEC"));
278
+ return true;
279
+ }
280
+ else {
281
+ found += stream.next();
282
+ }
283
+ }
284
+ return false;
285
+ }
286
+
287
+ /**
288
+ @returns {Boolean} Was the token found?
289
+ */
290
+ JSDOC.TokenReader.prototype.read_regx = function(/**JSDOC.TokenStream*/stream, tokens) {
291
+ var last;
292
+ if (
293
+ stream.look() == "/"
294
+ &&
295
+ (
296
+
297
+ (
298
+ !(last = tokens.lastSym()) // there is no last, the regex is the first symbol
299
+ ||
300
+ (
301
+ !last.is("NUMB")
302
+ && !last.is("NAME")
303
+ && !last.is("RIGHT_PAREN")
304
+ && !last.is("RIGHT_BRACKET")
305
+ )
306
+ )
307
+ )
308
+ ) {
309
+ var regex = stream.next();
310
+
311
+ while (!stream.look().eof) {
312
+ if (stream.look() == "\\") { // escape sequence
313
+ regex += stream.next(2);
314
+ }
315
+ else if (stream.look() == "/") {
316
+ regex += stream.next();
317
+
318
+ while (/[gmi]/.test(stream.look())) {
319
+ regex += stream.next();
320
+ }
321
+
322
+ tokens.push(new JSDOC.Token(regex, "REGX", "REGX"));
323
+ return true;
324
+ }
325
+ else {
326
+ regex += stream.next();
327
+ }
328
+ }
329
+ // error: unterminated regex
330
+ }
331
+ return false;
332
+ }