annotate src/dil/doc/Doc.d @ 806:bcb74c9b895c

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