OLD | NEW |
1 /** | 1 /** |
2 * This processes comments. | 2 * This processes comments. |
3 */ | 3 */ |
4 function associate_comments(filename, scopeObject) { | 4 function associate_comments(filename, scopeObject) { |
5 // Read the script and give us line stuff | 5 // Read the script and give us line stuff |
6 let file = read_file(filename).split(/\r\n|[\r\n]/); | 6 let file = read_file(filename).split(/\r\n|[\r\n]/); |
7 // make file 1-based to avoid off-by-one errors... | 7 // make file 1-based to avoid off-by-one errors... |
8 file.unshift(""); | 8 file.unshift(""); |
9 | 9 |
10 // Now, get us a sorted list of all important AST locations | 10 // Now, get us a sorted list of all important AST locations |
11 let locations = [{loc: {line: 0, column: -1}}]; | 11 let locations = [{loc: {line: 0, column: -1}}]; |
12 | 12 |
13 function add_func(func) { | 13 function add_func(func) { |
14 locations.push({loc: func.loc, obj: func, commentWanted: true}); | 14 locations.push({loc: func.loc, obj: func, commentWanted: true}); |
15 // The following will get us to the last line of the function | 15 // The following will get us to the last line of the function |
16 if (func.body.kids.length == 0) | 16 if (func.body.kids.length == 0) |
17 return; | 17 return; |
18 let last = func.body.kids[func.body.kids.length - 1]; | 18 let last = func.body.kids[func.body.kids.length - 1]; |
19 while (last.kids[last.kids.length - 1] && | 19 while (last.kids[last.kids.length - 1] && |
20 last.kids[last.kids.length - 1].line > last.line) | 20 last.kids[last.kids.length - 1].line > last.line) |
21 last = last.kids[last.kids.length - 1]; | 21 last = last.kids[last.kids.length - 1]; |
22 locations.push({loc: {line: last.line, column: last.column}}); | 22 locations.push({loc: {line: last.line, column: last.column}}); |
23 } | 23 } |
24 for each (let v in scopeObject.variables) | 24 for (let v of scopeObject.variables) |
25 locations.push({loc: v.loc, obj: v, commentWanted: true}); | 25 locations.push({loc: v.loc, obj: v, commentWanted: true}); |
26 for each (let v in scopeObject.constants) | 26 for (let v of scopeObject.constants) |
27 locations.push({loc: v.loc, obj: v, commentWanted: true}); | 27 locations.push({loc: v.loc, obj: v, commentWanted: true}); |
28 for each (let v in scopeObject.functions) | 28 for (let v of scopeObject.functions) |
29 add_func(v); | 29 add_func(v); |
30 for each (let v in scopeObject.code) | 30 for (let v of scopeObject.code) |
31 locations.push({loc: {line: v.line, column: v.column}, obj: v}); | 31 locations.push({loc: {line: v.line, column: v.column}, obj: v}); |
32 for each (let o in scopeObject.objects) { | 32 for (let o of scopeObject.objects) { |
33 locations.push({loc: o.loc, obj: o, commentWanted: true}); | 33 locations.push({loc: o.loc, obj: o, commentWanted: true}); |
34 for each (let x in o.variables) | 34 for (let x of o.variables) |
35 locations.push({loc: x.loc, obj: x, commentWanted: true}); | 35 locations.push({loc: x.loc, obj: x, commentWanted: true}); |
36 for each (let x in o.functions) | 36 for (let x of o.functions) |
37 add_func(x); | 37 add_func(x); |
38 for each (let x in o.getters) | 38 for (let x of o.getters) |
39 add_func(x); | 39 add_func(x); |
40 for each (let x in o.setters) | 40 for (let x of o.setters) |
41 add_func(x); | 41 add_func(x); |
42 } | 42 } |
43 for each (let o in scopeObject.classes) { | 43 for (let o of scopeObject.classes) { |
44 locations.push({loc: o.loc, obj: o, commentWanted: true}); | 44 locations.push({loc: o.loc, obj: o, commentWanted: true}); |
45 for each (let x in o.variables) | 45 for (let x of o.variables) |
46 locations.push({loc: x.loc, obj: x, commentWanted: true}); | 46 locations.push({loc: x.loc, obj: x, commentWanted: true}); |
47 for each (let x in o.functions) | 47 for (let x of o.functions) |
48 add_func(x); | 48 add_func(x); |
49 for each (let x in o.getters) | 49 for (let x of o.getters) |
50 add_func(x); | 50 add_func(x); |
51 for each (let x in o.setters) | 51 for (let x of o.setters) |
52 add_func(x); | 52 add_func(x); |
53 } | 53 } |
54 locations.sort(function (a, b) { | 54 locations.sort(function (a, b) { |
55 if (a.loc.line == b.loc.line) | 55 if (a.loc.line == b.loc.line) |
56 return a.loc.column - b.loc.column; | 56 return a.loc.column - b.loc.column; |
57 return a.loc.line - b.loc.line; | 57 return a.loc.line - b.loc.line; |
58 }); | 58 }); |
59 | 59 |
60 // With that list done, let's find comments in the range. | 60 // With that list done, let's find comments in the range. |
61 for (let i = 1; i < locations.length; i++) { | 61 for (let i = 1; i < locations.length; i++) { |
(...skipping 15 matching lines...) Expand all Loading... |
77 lines.push(file[end.line].substring(0, end.column).trim()); | 77 lines.push(file[end.line].substring(0, end.column).trim()); |
78 | 78 |
79 let goop = lines.join("\n"); | 79 let goop = lines.join("\n"); |
80 let match; | 80 let match; |
81 lines = []; | 81 lines = []; |
82 while ((match = comment_regex.exec(goop)) != null) { | 82 while ((match = comment_regex.exec(goop)) != null) { |
83 lines.push(match); | 83 lines.push(match); |
84 } | 84 } |
85 return lines.join("\n"); | 85 return lines.join("\n"); |
86 } | 86 } |
OLD | NEW |