2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
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.
27 #ifndef Syntax_INCLUDED
28 #define Syntax_INCLUDED 1
37 #include "SubstTable.h"
38 #include "HashTable.h"
42 #include "EntityCatalog.h"
45 namespace SP_NAMESPACE {
51 class SP_API Syntax : public Resource, public EntityCatalog::Syntax {
110 enum { nNames = rUSEMAP + 1 };
128 enum { nQuantity = qTAGLVL + 1 };
162 enum { nDelimGeneral = dVI + 1 };
163 enum StandardFunction {
178 nmchar, // LCNMCHAR or UCNMCHAR
184 functionChar, // function character
187 enum { nSet = sgmlChar + 1 };
191 nameStartCategory = 02,
193 otherNameCategory = 010
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;
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)
266 static int referenceQuantity(Quantity);
267 const XcharMap<unsigned char> &markupScanTable() const;
268 Boolean multicode() const;
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;
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_;
296 XcharMap<unsigned char> markupScanTable_;
297 static const int referenceQuantity_[];
300 inline Number Syntax::quantity(Quantity q) const
305 inline void Syntax::setQuantity(int i, Number n)
310 inline const SubstTable<Char> *Syntax::generalSubstTable() const
312 return generalSubst_;
315 inline const SubstTable<Char> *Syntax::entitySubstTable() const
320 inline int Syntax::nDelimShortrefComplex() const
322 return int(delimShortrefComplex_.size());
325 inline const StringC &Syntax::delimGeneral(int i) const
327 return delimGeneral_[i];
330 inline const StringC &Syntax::delimShortrefComplex(size_t i) const
332 return delimShortrefComplex_[i];
335 inline const ISet<Char> &Syntax::delimShortrefSimple() const
337 return delimShortrefSimple_;
340 inline Boolean Syntax::hasShortrefs() const
342 return delimShortrefComplex_.size() > 0 || !delimShortrefSimple_.isEmpty();
345 inline Char Syntax::standardFunction(int i) const
347 return standardFunction_[i];
350 inline Boolean Syntax::getStandardFunction(int i, Char &result) const
352 if (standardFunctionValid_[i]) {
353 result = standardFunction_[i];
360 inline const ISet<Char> *Syntax::charSet(int i) const
365 inline Boolean Syntax::isNameCharacter(Xchar c) const
367 return categoryTable_[c] >= nameStartCategory;
370 inline Boolean Syntax::isNameStartCharacter(Xchar c) const
372 return categoryTable_[c] == nameStartCategory;
375 inline Boolean Syntax::isDigit(Xchar c) const
377 return categoryTable_[c] == digitCategory;
380 inline Boolean Syntax::isS(Xchar c) const
382 return categoryTable_[c] == sCategory;
385 inline Boolean Syntax::isB(Xchar c) const
387 return (categoryTable_[c] == sCategory
388 && !(standardFunctionValid_[fRE] && c == standardFunction_[fRE])
389 && !(standardFunctionValid_[fRS] && c == standardFunction_[fRS]));
392 inline Syntax::Category Syntax::charCategory(Xchar c) const
394 return Category(categoryTable_[c]);
397 inline Boolean Syntax::isSgmlChar(Xchar c) const
399 return c >= 0 && set_[sgmlChar].contains(Char(c));
402 inline const StringC &Syntax::reservedName(ReservedName i) const
407 inline size_t Syntax::attcnt() const
409 return quantity(qATTCNT);
412 inline size_t Syntax::attsplen() const
414 return quantity(qATTSPLEN);
417 inline size_t Syntax::namelen() const
419 return quantity(qNAMELEN);
422 inline size_t Syntax::penamelen() const
424 return quantity(qNAMELEN) - delimGeneral(dPERO).size();
427 inline size_t Syntax::litlen() const
429 return quantity(qLITLEN);
432 inline size_t Syntax::normsep() const
434 return quantity(qNORMSEP);
437 inline size_t Syntax::dtemplen() const
439 return quantity(qDTEMPLEN);
442 inline size_t Syntax::grpcnt() const
444 return quantity(qGRPCNT);
447 inline size_t Syntax::grpgtcnt() const
449 return quantity(qGRPGTCNT);
452 inline size_t Syntax::grplvl() const
454 return quantity(qGRPLVL);
457 inline size_t Syntax::taglvl() const
459 return quantity(qTAGLVL);
462 inline size_t Syntax::taglen() const
464 return quantity(qTAGLEN);
467 inline size_t Syntax::entlvl() const
469 return quantity(qENTLVL);
472 inline size_t Syntax::pilen() const
474 return quantity(qPILEN);
477 inline Char Syntax::space() const
479 return standardFunction(fSPACE);
482 inline void Syntax::setSgmlChar(const ISet<Char> &set)
484 set_[sgmlChar] = set;
487 inline int Syntax::referenceQuantity(Quantity i)
489 return referenceQuantity_[i];
492 inline void Syntax::setShuncharControls()
494 shuncharControls_ = 1;
497 inline const XcharMap<unsigned char> &Syntax::markupScanTable() const
499 return markupScanTable_;
502 inline Boolean Syntax::multicode() const
507 inline Boolean Syntax::namecaseGeneral() const
509 return namecaseGeneral_;
512 inline Boolean Syntax::namecaseEntity() const
514 return namecaseEntity_;
521 #endif /* Syntax_INCLUDED */