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