1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 #include <precomp.h>
23 #include <adoc/docu_pe.hxx>
24
25
26 // NOT FULLY DEFINED SERVICES
27 #include <ary/doc/d_oldcppdocu.hxx>
28 #include <ary/info/ci_attag.hxx>
29 #include <ary/info/ci_text.hxx>
30 #include <adoc/adoc_tok.hxx>
31 #include <adoc/tk_attag.hxx>
32 #include <adoc/tk_docw.hxx>
33
34
35 namespace adoc
36 {
37
38
39 inline bool
UsesHtmlInDocuText()40 Adoc_PE::UsesHtmlInDocuText()
41 {
42 return bUsesHtmlInDocuText;
43 }
44
45
46
47
Adoc_PE()48 Adoc_PE::Adoc_PE()
49 : pCurDocu(0),
50 pCurAtTag(0),
51 nLineCountInDocu(0),
52 nCurSpecialMeaningTokens(0),
53 nCurSubtractFromLineStart(0),
54 eCurTagState(ts_new),
55 eDocuState(ds_wait_for_short),
56 bIsComplete(false),
57 bUsesHtmlInDocuText(false)
58 {
59 }
60
~Adoc_PE()61 Adoc_PE::~Adoc_PE()
62 {
63 }
64
65 void
Hdl_at_std(const Tok_at_std & i_rTok)66 Adoc_PE::Hdl_at_std( const Tok_at_std & i_rTok )
67 {
68 InstallAtTag(
69 CurDocu().Create_StdTag(i_rTok.Id()) );
70 }
71
72 void
Hdl_at_base(const Tok_at_base &)73 Adoc_PE::Hdl_at_base( const Tok_at_base & )
74 {
75 InstallAtTag(
76 CurDocu().CheckIn_BaseTag() );
77 }
78
79 void
Hdl_at_exception(const Tok_at_exception &)80 Adoc_PE::Hdl_at_exception( const Tok_at_exception & )
81 {
82 InstallAtTag(
83 CurDocu().CheckIn_ExceptionTag() );
84 }
85
86 void
Hdl_at_impl(const Tok_at_impl &)87 Adoc_PE::Hdl_at_impl( const Tok_at_impl & )
88 {
89 InstallAtTag(
90 CurDocu().Create_ImplementsTag() );
91 }
92
93 void
Hdl_at_key(const Tok_at_key &)94 Adoc_PE::Hdl_at_key( const Tok_at_key & )
95 {
96 InstallAtTag(
97 CurDocu().Create_KeywordTag() );
98 }
99
100 void
Hdl_at_param(const Tok_at_param &)101 Adoc_PE::Hdl_at_param( const Tok_at_param & )
102 {
103 InstallAtTag(
104 CurDocu().CheckIn_ParameterTag() );
105 }
106
107 void
Hdl_at_see(const Tok_at_see &)108 Adoc_PE::Hdl_at_see( const Tok_at_see & )
109 {
110 InstallAtTag(
111 CurDocu().CheckIn_SeeTag() );
112 }
113
114 void
Hdl_at_template(const Tok_at_template &)115 Adoc_PE::Hdl_at_template( const Tok_at_template & )
116 {
117 InstallAtTag(
118 CurDocu().CheckIn_TemplateTag() );
119 }
120
121 void
Hdl_at_interface(const Tok_at_interface &)122 Adoc_PE::Hdl_at_interface( const Tok_at_interface & )
123 {
124 CurDocu().Set_Interface();
125 }
126
127 void
Hdl_at_internal(const Tok_at_internal &)128 Adoc_PE::Hdl_at_internal( const Tok_at_internal & )
129 {
130 CurDocu().Set_Internal();
131 }
132
133 void
Hdl_at_obsolete(const Tok_at_obsolete &)134 Adoc_PE::Hdl_at_obsolete( const Tok_at_obsolete & )
135 {
136 CurDocu().Set_Obsolete();
137 }
138
139 void
Hdl_at_module(const Tok_at_module &)140 Adoc_PE::Hdl_at_module( const Tok_at_module & )
141 {
142 // KORR_FUTURE
143
144 // pCurAtTag = CurDocu().Assign2_ModuleTag();
145 // nCurSpecialMeaningTokens = pCurAtTag->NrOfSpecialMeaningTokens();
146 }
147
148 void
Hdl_at_file(const Tok_at_file &)149 Adoc_PE::Hdl_at_file( const Tok_at_file & )
150 {
151 // KORR_FUTURE
152
153 // pCurAtTag = CurDocu().Assign2_FileTag();
154 // nCurSpecialMeaningTokens = pCurAtTag->NrOfSpecialMeaningTokens();
155 }
156
157 void
Hdl_at_gloss(const Tok_at_gloss &)158 Adoc_PE::Hdl_at_gloss( const Tok_at_gloss & )
159 {
160 // KORR_FUTURE
161
162 // Create_GlossaryEntry();
163 }
164
165 void
Hdl_at_global(const Tok_at_global &)166 Adoc_PE::Hdl_at_global( const Tok_at_global & )
167 {
168 // KORR_FUTURE
169 // Create_GlobalTextComponent();
170 }
171
172 void
Hdl_at_include(const Tok_at_include &)173 Adoc_PE::Hdl_at_include( const Tok_at_include & )
174 {
175 // KORR_FUTURE
176 }
177
178 void
Hdl_at_label(const Tok_at_label &)179 Adoc_PE::Hdl_at_label( const Tok_at_label & )
180 {
181 InstallAtTag(
182 CurDocu().Create_LabelTag() );
183 }
184
185 void
Hdl_at_since(const Tok_at_since &)186 Adoc_PE::Hdl_at_since( const Tok_at_since & )
187 {
188 InstallAtTag(
189 CurDocu().Create_SinceTag() );
190 }
191
192 void
Hdl_at_HTML(const Tok_at_HTML &)193 Adoc_PE::Hdl_at_HTML( const Tok_at_HTML & )
194 {
195 bUsesHtmlInDocuText = true;
196 }
197
198 void
Hdl_at_NOHTML(const Tok_at_NOHTML &)199 Adoc_PE::Hdl_at_NOHTML( const Tok_at_NOHTML & )
200 {
201 bUsesHtmlInDocuText = false;
202 }
203
204 void
Hdl_DocWord(const Tok_DocWord & i_rTok)205 Adoc_PE::Hdl_DocWord( const Tok_DocWord & i_rTok )
206 {
207 bool bIsSpecial = false;
208 if ( nCurSpecialMeaningTokens > 0 )
209 {
210 bIsSpecial = CurAtTag().Add_SpecialMeaningToken(
211 i_rTok.Text(),
212 CurAtTag().NrOfSpecialMeaningTokens()
213 - (--nCurSpecialMeaningTokens) );
214 }
215
216 if ( NOT bIsSpecial )
217 {
218 if ( eDocuState == ds_wait_for_short OR eDocuState == ds_1newline_after_short )
219 eDocuState = ds_in_short;
220 if (nLineCountInDocu == 0)
221 nLineCountInDocu = 1;
222
223 uintt nLength = i_rTok.Length();
224 if ( nLength > 2 )
225 {
226 bool bMaybeGlobalLink = strncmp( "::", i_rTok.Text(), 2 ) == 0;
227 bool bMayBeFunction = *(i_rTok.Text() + nLength - 2) == '('
228 AND *(i_rTok.Text() + nLength - 1) == ')';
229 if ( bMaybeGlobalLink OR bMayBeFunction )
230 {
231 CurAtTag().Add_PotentialLink( i_rTok.Text(),
232 bMaybeGlobalLink,
233 bMayBeFunction );
234 return;
235 }
236 }
237
238 CurAtTag().Add_Token( i_rTok.Text() );
239 eCurTagState = ts_std;
240 }
241 }
242
243 void
Hdl_Whitespace(const Tok_Whitespace & i_rTok)244 Adoc_PE::Hdl_Whitespace( const Tok_Whitespace & i_rTok )
245 {
246 if ( eCurTagState == ts_std )
247 {
248
249 CurAtTag().Add_Whitespace(i_rTok.Size());
250 }
251 }
252
253 void
Hdl_LineStart(const Tok_LineStart & i_rTok)254 Adoc_PE::Hdl_LineStart( const Tok_LineStart & i_rTok )
255 {
256 if ( pCurAtTag == 0 )
257 return;
258
259 if ( nLineCountInDocu == 2 )
260 {
261 nCurSubtractFromLineStart = i_rTok.Size();
262 eCurTagState = ts_std;
263 }
264 else if ( nLineCountInDocu > 2 )
265 {
266 if ( i_rTok.Size() > nCurSubtractFromLineStart )
267 {
268 CurAtTag().Add_Whitespace( i_rTok.Size()
269 - nCurSubtractFromLineStart );
270 }
271 // else do nothing, because there is no whitespace.
272 }
273 }
274
275 void
Hdl_Eol(const Tok_Eol &)276 Adoc_PE::Hdl_Eol( const Tok_Eol & )
277 {
278 if ( pCurAtTag == 0 )
279 return;
280
281 nLineCountInDocu++;
282
283 if ( nCurSpecialMeaningTokens == 0 )
284 {
285 CurAtTag().Add_Eol();
286
287 switch ( eDocuState )
288 {
289 case ds_wait_for_short: break;
290 case ds_in_short: if ( nLineCountInDocu < 4 )
291 eDocuState = ds_1newline_after_short;
292 else
293 {
294 RenameCurShortTag();
295 eDocuState = ds_in_descr;
296 }
297 break;
298 case ds_1newline_after_short: FinishCurShortTag();
299 eDocuState = ds_in_descr;
300 break;
301 default:
302 ; // Do noting.
303 }
304 }
305 else
306 {
307 nCurSpecialMeaningTokens = 0;
308 }
309
310
311 }
312
313 void
Hdl_EoDocu(const Tok_EoDocu &)314 Adoc_PE::Hdl_EoDocu( const Tok_EoDocu & )
315 {
316 bIsComplete = true;
317 }
318
319 DYN ary::doc::OldCppDocu *
ReleaseJustParsedDocu()320 Adoc_PE::ReleaseJustParsedDocu()
321 {
322 pCurAtTag = 0;
323 nLineCountInDocu = 0;
324 nCurSpecialMeaningTokens = 0;
325 nCurSubtractFromLineStart = 0;
326 eCurTagState = ts_new;
327 eDocuState = ds_wait_for_short;
328 bIsComplete = false;
329 return pCurDocu.Release();
330 }
331
332 void
InstallAtTag(DYN ary::info::AtTag * let_dpTag,bool i_bImplicit)333 Adoc_PE::InstallAtTag( DYN ary::info::AtTag * let_dpTag,
334 bool i_bImplicit )
335 {
336 pCurAtTag = let_dpTag;
337 if ( pCurAtTag != 0 )
338 {
339 nCurSpecialMeaningTokens = pCurAtTag->NrOfSpecialMeaningTokens();
340 pCurAtTag->Set_HtmlUseInDocuText( bUsesHtmlInDocuText );
341 }
342
343 eCurTagState = ts_new;
344 if ( NOT i_bImplicit )
345 eDocuState = ds_std;
346 }
347
348 ary::doc::OldCppDocu &
CurDocu()349 Adoc_PE::CurDocu()
350 {
351 if (NOT pCurDocu)
352 pCurDocu = new ary::doc::OldCppDocu;
353 return *pCurDocu;
354 }
355
356 ary::info::AtTag &
CurAtTag()357 Adoc_PE::CurAtTag()
358 {
359 if (NOT pCurAtTag)
360 {
361 if ( int(eDocuState) < int(ds_in_descr) )
362 {
363 InstallAtTag(
364 CurDocu().Create_StdTag(ary::info::atid_short),
365 true );
366 }
367 else
368 {
369 InstallAtTag(
370 CurDocu().Create_StdTag(ary::info::atid_descr),
371 true );
372 }
373 }
374 return *pCurAtTag;
375 }
376
377 void
RenameCurShortTag()378 Adoc_PE::RenameCurShortTag()
379 {
380 CurDocu().Replace_AtShort_By_AtDescr();
381 }
382
383 void
FinishCurShortTag()384 Adoc_PE::FinishCurShortTag()
385 {
386 InstallAtTag(
387 CurDocu().Create_StdTag(ary::info::atid_descr),
388 true );
389 }
390
391
392 } // namespace adoc
393
394
395
396
397
398