Mercurial > projects > dil
annotate trunk/src/dil/doc/Doc.d @ 731:ca7607226caa
Added new module cmd.DDoc.
Added command 'ddoc'.
Fixed scanArguments() in dil.doc.Macro.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sun, 03 Feb 2008 19:56:47 +0100 |
parents | 41cad5ca4863 |
children | f88b5285b86b |
rev | line source |
---|---|
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
1 /++ |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
2 Author: Aziz Köksal |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
3 License: GPL3 |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
4 +/ |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
5 module dil.doc.Doc; |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
6 |
728
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
7 import dil.doc.Parser; |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
8 import dil.ast.Node; |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
9 import dil.lexer.Funcs; |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
10 import dil.Unicode; |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
11 import common; |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
12 |
731
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
13 import tango.text.Ascii : toLower; |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
14 |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
15 class DDocComment |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
16 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
17 Section[] sections; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
18 Section summary; /// Optional summary section. |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
19 Section description; /// Optional description section. |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
20 |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
21 this(Section[] sections, Section summary, Section description) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
22 { |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
23 this.sections = sections; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
24 this.summary = summary; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
25 this.description = description; |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
26 } |
731
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
27 |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
28 Section getCopyright() |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
29 { |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
30 foreach (section; sections) |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
31 if (toLower(section.name) == "copyright") |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
32 return section; |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
33 return null; |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
34 } |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
35 } |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
36 |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
37 /// Returns a node's DDocComment. |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
38 DDocComment getDDocComment(Node node) |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
39 { |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
40 DDocParser p; |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
41 p.parse(getDDocText(getDocTokens(node))); |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
42 return new DDocComment(p.sections, p.summary, p.description); |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
43 } |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
44 |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
45 struct DDocParser |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
46 { |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
47 char* p; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
48 char* textEnd; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
49 Section[] sections; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
50 Section summary; /// Optional summary section. |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
51 Section description; /// Optional description section. |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
52 |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
53 /// Parses the DDoc text into sections. |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
54 Section[] parse(string text) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
55 { |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
56 if (!text.length) |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
57 return null; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
58 if (text[$-1] != '\0') |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
59 text ~= '\0'; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
60 p = text.ptr; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
61 textEnd = p + text.length; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
62 |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
63 char* summaryBegin; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
64 char* idBegin, idEnd; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
65 char* nextIdBegin, nextIdEnd; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
66 |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
67 skipWhitespace(p); |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
68 summaryBegin = p; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
69 |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
70 if (findNextIdColon(idBegin, idEnd)) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
71 { // Check that this is not an explicit section. |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
72 if (summaryBegin != idBegin) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
73 scanSummaryAndDescription(summaryBegin, idBegin); |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
74 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
75 else // There are no explicit sections. |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
76 { |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
77 scanSummaryAndDescription(summaryBegin, textEnd); |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
78 return null; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
79 } |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
80 |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
81 assert(idBegin && idEnd); |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
82 while (findNextIdColon(nextIdBegin, nextIdEnd)) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
83 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
84 sections ~= new Section(makeString(idBegin, idEnd), makeString(idEnd+1, nextIdBegin)); |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
85 idBegin = nextIdBegin; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
86 idEnd = nextIdEnd; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
87 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
88 // Add last section. |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
89 sections ~= new Section(makeString(idBegin, idEnd), makeString(idEnd+1, textEnd)); |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
90 return sections; |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
91 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
92 |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
93 void scanSummaryAndDescription(char* p, char* end) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
94 { |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
95 assert(p < end); |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
96 char* sectionBegin = p; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
97 // Search for the end of the first paragraph. |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
98 while (p < end && !(*p == '\n' && p[1] == '\n')) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
99 p++; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
100 // The first paragraph is the summary. |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
101 summary = new Section("", makeString(sectionBegin, p)); |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
102 sections ~= summary; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
103 // The rest is the description section. |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
104 if (p != end) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
105 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
106 sectionBegin = p; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
107 skipWhitespace(p); |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
108 if (p < end) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
109 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
110 description = new Section("", makeString(sectionBegin, end)); |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
111 sections ~= description; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
112 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
113 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
114 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
115 |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
116 void skipWhitespace(ref char* p) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
117 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
118 while (isspace(*p) || *p == '\n') |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
119 p++; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
120 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
121 |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
122 /// Find next "Identifier:". |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
123 /// Params: |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
124 /// p = current character pointer |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
125 /// idBegin = set to the first character of the Identifier |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
126 /// idEnd = set to the colon following the Identifier |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
127 /// Returns: true if found |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
128 bool findNextIdColon(ref char* ref_idBegin, ref char* ref_idEnd) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
129 { |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
130 auto p = this.p; |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
131 while (*p != '\0') |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
132 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
133 auto idBegin = p; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
134 assert(isascii(*p) || isLeadByte(*p)); |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
135 if (isidbeg(*p) || isUnicodeAlpha(p, textEnd)) // IdStart |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
136 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
137 do // IdChar* |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
138 p++; |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
139 while (isident(*p) || isUnicodeAlpha(p, textEnd)) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
140 if (*p == ':') // : |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
141 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
142 ref_idBegin = idBegin; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
143 ref_idEnd = p; |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
144 this.p = p; |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
145 return true; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
146 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
147 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
148 else if (!isascii(*p)) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
149 { // Skip UTF-8 sequences. |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
150 while (!isascii(*++p)) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
151 {} |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
152 continue; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
153 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
154 p++; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
155 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
156 return false; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
157 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
158 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
159 |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
160 class Section |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
161 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
162 string name; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
163 string text; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
164 this(string name, string text) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
165 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
166 this.name = name; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
167 this.text = text; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
168 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
169 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
170 |
728
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
171 class ParamsSection : Section |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
172 { |
728
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
173 string[] paramNames; /// Parameter names. |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
174 string[] paramDescs; /// Parameter descriptions. |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
175 this(string name, string text) |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
176 { |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
177 super(name, text); |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
178 IdentValueParser parser; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
179 auto idvalues = parser.parse(text); |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
180 this.paramNames = new string[idvalues.length]; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
181 this.paramDescs = new string[idvalues.length]; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
182 foreach (i, idvalue; idvalues) |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
183 { |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
184 this.paramNames[i] = idvalue.ident; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
185 this.paramDescs[i] = idvalue.value; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
186 } |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
187 } |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
188 } |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
189 |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
190 class MacrosSection : Section |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
191 { |
731
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
192 string[] macroNames; /// Macro names. |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
193 string[] macroTexts; /// Macro texts. |
728
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
194 this(string name, string text) |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
195 { |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
196 super(name, text); |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
197 IdentValueParser parser; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
198 auto idvalues = parser.parse(text); |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
199 this.macroNames = new string[idvalues.length]; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
200 this.macroTexts = new string[idvalues.length]; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
201 foreach (i, idvalue; idvalues) |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
202 { |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
203 this.macroNames[i] = idvalue.ident; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
204 this.macroTexts[i] = idvalue.value; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
205 } |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
206 } |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
207 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
208 |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
209 bool isDoxygenComment(Token* token) |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
210 { // Doxygen: '/+!' '/*!' '//!' |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
211 return token.kind == TOK.Comment && token.start[2] == '!'; |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
212 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
213 |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
214 bool isDDocComment(Token* token) |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
215 { // DDOC: '/++' '/**' '///' |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
216 return token.kind == TOK.Comment && token.start[1] == token.start[2]; |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
217 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
218 |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
219 /++ |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
220 Returns the surrounding documentation comment tokens. |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
221 Note: this function works correctly only if |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
222 the source text is syntactically correct. |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
223 +/ |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
224 Token*[] getDocTokens(Node node, bool function(Token*) isDocComment = &isDDocComment) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
225 { |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
226 Token*[] comments; |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
227 auto isEnumMember = node.kind == NodeKind.EnumMemberDeclaration; |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
228 // Get preceding comments. |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
229 auto token = node.begin; |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
230 // Scan backwards until we hit another declaration. |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
231 Loop: |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
232 while (1) |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
233 { |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
234 token = token.prev; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
235 if (token.kind == TOK.LBrace || |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
236 token.kind == TOK.RBrace || |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
237 token.kind == TOK.Semicolon || |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
238 token.kind == TOK.HEAD || |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
239 (isEnumMember && token.kind == TOK.Comma)) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
240 break; |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
241 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
242 if (token.kind == TOK.Comment) |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
243 { // Check that this comment doesn't belong to the previous declaration. |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
244 switch (token.prev.kind) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
245 { |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
246 case TOK.Semicolon, TOK.RBrace, TOK.Comma: |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
247 break Loop; |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
248 default: |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
249 if (isDocComment(token)) |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
250 comments = [token] ~ comments; |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
251 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
252 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
253 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
254 // Get single comment to the right. |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
255 token = node.end.next; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
256 if (token.kind == TOK.Comment && isDocComment(token)) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
257 comments ~= token; |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
258 else if (isEnumMember) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
259 { |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
260 token = node.end.nextNWS; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
261 if (token.kind == TOK.Comma) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
262 { |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
263 token = token.next; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
264 if (token.kind == TOK.Comment && isDocComment(token)) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
265 comments ~= token; |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
266 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
267 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
268 return comments; |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
269 } |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
270 |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
271 bool isLineComment(Token* t) |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
272 { |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
273 assert(t.kind == TOK.Comment); |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
274 return t.start[1] == '/'; |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
275 } |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
276 |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
277 /// Extracts the text body of the comment tokens. |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
278 string getDDocText(Token*[] tokens) |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
279 { |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
280 string result; |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
281 foreach (token; tokens) |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
282 { |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
283 auto n = isLineComment(token) ? 0 : 2; // 0 for "//", 2 for "+/" and "*/". |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
284 result ~= sanitize(token.srcText[3 .. $-n], token.start[1]); |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
285 } |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
286 return result; |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
287 } |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
288 |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
289 /// Sanitizes a DDoc comment string. |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
290 /// Leading "commentChar"s are removed from the lines. |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
291 /// The various newline types are converted to '\n'. |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
292 /// Params: |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
293 /// comment = the string to be sanitized. |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
294 /// commentChar = '/', '+', or '*' |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
295 string sanitize(string comment, char commentChar) |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
296 { |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
297 string result = comment.dup ~ '\0'; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
298 |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
299 assert(result[$-1] == '\0'); |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
300 bool newline = true; // Indicates whether a newline has been encountered. |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
301 uint i, j; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
302 for (; i < result.length; i++) |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
303 { |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
304 if (newline) |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
305 { // Ignore commentChars at the beginning of each new line. |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
306 newline = false; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
307 while (isspace(result[i])) |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
308 { i++; } |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
309 while (result[i] == commentChar) |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
310 { i++; } |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
311 } |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
312 // Check for Newline. |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
313 switch (result[i]) |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
314 { |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
315 case '\r': |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
316 if (result[i+1] == '\n') |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
317 i++; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
318 case '\n': |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
319 result[j++] = '\n'; // Copy Newline as '\n'. |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
320 newline = true; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
321 continue; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
322 default: |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
323 if (isUnicodeNewline(result.ptr + i)) |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
324 { |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
325 i++; i++; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
326 goto case '\n'; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
327 } |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
328 } |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
329 // Copy character. |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
330 result[j++] = result[i]; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
331 } |
728
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
332 result.length = j - 1; // Adjust length. -1 removes '\0'. |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
333 // Lastly, strip trailing commentChars. |
728
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
334 i = result.length; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
335 while (--i && result[i] == commentChar) |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
336 {} |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
337 result.length = i + 1; |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
338 return result; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
339 } |