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__
8
static
const
char_t
__THIS_FILE__
[] =
__T
(
"src2html/DocParser.cpp"
);
9
#endif
10
11
__DCL_BEGIN_NAMESPACE
12
13
DocParser::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
21
enum
CurrentState
{
22
inInitial
,
23
inSpace
,
24
inQuotation
,
25
inBlockComment
,
26
inLineComment
,
27
inNormal
28
};
29
30
#define DATA_SIZE ( __pCurrent - block.pData)
31
32
bool
DocParser::getNextBlock
(
DOC_BLOCK
& block)
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:
147
__DCL_ASSERT
(
__pCurrent
<=
__pEnd
);
148
149
block.
nDataSize
=
DATA_SIZE
;
150
151
return
true
;
152
}
153
154
__DCL_END_NAMESPACE
155
__THIS_FILE__
#define __THIS_FILE__
Definition
_trace.h:14
Config.h
char_t
wchar_t char_t
Definition
Config.h:247
CurrentState
CurrentState
Definition
DocParser.cpp:21
inNormal
@ inNormal
Definition
DocParser.cpp:27
inInitial
@ inInitial
Definition
DocParser.cpp:22
inBlockComment
@ inBlockComment
Definition
DocParser.cpp:25
inLineComment
@ inLineComment
Definition
DocParser.cpp:26
inSpace
@ inSpace
Definition
DocParser.cpp:23
inQuotation
@ inQuotation
Definition
DocParser.cpp:24
DATA_SIZE
#define DATA_SIZE
Definition
DocParser.cpp:30
DocParser.h
quotation
@ quotation
Definition
DocParser.h:18
comment
@ comment
Definition
DocParser.h:17
keyword
@ keyword
Definition
DocParser.h:19
normal
@ normal
Definition
DocParser.h:16
__DCL_ASSERT
#define __DCL_ASSERT(expr)
Definition
Object.h:394
__T
#define __T(str)
Definition
Object.h:60
DocParser::__pCurrent
const wchar_t * __pCurrent
Definition
DocParser.h:37
DocParser::__pEnd
const wchar_t * __pEnd
Definition
DocParser.h:38
DocParser::__pSyntax
const DocSyntax * __pSyntax
Definition
DocParser.h:36
DocParser::getNextBlock
bool getNextBlock(DOC_BLOCK &block)
Definition
DocParser.cpp:32
DocParser::DocParser
DocParser(const wchar_t *pchData, size_t nDataSize, const DocSyntax *pSyntax)
Definition
DocParser.cpp:13
DocSyntax
Definition
DocSyntax.h:19
DOC_BLOCK
Definition
DocParser.h:23
DOC_BLOCK::type
BlockType type
Definition
DocParser.h:26
DOC_BLOCK::pData
const wchar_t * pData
Definition
DocParser.h:24
DOC_BLOCK::nDataSize
size_t nDataSize
Definition
DocParser.h:25
hse
HSAIDoc
DocParser.cpp
Generated by
1.14.0