DCL 3.7.4
Loading...
Searching...
No Matches
DocParser.cpp
Go to the documentation of this file.
1#include <dcl/Config.h>
2
3#include <wctype.h>
4#include "DocParser.h"
5
6#if __DCL_HAVE_THIS_FILE__
7#undef __THIS_FILE__
8static const char_t __THIS_FILE__[] = __T("src2html/DocParser.cpp");
9#endif
10
11__DCL_BEGIN_NAMESPACE
12
13DocParser::DocParser(const wchar_t* pchData, size_t nDataSize, const DocSyntax* pSyntax)
14{
15 __pSyntax = pSyntax;
16 __pCurrent = pchData;
17 __pEnd = pchData + nDataSize; // *__pEnd == '\0'
18 __DCL_ASSERT(*__pEnd == '\0');
19}
20
29
30#define DATA_SIZE ( __pCurrent - block.pData)
31
33{
34 if (!(__pCurrent < __pEnd))
35 return false;
36
37 ssize_t nLineCommentLength = __pSyntax->__strLineComment.length();
38
39 block.pData = __pCurrent;
40 block.type = normal;
41
42 CurrentState state = inInitial;
43 wchar_t chQuotation = 0;
44 bool bEscape = false;
45
46 while(__pCurrent < __pEnd) {
47 switch (state) {
48 case inInitial: {
49 if (iswspace((unsigned)*__pCurrent))
50 state = inSpace;
51 else if (__pSyntax->isQuotation(*__pCurrent)) {
52 state = inQuotation;
53 chQuotation = *__pCurrent;
54 }
55 else {
56 state = inNormal;
57 continue;
58 }
59 break;
60 }
61 case inSpace: {
62 if (!iswspace(*__pCurrent))
63 goto __done;
64 break;
65 }
66 case inQuotation: {
67 __DCL_ASSERT(chQuotation != 0);
68 if (!bEscape) {
69 if (chQuotation == *__pCurrent) {
70 __pCurrent++;
71 block.type = quotation;
72 goto __done;
73 }
74 if (__pSyntax->isEscapeChar(*__pCurrent))
75 bEscape = true;
76 }
77 else
78 bEscape = false;
79 break;
80 }
81 case inBlockComment: {
82 if (__pSyntax->isCommentOff(block.pData, DATA_SIZE)) {
83 __pCurrent++;
84 block.type = comment;
85 goto __done;
86 }
87 break;
88 }
89 case inLineComment: {
90 if (*__pCurrent == 10) {
91 __pCurrent++;
92 block.type = comment;
93 goto __done;
94 }
95 break;
96 }
97 case inNormal: {
98 if (iswspace(*__pCurrent) || __pSyntax->isDelimeter(*__pCurrent)) {
99 if ((__pCurrent - block.pData) > 0) {
100 if (__pSyntax->isCommentOn(block.pData, DATA_SIZE)) {
101 state = inBlockComment;
102 block.type = comment;
103 }
104 else if (__pSyntax->isLineComment(block.pData, DATA_SIZE)) {
105 state = inLineComment;
106 block.type = comment;
107 }
108 else if (__pSyntax->isReservedWord(block.pData, DATA_SIZE)) {
109 block.type = keyword;
110 goto __done;
111 }
112 else {
113 if (!__pSyntax->isCommentChar(*__pCurrent))
114 goto __done;
115 }
116 }
117 else {
118 if (__pSyntax->isReservedWord(__pCurrent, 1)) {
119 block.type = keyword;
120 }
121
122 if (!__pSyntax->isCommentChar(*__pCurrent)) {
123 __pCurrent++;
124 goto __done;
125 }
126 }
127
128 }
129 else {
130 if ((DATA_SIZE == nLineCommentLength)
131 && __pSyntax->isLineComment(block.pData, DATA_SIZE)
132 ) {
133 state = inLineComment;
134 block.type = comment;
135 }
136 }
137 break;
138 }
139 default: {
140 __DCL_ASSERT(false);
141 }
142 }
143 __pCurrent++;
144 }
145
146__done:
148
149 block.nDataSize = DATA_SIZE;
150
151 return true;
152}
153
154__DCL_END_NAMESPACE
155
#define __THIS_FILE__
Definition _trace.h:14
wchar_t char_t
Definition Config.h:247
CurrentState
Definition DocParser.cpp:21
@ inNormal
Definition DocParser.cpp:27
@ inInitial
Definition DocParser.cpp:22
@ inBlockComment
Definition DocParser.cpp:25
@ inLineComment
Definition DocParser.cpp:26
@ inSpace
Definition DocParser.cpp:23
@ inQuotation
Definition DocParser.cpp:24
#define DATA_SIZE
Definition DocParser.cpp:30
@ quotation
Definition DocParser.h:18
@ comment
Definition DocParser.h:17
@ keyword
Definition DocParser.h:19
@ normal
Definition DocParser.h:16
#define __DCL_ASSERT(expr)
Definition Object.h:394
#define __T(str)
Definition Object.h:60
const wchar_t * __pCurrent
Definition DocParser.h:37
const wchar_t * __pEnd
Definition DocParser.h:38
const DocSyntax * __pSyntax
Definition DocParser.h:36
bool getNextBlock(DOC_BLOCK &block)
Definition DocParser.cpp:32
DocParser(const wchar_t *pchData, size_t nDataSize, const DocSyntax *pSyntax)
Definition DocParser.cpp:13
BlockType type
Definition DocParser.h:26
const wchar_t * pData
Definition DocParser.h:24
size_t nDataSize
Definition DocParser.h:25