OSDN Git Service

three.jsをThirdPartyに追加
[webglgame/webgl_framework.git] / webglFramework / Thirdparty / three.js-master / editor / js / libs / ternjs / comment.js
1 (function(mod) {
2   if (typeof exports == "object" && typeof module == "object") // CommonJS
3     return mod(exports);
4   if (typeof define == "function" && define.amd) // AMD
5     return define(["exports"], mod);
6   mod(tern.comment || (tern.comment = {}));
7 })(function(exports) {
8   function isSpace(ch) {
9     return (ch < 14 && ch > 8) || ch === 32 || ch === 160;
10   }
11
12   function onOwnLine(text, pos) {
13     for (; pos > 0; --pos) {
14       var ch = text.charCodeAt(pos - 1);
15       if (ch == 10) break;
16       if (!isSpace(ch)) return false;
17     }
18     return true;
19   }
20
21   // Gather comments directly before a function
22   exports.commentsBefore = function(text, pos) {
23     var found = null, emptyLines = 0, topIsLineComment;
24     out: while (pos > 0) {
25       var prev = text.charCodeAt(pos - 1);
26       if (prev == 10) {
27         for (var scan = --pos, sawNonWS = false; scan > 0; --scan) {
28           prev = text.charCodeAt(scan - 1);
29           if (prev == 47 && text.charCodeAt(scan - 2) == 47) {
30             if (!onOwnLine(text, scan - 2)) break out;
31             var content = text.slice(scan, pos);
32             if (!emptyLines && topIsLineComment) found[0] = content + "\n" + found[0];
33             else (found || (found = [])).unshift(content);
34             topIsLineComment = true;
35             emptyLines = 0;
36             pos = scan - 2;
37             break;
38           } else if (prev == 10) {
39             if (!sawNonWS && ++emptyLines > 1) break out;
40             break;
41           } else if (!sawNonWS && !isSpace(prev)) {
42             sawNonWS = true;
43           }
44         }
45       } else if (prev == 47 && text.charCodeAt(pos - 2) == 42) {
46         for (var scan = pos - 2; scan > 1; --scan) {
47           if (text.charCodeAt(scan - 1) == 42 && text.charCodeAt(scan - 2) == 47) {
48             if (!onOwnLine(text, scan - 2)) break out;
49             (found || (found = [])).unshift(text.slice(scan, pos - 2));
50             topIsLineComment = false;
51             emptyLines = 0;
52             break;
53           }
54         }
55         pos = scan - 2;
56       } else if (isSpace(prev)) {
57         --pos;
58       } else {
59         break;
60       }
61     }
62     return found;
63   };
64
65   exports.commentAfter = function(text, pos) {
66     while (pos < text.length) {
67       var next = text.charCodeAt(pos);
68       if (next == 47) {
69         var after = text.charCodeAt(pos + 1), end;
70         if (after == 47) // line comment
71           end = text.indexOf("\n", pos + 2);
72         else if (after == 42) // block comment
73           end = text.indexOf("*/", pos + 2);
74         else
75           return;
76         return text.slice(pos + 2, end < 0 ? text.length : end);
77       } else if (isSpace(next)) {
78         ++pos;
79       }
80     }
81   };
82
83   exports.ensureCommentsBefore = function(text, node) {
84     if (node.hasOwnProperty("commentsBefore")) return node.commentsBefore;
85     return node.commentsBefore = exports.commentsBefore(text, node.start);
86   };
87 });