Mercurial > projects > dil
annotate trunk/src/dil/doc/Doc.d @ 785:57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Added a lot of documentation comments and revised some.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sat, 23 Feb 2008 21:15:56 +0100 |
parents | 939097e0990f |
children | 3b34f6a95a27 |
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 |
746
32a8ddd330f8
Using icompare() instead of toLower().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
745
diff
changeset
|
13 import tango.text.Ascii : icompare; |
731
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
14 |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
15 /// Represents a sanitized and parsed DDoc comment. |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
16 class DDocComment |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
17 { |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
18 Section[] sections; /// The sections of this comment. |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
19 Section summary; /// Optional summary section. |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
20 Section description; /// Optional description section. |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
21 |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
22 this(Section[] sections, Section summary, Section description) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
23 { |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
24 this.sections = sections; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
25 this.summary = summary; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
26 this.description = description; |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
27 } |
731
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
28 |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
29 /// Removes the first copyright section and returns it. |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
30 Section takeCopyright() |
731
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
31 { |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
32 foreach (i, section; sections) |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
33 if (section.Is("copyright")) |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
34 { |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
35 sections = sections[0..i] ~ sections[i+1..$]; |
731
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
36 return section; |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
37 } |
731
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
38 return null; |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
39 } |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
40 |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
41 /// Returns true if "ditto" is the only text in this comment. |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
42 bool isDitto() |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
43 { |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
44 if (summary && sections.length == 1 && |
746
32a8ddd330f8
Using icompare() instead of toLower().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
745
diff
changeset
|
45 icompare(strip(summary.text), "ditto") == 0) |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
46 return true; |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
47 return false; |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
48 } |
731
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
49 } |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
50 |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
51 /// Returns a node's DDocComment. |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
52 DDocComment getDDocComment(Node node) |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
53 { |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
54 DDocParser p; |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
55 p.parse(getDDocText(getDocTokens(node))); |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
56 if (p.sections.length) |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
57 return new DDocComment(p.sections, p.summary, p.description); |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
58 return null; |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
59 } |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
60 |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
61 /// Strips leading and trailing whitespace characters. |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
62 /// Whitespace: ' ', '\t', '\v', '\f' and '\n' |
746
32a8ddd330f8
Using icompare() instead of toLower().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
745
diff
changeset
|
63 /// Returns: a slice into str. |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
64 char[] strip(char[] str) |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
65 { |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
66 if (str.length == 0) |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
67 return null; |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
68 uint i; |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
69 for (; i < str.length; i++) |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
70 if (!isspace(str[i]) && str[i] != '\n') |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
71 break; |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
72 if (str.length == i) |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
73 return null; |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
74 str = str[i..$]; |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
75 assert(str.length); |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
76 for (i = str.length; i; i--) |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
77 if (!isspace(str[i-1]) && str[i-1] != '\n') |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
78 break; |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
79 return str[0..i]; |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
80 } |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
81 |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
82 /// Parses a DDoc comment string. |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
83 struct DDocParser |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
84 { |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
85 char* p; /// Current character pointer. |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
86 char* textEnd; /// Points one character past the end of the text. |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
87 Section[] sections; /// Parsed sections. |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
88 Section summary; /// Optional summary section. |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
89 Section description; /// Optional description section. |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
90 |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
91 /// 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
|
92 Section[] parse(string text) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
93 { |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
94 if (!text.length) |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
95 return null; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
96 p = text.ptr; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
97 textEnd = p + text.length; |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
98 |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
99 char* summaryBegin; |
745 | 100 string ident, nextIdent; |
101 char* bodyBegin, nextBodyBegin; | |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
102 |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
103 skipWhitespace(p); |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
104 summaryBegin = p; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
105 |
745 | 106 if (findNextIdColon(ident, bodyBegin)) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
107 { // Check that this is not an explicit section. |
745 | 108 if (summaryBegin != ident.ptr) |
109 scanSummaryAndDescription(summaryBegin, ident.ptr); | |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
110 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
111 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
|
112 { |
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
113 scanSummaryAndDescription(summaryBegin, textEnd); |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
114 return sections; |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
115 } |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
116 |
745 | 117 assert(ident.length); |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
118 // Continue parsing. |
745 | 119 while (findNextIdColon(nextIdent, nextBodyBegin)) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
120 { |
745 | 121 sections ~= new Section(ident, textBody(bodyBegin, nextIdent.ptr)); |
122 ident = nextIdent; | |
123 bodyBegin = nextBodyBegin; | |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
124 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
125 // Add last section. |
745 | 126 sections ~= new Section(ident, textBody(bodyBegin, textEnd)); |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
127 return sections; |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
128 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
129 |
745 | 130 /// Removes trailing whitespace characters from the text body. |
131 char[] textBody(char* begin, char* end) | |
132 { | |
133 // The body of A is empty, e.g.: | |
134 // A: | |
135 // B: some text | |
136 // ^- begin and end point to B (or to this.textEnd in the 2nd case.) | |
137 if (begin is end) | |
138 return ""; | |
139 // Remove trailing whitespace. | |
140 while (isspace(*--end) || *end == '\n') | |
141 {} | |
142 end++; | |
143 return makeString(begin, end); | |
144 } | |
145 | |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
146 /// Separates the text between p and end |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
147 /// into a summary and description section. |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
148 void scanSummaryAndDescription(char* p, char* end) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
149 { |
751
8caf18892c1b
Improved DDocEmitter and fixed bugs.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
746
diff
changeset
|
150 assert(p <= end); |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
151 char* sectionBegin = p; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
152 // Search for the end of the first paragraph. |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
153 end--; // Decrement end, so we can look ahead one character. |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
154 while (p < end && !(*p == '\n' && p[1] == '\n')) |
784
939097e0990f
Fixed the summary section scanner.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
155 { |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
156 if (isCodeSection(p, end)) |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
157 skipCodeSection(p, end); |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
158 p++; |
784
939097e0990f
Fixed the summary section scanner.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
769
diff
changeset
|
159 } |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
160 end++; |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
161 if (p+1 >= end) |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
162 p = end; |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
163 assert(p == end || (*p == '\n' && p[1] == '\n')); |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
164 // The first paragraph is the summary. |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
165 summary = new Section("", makeString(sectionBegin, p)); |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
166 sections ~= summary; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
167 // The rest is the description section. |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
168 if (p < end) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
169 { |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
170 skipWhitespace(p); |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
171 sectionBegin = p; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
172 if (p < end) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
173 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
174 description = new Section("", makeString(sectionBegin, end)); |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
175 sections ~= description; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
176 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
177 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
178 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
179 |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
180 /// Returns true if p points to "$(DDD)". |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
181 bool isCodeSection(char* p, char* end) |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
182 { |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
183 return p+2 < end && *p == '-' && p[1] == '-' && p[2] == '-'; |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
184 } |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
185 |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
186 /// Skips over a code section. |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
187 /// |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
188 /// Note that dmd apparently doesn't skip over code sections when |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
189 /// parsing DDoc sections. However, from experience it seems |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
190 /// to be a good idea to do that. |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
191 void skipCodeSection(ref char* p, char* end) |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
192 out { assert(p+1 == end || *p == '-'); } |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
193 body |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
194 { |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
195 assert(isCodeSection(p, end)); |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
196 |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
197 while (p < end && *p == '-') |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
198 p++; |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
199 p--; |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
200 while (++p < end) |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
201 if (p+2 < end && *p == '-' && p[1] == '-' && p[2] == '-') |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
202 break; |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
203 while (p < end && *p == '-') |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
204 p++; |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
205 p--; |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
206 } |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
207 |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
208 void skipWhitespace(ref char* p) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
209 { |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
210 while (p < textEnd && (isspace(*p) || *p == '\n')) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
211 p++; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
212 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
213 |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
214 /// Find next "Identifier:". |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
215 /// Params: |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
216 /// ident = set to the Identifier. |
745 | 217 /// bodyBegin = set to the beginning of the text body (whitespace skipped.) |
769
5e3ef1b2011c
Added and improved documentation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
754
diff
changeset
|
218 /// Returns: true if found. |
745 | 219 bool findNextIdColon(ref char[] ident, ref char* bodyBegin) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
220 { |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
221 while (p < textEnd) |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
222 { |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
223 skipWhitespace(p); |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
224 if (p >= textEnd) |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
225 break; |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
226 if (isCodeSection(p, textEnd)) |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
227 { |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
228 skipCodeSection(p, textEnd); |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
229 p++; |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
230 continue; |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
231 } |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
232 assert(isascii(*p) || isLeadByte(*p)); |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
233 auto idBegin = p; |
722
ceaac6a24258
Added isUnicodeAlpha() for DDocParser and MacroParser.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
718
diff
changeset
|
234 if (isidbeg(*p) || isUnicodeAlpha(p, textEnd)) // IdStart |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
235 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
236 do // IdChar* |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
237 p++; |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
238 while (p < textEnd && (isident(*p) || isUnicodeAlpha(p, textEnd))) |
745 | 239 auto idEnd = p; |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
240 if (p < textEnd && *p == ':') // : |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
241 { |
745 | 242 p++; |
243 skipWhitespace(p); | |
244 bodyBegin = p; | |
245 ident = makeString(idBegin, idEnd); | |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
246 return true; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
247 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
248 } |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
249 // Skip this line. |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
250 while (p < textEnd && *p != '\n') |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
251 p++; |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
252 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
253 return false; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
254 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
255 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
256 |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
257 /// Represents a DDoc section. |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
258 class Section |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
259 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
260 string name; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
261 string text; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
262 this(string name, string text) |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
263 { |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
264 this.name = name; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
265 this.text = text; |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
266 } |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
267 |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
268 /// Case-insensitively compares the section's name with name2. |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
269 bool Is(char[] name2) |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
270 { |
746
32a8ddd330f8
Using icompare() instead of toLower().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
745
diff
changeset
|
271 return icompare(name, name2) == 0; |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
272 } |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
273 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
274 |
728
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
275 class ParamsSection : Section |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
276 { |
728
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
277 string[] paramNames; /// Parameter names. |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
278 string[] paramDescs; /// Parameter descriptions. |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
279 this(string name, string text) |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
280 { |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
281 super(name, text); |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
282 IdentValueParser parser; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
283 auto idvalues = parser.parse(text); |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
284 this.paramNames = new string[idvalues.length]; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
285 this.paramDescs = new string[idvalues.length]; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
286 foreach (i, idvalue; idvalues) |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
287 { |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
288 this.paramNames[i] = idvalue.ident; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
289 this.paramDescs[i] = idvalue.value; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
290 } |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
291 } |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
292 } |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
293 |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
294 class MacrosSection : Section |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
295 { |
731
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
296 string[] macroNames; /// Macro names. |
ca7607226caa
Added new module cmd.DDoc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
728
diff
changeset
|
297 string[] macroTexts; /// Macro texts. |
728
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
298 this(string name, string text) |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
299 { |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
300 super(name, text); |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
301 IdentValueParser parser; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
302 auto idvalues = parser.parse(text); |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
303 this.macroNames = new string[idvalues.length]; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
304 this.macroTexts = new string[idvalues.length]; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
305 foreach (i, idvalue; idvalues) |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
306 { |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
307 this.macroNames[i] = idvalue.ident; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
308 this.macroTexts[i] = idvalue.value; |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
309 } |
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
310 } |
716
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
311 } |
08e6174a2e1c
Added class DDocComment.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
714
diff
changeset
|
312 |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
313 /// Returns true if token is a Doxygen comment. |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
314 bool isDoxygenComment(Token* token) |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
315 { // Doxygen: '/+!' '/*!' '//!' |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
316 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
|
317 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
318 |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
319 /// Returns true if token is a DDoc comment. |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
320 bool isDDocComment(Token* token) |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
321 { // DDOC: '/++' '/**' '///' |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
322 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
|
323 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
324 |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
325 /// Returns the surrounding documentation comment tokens. |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
326 /// Params: |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
327 /// node = the node to find doc comments for. |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
328 /// isDocComment = a function predicate that checks for doc comment tokens. |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
329 /// Note: this function works correctly only if |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
330 /// the source text is syntactically correct. |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
331 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
|
332 { |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
333 Token*[] comments; |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
334 auto isEnumMember = node.kind == NodeKind.EnumMemberDeclaration; |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
335 // Get preceding comments. |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
336 auto token = node.begin; |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
337 // 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
|
338 Loop: |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
339 for (; token; token = token.prev) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
340 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
341 if (token.kind == TOK.LBrace || |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
342 token.kind == TOK.RBrace || |
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
343 token.kind == TOK.Semicolon || |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
344 /+token.kind == TOK.HEAD ||+/ |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
345 (isEnumMember && token.kind == TOK.Comma)) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
346 break; |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
347 |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
348 if (token.kind == TOK.Comment) |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
349 { // 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
|
350 switch (token.prev.kind) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
351 { |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
352 case TOK.Semicolon, TOK.RBrace, TOK.Comma: |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
353 break Loop; |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
354 default: |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
355 if (isDocComment(token)) |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
356 comments = [token] ~ comments; |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
357 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
358 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
359 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
360 // Get single comment to the right. |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
361 token = node.end.next; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
362 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
|
363 comments ~= token; |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
364 else if (isEnumMember) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
365 { |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
366 token = node.end.nextNWS; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
367 if (token.kind == TOK.Comma) |
676
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
368 { |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
369 token = token.next; |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
676
diff
changeset
|
370 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
|
371 comments ~= token; |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
372 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
373 } |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
374 return comments; |
c4e3a34e40f1
Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
375 } |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
376 |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
377 bool isLineComment(Token* t) |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
378 { |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
379 assert(t.kind == TOK.Comment); |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
380 return t.start[1] == '/'; |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
381 } |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
382 |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
383 /// 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
|
384 string getDDocText(Token*[] tokens) |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
385 { |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
386 if (tokens.length == 0) |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
387 return null; |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
388 string result; |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
389 foreach (token; tokens) |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
390 { |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
391 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
|
392 result ~= sanitize(token.srcText[3 .. $-n], token.start[1]); |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
393 assert(token.next); |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
394 if (token.next.kind == TOK.Newline) |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
395 result ~= \n; |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
396 else |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
397 result ~= ' '; |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
398 } |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
399 // Stdout.formatln("→{}←", result); |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
400 return result[0..$-1]; // Remove \n or ' ' |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
401 } |
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
402 |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
403 /// Sanitizes a DDoc comment string. |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
784
diff
changeset
|
404 /// |
714
140469ecb90e
Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
712
diff
changeset
|
405 /// 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
|
406 /// 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
|
407 /// Params: |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
408 /// 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
|
409 /// commentChar = '/', '+', or '*' |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
410 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
|
411 { |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
412 alias comment result; |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
413 |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
414 bool newline = true; // True when at the beginning of a new line. |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
415 uint i, j; |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
416 auto len = result.length; |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
417 for (; i < len; i++, j++) |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
418 { |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
419 if (newline) |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
420 { // 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
|
421 newline = false; |
754
c7a5499faa77
Improved DDoc related code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
751
diff
changeset
|
422 auto begin = i; |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
423 while (i < len && isspace(result[i])) |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
424 i++; |
754
c7a5499faa77
Improved DDoc related code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
751
diff
changeset
|
425 if (i < len && result[i] == commentChar) |
c7a5499faa77
Improved DDoc related code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
751
diff
changeset
|
426 while (++i < len && result[i] == commentChar) |
c7a5499faa77
Improved DDoc related code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
751
diff
changeset
|
427 {} |
c7a5499faa77
Improved DDoc related code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
751
diff
changeset
|
428 else |
c7a5499faa77
Improved DDoc related code.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
751
diff
changeset
|
429 i = begin; // Reset. No commentChar found. |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
430 if (i >= len) |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
431 break; |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
432 } |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
433 // Check for Newline. |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
434 switch (result[i]) |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
435 { |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
436 case '\r': |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
437 if (i+1 < len && result[i+1] == '\n') |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
438 i++; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
439 case '\n': |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
440 result[j] = '\n'; // Copy Newline as '\n'. |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
441 newline = true; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
442 continue; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
443 default: |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
444 if (!isascii(result[i]) && i+2 < len && isUnicodeNewline(result.ptr + i)) |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
445 { |
739
49fe21aa387c
Added sanitizeText() to dil.Converter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
737
diff
changeset
|
446 i += 2; |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
447 goto case '\n'; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
448 } |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
449 } |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
450 // Copy character. |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
451 result[j] = result[i]; |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
452 } |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
453 result.length = j; // Adjust length. |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
454 // Lastly, strip trailing commentChars. |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
455 if (!result.length) |
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
456 return null; |
728
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
457 i = result.length; |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
458 for (; i && result[i-1] == commentChar; i--) |
728
41cad5ca4863
Added ParamsSection and MacrosSection.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
722
diff
changeset
|
459 {} |
737
f88b5285b86b
Implemented DDocEmitter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
731
diff
changeset
|
460 result.length = i; |
712
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
461 return result; |
f8875ef9a66d
Added function sanitize() to dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
680
diff
changeset
|
462 } |