nsgmls: remove register keyword
[oweals/cde.git] / cde / programs / nsgmls / Syntax.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: Syntax.h /main/1 1996/07/29 17:06:04 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef Syntax_INCLUDED
28 #define Syntax_INCLUDED 1
29 #ifdef __GNUG__
30 #pragma interface
31 #endif
32
33 #include "types.h"
34 #include "Boolean.h"
35 #include "ISet.h"
36 #include "StringC.h"
37 #include "SubstTable.h"
38 #include "HashTable.h"
39 #include "Vector.h"
40 #include "Resource.h"
41 #include "XcharMap.h"
42 #include "EntityCatalog.h"
43
44 #ifdef SP_NAMESPACE
45 namespace SP_NAMESPACE {
46 #endif
47
48 class Sd;
49 class CharsetInfo;
50
51 class SP_API Syntax : public Resource, public EntityCatalog::Syntax {
52 public:
53   enum ReservedName {
54     rANY,
55     rATTLIST,
56     rCDATA,
57     rCONREF,
58     rCURRENT,
59     rDEFAULT,
60     rDOCTYPE,
61     rELEMENT,
62     rEMPTY,
63     rENDTAG,
64     rENTITIES,
65     rENTITY,
66     rFIXED,
67     rID,
68     rIDLINK,
69     rIDREF,
70     rIDREFS,
71     rIGNORE,
72     rIMPLIED,
73     rINCLUDE,
74     rINITIAL,
75     rLINK,
76     rLINKTYPE,
77     rMD,
78     rMS,
79     rNAME,
80     rNAMES,
81     rNDATA,
82     rNMTOKEN,
83     rNMTOKENS,
84     rNOTATION,
85     rNUMBER,
86     rNUMBERS,
87     rNUTOKEN,
88     rNUTOKENS,
89     rO,
90     rPCDATA,
91     rPI,
92     rPOSTLINK,
93     rPUBLIC,
94     rRCDATA,
95     rRE,
96     rREQUIRED,
97     rRESTORE,
98     rRS,
99     rSDATA,
100     rSHORTREF,
101     rSIMPLE,
102     rSPACE,
103     rSTARTTAG,
104     rSUBDOC,
105     rSYSTEM,
106     rTEMP,
107     rUSELINK,
108     rUSEMAP
109   };
110   enum { nNames = rUSEMAP + 1 };
111   enum Quantity {
112     qATTCNT,
113     qATTSPLEN,
114     qBSEQLEN,
115     qDTAGLEN,
116     qDTEMPLEN,
117     qENTLVL,
118     qGRPCNT,
119     qGRPGTCNT,
120     qGRPLVL,
121     qLITLEN,
122     qNAMELEN,
123     qNORMSEP,
124     qPILEN,
125     qTAGLEN,
126     qTAGLVL
127   };
128   enum { nQuantity = qTAGLVL + 1 };
129   enum DelimGeneral {
130     dAND,
131     dCOM,
132     dCRO,
133     dDSC,
134     dDSO,
135     dDTGC,
136     dDTGO,
137     dERO,
138     dETAGO,
139     dGRPC,
140     dGRPO,
141     dLIT,
142     dLITA,
143     dMDC,
144     dMDO,
145     dMINUS,
146     dMSC,
147     dNET,
148     dOPT,
149     dOR,
150     dPERO,
151     dPIC,
152     dPIO,
153     dPLUS,
154     dREFC,
155     dREP,
156     dRNI,
157     dSEQ,
158     dSTAGO,
159     dTAGC,
160     dVI
161   };
162   enum { nDelimGeneral = dVI + 1 };
163   enum StandardFunction {
164     fRE,
165     fRS,
166     fSPACE
167   };
168   enum FunctionClass {
169     cFUNCHAR,
170     cSEPCHAR,
171     cMSOCHAR,
172     cMSICHAR,
173     cMSSCHAR
174   };
175   enum Set {
176     nameStart,
177     digit,
178     nmchar,                     // LCNMCHAR or UCNMCHAR
179     s,
180     blank,
181     sepchar,
182     minimumData,
183     significant,
184     functionChar,               // function character
185     sgmlChar
186   };
187   enum { nSet = sgmlChar + 1 };
188   enum Category {
189     otherCategory = 0,
190     sCategory = 01,
191     nameStartCategory = 02,
192     digitCategory = 04,
193     otherNameCategory = 010
194     };
195
196   Syntax(const Sd &);
197   Syntax(const Syntax &);
198   Boolean lookupFunctionChar(const StringC &, Char *) const;
199   Boolean charFunctionName(Char c, const StringC *&name) const;
200   Boolean lookupReservedName(const StringC &, ReservedName *) const;
201   const StringC &reservedName(ReservedName) const;
202   StringC rniReservedName(ReservedName) const;
203   Number quantity(Quantity) const;
204   Char standardFunction(int) const;
205   Boolean getStandardFunction(int, Char &) const;
206   const StringC &delim() const;
207   const ISet<Char> *charSet(int i) const;
208   const SubstTable<Char> *generalSubstTable() const;
209   const SubstTable<Char> *entitySubstTable() const;
210   const SubstTable<Char> &upperSubstTable() const;
211   Boolean namecaseGeneral() const;
212   Boolean namecaseEntity() const;
213   const StringC &peroDelim() const;
214   const StringC &delimGeneral(int) const;
215   const StringC &delimShortrefComplex(size_t) const;
216   const ISet<Char> &delimShortrefSimple() const;
217   int nDelimShortrefComplex() const;
218   Boolean isValidShortref(const StringC &) const;
219   Boolean hasShortrefs() const;
220   Boolean isNameCharacter(Xchar) const;
221   Boolean isNameStartCharacter(Xchar) const;
222   Boolean isDigit(Xchar) const;
223   Boolean isS(Xchar) const;
224   Boolean isB(Xchar c) const;
225   Category charCategory(Xchar) const;
226   Boolean isSgmlChar(Xchar) const;
227   size_t attcnt() const;
228   size_t attsplen() const;
229   size_t namelen() const;
230   size_t penamelen() const;
231   size_t litlen() const;
232   size_t normsep() const;
233   size_t dtemplen() const;
234   size_t grpcnt() const;
235   size_t grpgtcnt() const;
236   size_t grplvl() const;
237   size_t taglvl() const;
238   size_t taglen() const;
239   size_t entlvl() const;
240   size_t pilen() const;
241   Char space() const;
242   
243   void setStandardFunction(StandardFunction, Char);
244   void enterStandardFunctionNames();
245   void addFunctionChar(const StringC &, FunctionClass, Char);
246   void setNamecaseGeneral(Boolean);
247   void setNamecaseEntity(Boolean);
248   void setDelimGeneral(int, const StringC &);
249   void addDelimShortref(const StringC &, const CharsetInfo &);
250   void addDelimShortrefs(const ISet<Char> &shortrefChars,
251                          const CharsetInfo &charset);
252   void addNameCharacters(const ISet<Char> &);
253   void addNameStartCharacters(const ISet<Char> &);
254   void addSubst(Char lc, Char uc);
255   void addShunchar(Char);
256   void setShuncharControls();
257   void setQuantity(int, Number);
258   void setName(int, const StringC &);
259   void setSgmlChar(const ISet<Char> &);
260   void implySgmlChar(const CharsetInfo &docCharset);
261   // :: is for Watcom 10.0a
262   void checkSgmlChar(const CharsetInfo &docCharset,
263                      const /* ::SP_NAMESPACE_SCOPE */ Syntax *otherSyntax,
264                      ISet<WideChar> &invalid)
265        const;
266   static int referenceQuantity(Quantity);
267   const XcharMap<unsigned char> &markupScanTable() const;
268   Boolean multicode() const;
269 private:
270   void subst(Char, Char);
271   void checkUnivControlChar(UnivChar univChar,
272                             const CharsetInfo &docCharset,
273                             const /* ::SP_NAMESPACE_SCOPE */ Syntax *otherSyntax,
274                             ISet<WideChar> &invalid) const;
275
276   ISet<Char> shunchar_;
277   PackedBoolean shuncharControls_;
278   ISet<Char> set_[nSet];
279   Char standardFunction_[3];
280   PackedBoolean standardFunctionValid_[3];
281   Boolean namecaseGeneral_;
282   Boolean namecaseEntity_;
283   StringC delimGeneral_[nDelimGeneral];
284   Vector<StringC> delimShortrefComplex_;
285   ISet<Char> delimShortrefSimple_;
286   StringC names_[nNames];
287   Number quantity_[nQuantity];
288   HashTable<StringC,int> nameTable_;
289   HashTable<StringC,Char> functionTable_;
290   SubstTable<Char> upperSubst_;
291   SubstTable<Char> identitySubst_;
292   const SubstTable<Char> *generalSubst_;
293   const SubstTable<Char> *entitySubst_;
294   XcharMap<unsigned char> categoryTable_;
295   Boolean multicode_;
296   XcharMap<unsigned char> markupScanTable_;
297   static const int referenceQuantity_[];
298 };
299
300 inline Number Syntax::quantity(Quantity q) const
301 {
302   return quantity_[q];
303 }
304
305 inline void Syntax::setQuantity(int i, Number n)
306 {
307   quantity_[i] = n;
308 }
309
310 inline const SubstTable<Char> *Syntax::generalSubstTable() const
311 {
312   return generalSubst_;
313 }
314
315 inline const SubstTable<Char> *Syntax::entitySubstTable() const
316 {
317   return entitySubst_;
318 }
319
320 inline int Syntax::nDelimShortrefComplex() const
321 {
322   return int(delimShortrefComplex_.size());
323 }
324
325 inline const StringC &Syntax::delimGeneral(int i) const
326 {
327   return delimGeneral_[i];
328 }
329
330 inline const StringC &Syntax::delimShortrefComplex(size_t i) const
331 {
332   return delimShortrefComplex_[i];
333 }
334
335 inline const ISet<Char> &Syntax::delimShortrefSimple() const
336 {
337   return delimShortrefSimple_;
338 }
339
340 inline Boolean Syntax::hasShortrefs() const
341 {
342   return delimShortrefComplex_.size() > 0 || !delimShortrefSimple_.isEmpty();
343 }
344
345 inline Char Syntax::standardFunction(int i) const
346 {
347   return standardFunction_[i];
348 }
349
350 inline Boolean Syntax::getStandardFunction(int i, Char &result) const
351 {
352   if (standardFunctionValid_[i]) {
353     result = standardFunction_[i];
354     return 1;
355   }
356   else
357     return 0;
358 }
359
360 inline const ISet<Char> *Syntax::charSet(int i) const
361 {
362   return &set_[i];
363 }
364
365 inline Boolean Syntax::isNameCharacter(Xchar c) const
366 {
367   return categoryTable_[c] >= nameStartCategory;
368 }
369
370 inline Boolean Syntax::isNameStartCharacter(Xchar c) const
371 {
372   return categoryTable_[c] == nameStartCategory;
373 }
374
375 inline Boolean Syntax::isDigit(Xchar c) const
376 {
377   return categoryTable_[c] == digitCategory;
378 }
379
380 inline Boolean Syntax::isS(Xchar c) const
381 {
382   return categoryTable_[c] == sCategory;
383 }
384
385 inline Boolean Syntax::isB(Xchar c) const
386 {
387   return (categoryTable_[c] == sCategory
388           && !(standardFunctionValid_[fRE] && c == standardFunction_[fRE])
389           && !(standardFunctionValid_[fRS] && c == standardFunction_[fRS]));
390 }
391
392 inline Syntax::Category Syntax::charCategory(Xchar c) const
393 {
394   return Category(categoryTable_[c]);
395 }
396
397 inline Boolean Syntax::isSgmlChar(Xchar c) const
398 {
399   return c >= 0 && set_[sgmlChar].contains(Char(c));
400 }
401
402 inline const StringC &Syntax::reservedName(ReservedName i) const
403 {
404   return names_[i];
405 }
406
407 inline size_t Syntax::attcnt() const
408 {
409   return quantity(qATTCNT);
410 }
411
412 inline size_t Syntax::attsplen() const
413 {
414   return quantity(qATTSPLEN);
415 }
416
417 inline size_t Syntax::namelen() const
418 {
419   return quantity(qNAMELEN);
420 }
421
422 inline size_t Syntax::penamelen() const
423 {
424   return quantity(qNAMELEN) - delimGeneral(dPERO).size();
425 }
426
427 inline size_t Syntax::litlen() const
428 {
429   return quantity(qLITLEN);
430 }
431
432 inline size_t Syntax::normsep() const
433 {
434   return quantity(qNORMSEP);
435 }
436
437 inline size_t Syntax::dtemplen() const
438 {
439   return quantity(qDTEMPLEN);
440 }
441
442 inline size_t Syntax::grpcnt() const
443 {
444   return quantity(qGRPCNT);
445 }
446
447 inline size_t Syntax::grpgtcnt() const
448 {
449   return quantity(qGRPGTCNT);
450 }
451
452 inline size_t Syntax::grplvl() const
453 {
454   return quantity(qGRPLVL);
455 }
456
457 inline size_t Syntax::taglvl() const
458 {
459   return quantity(qTAGLVL);
460 }
461
462 inline size_t Syntax::taglen() const
463 {
464   return quantity(qTAGLEN);
465 }
466
467 inline size_t Syntax::entlvl() const
468 {
469   return quantity(qENTLVL);
470 }
471
472 inline size_t Syntax::pilen() const
473 {
474   return quantity(qPILEN);
475 }
476
477 inline Char Syntax::space() const
478 {
479   return standardFunction(fSPACE);
480 }
481
482 inline void Syntax::setSgmlChar(const ISet<Char> &set)
483 {
484   set_[sgmlChar] = set;
485 }
486
487 inline int Syntax::referenceQuantity(Quantity i)
488 {
489   return referenceQuantity_[i];
490 }
491
492 inline void Syntax::setShuncharControls()
493 {
494   shuncharControls_ = 1;
495 }
496
497 inline const XcharMap<unsigned char> &Syntax::markupScanTable() const
498 {
499   return markupScanTable_;
500 }
501
502 inline Boolean Syntax::multicode() const
503 {
504   return multicode_;
505 }
506
507 inline Boolean Syntax::namecaseGeneral() const
508 {
509   return namecaseGeneral_;
510 }
511
512 inline Boolean Syntax::namecaseEntity() const
513 {
514   return namecaseEntity_;
515 }
516
517 #ifdef SP_NAMESPACE
518 }
519 #endif
520
521 #endif /* Syntax_INCLUDED */