"Fossies" - the Fresh Open Source Software Archive

Member "OpenSP-1.5.2/lib/Parser.h" (21 Jul 2005, 15335 Bytes) of package /linux/misc/old/OpenSP-1.5.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Parser.h" see the Fossies "Dox" file reference documentation.

    1 // Copyright (c) 1994 James Clark
    2 // See the file COPYING for copying permission.
    3 
    4 #ifndef Parser_INCLUDED
    5 #define Parser_INCLUDED 1
    6 
    7 #ifdef __GNUG__
    8 #pragma interface
    9 #endif
   10 
   11 #include "types.h"
   12 #include "Attribute.h"
   13 #include "Attributed.h"
   14 #include "Boolean.h"
   15 #include "StringC.h"
   16 #include "ElementType.h"
   17 #include "Entity.h"
   18 #include "Event.h"
   19 #include "IList.h"
   20 #include "ISet.h"
   21 #include "Location.h"
   22 #include "Owner.h"
   23 #include "ParserState.h"
   24 #include "Ptr.h"
   25 #include "SgmlParser.h"
   26 #include "StringOf.h"
   27 #include "Undo.h"
   28 #include "Vector.h"
   29 
   30 #ifdef SP_NAMESPACE
   31 namespace SP_NAMESPACE {
   32 #endif
   33 
   34 class AllowedParams;
   35 class Param;
   36 class ExternalId;
   37 class PublicId;
   38 class GroupToken;
   39 class AllowedGroupTokens;
   40 struct GroupConnector;
   41 class AllowedGroupConnectors;
   42 class AllowedSdParams;
   43 class Text;
   44 class AttributeList;
   45 class AttributeDefinition;
   46 class AttributeDefinitionList;
   47 class UnivCharsetDesc;
   48 class CharsetInfo;
   49 class CharsetDecl;
   50 class DeclaredValue;
   51 struct SdBuilder;
   52 struct SdParam;
   53 class Syntax;
   54 class ElementDefinition;
   55 class CharSwitcher;
   56 struct StandardSyntaxSpec;
   57 class Undo;
   58 class Decl;
   59 
   60 class Parser : private ParserState { 
   61 public:
   62   Parser(const SgmlParser::Params &);
   63   Event *nextEvent();
   64   void parseAll(EventHandler &, const volatile sig_atomic_t *cancelPtr);
   65   ParserState::sdPointer;
   66   ParserState::instanceSyntaxPointer;
   67   ParserState::prologSyntaxPointer;
   68   ParserState::activateLinkType;
   69   ParserState::allLinkTypesActivated;
   70   ParserState::entityManager;
   71   ParserState::entityCatalog;
   72   ParserState::baseDtd;
   73   ParserState::options;
   74   ParserState::instantiateDtd;
   75   friend class PiAttspecParser;
   76 private:
   77   Parser(const Parser &);   // undefined
   78   void operator=(const Parser &); // undefined
   79   Boolean setStandardSyntax(Syntax &syn, const StandardSyntaxSpec &,
   80                 const CharsetInfo &docCharset,
   81                 CharSwitcher &,
   82                 Boolean www);
   83   Boolean addRefDelimShortref(Syntax &syntax,
   84                   const CharsetInfo &syntaxCharset,
   85                   const CharsetInfo &docCharset,
   86                   CharSwitcher &switcher);
   87   Boolean setRefDelimGeneral(Syntax &syntax,
   88                  const CharsetInfo &syntaxCharset,
   89                  const CharsetInfo &docCharset,
   90                  CharSwitcher &switcher);
   91   void setRefNames(Syntax &syntax, const CharsetInfo &docCharset, Boolean www);
   92 
   93   void giveUp();
   94   void compileSdModes();
   95   void compilePrologModes();
   96   void compileInstanceModes();
   97   void addNeededShortrefs(Dtd &, const Syntax &);
   98   Boolean shortrefCanPreemptDelim(const StringC &sr,
   99                   const StringC &d,
  100                   Boolean dIsSr,
  101                   const Syntax &);
  102   void compileModes(const Mode *modes, int n, const Dtd *);
  103   void compileNormalMap();
  104 
  105   void doInit();
  106   void doProlog();
  107   void doDeclSubset();
  108   void doInstanceStart();
  109   void doContent();
  110   void extendNameToken(size_t, const MessageType1 &);
  111   void extendNumber(size_t, const MessageType1 &);
  112   void extendHexNumber();
  113   void extendData();
  114   void extendS();
  115   void extendContentS();
  116   void declSubsetRecover(unsigned startLevel);
  117   void prologRecover();
  118   void skipDeclaration(unsigned startLevel);
  119   Boolean parseElementDecl();
  120   Boolean parseAttlistDecl();
  121   Boolean parseNotationDecl();
  122   Boolean parseEntityDecl();
  123   Boolean parseShortrefDecl();
  124   Boolean parseUsemapDecl();
  125   Boolean parseUselinkDecl();
  126   Boolean parseDoctypeDeclStart();
  127   Boolean parseDoctypeDeclEnd(Boolean fake = 0);
  128   Boolean parseMarkedSectionDeclStart();
  129   void handleMarkedSectionEnd();
  130   Boolean parseCommentDecl();
  131   void emptyCommentDecl();
  132   Boolean parseExternalId(const AllowedParams &,
  133               const AllowedParams &,
  134               Boolean,
  135               unsigned,
  136               Param &,
  137               ExternalId &);
  138   Boolean parseParam(const AllowedParams &, unsigned, Param &);
  139   Boolean parseMinimumLiteral(Boolean, Text &);
  140   Boolean parseAttributeValueLiteral(Boolean, Text &);
  141   Boolean parseTokenizedAttributeValueLiteral(Boolean, Text &);
  142   Boolean parseSystemIdentifier(Boolean, Text &);
  143   Boolean parseParameterLiteral(Boolean, Text &);
  144   Boolean parseDataTagParameterLiteral(Boolean, Text &);
  145   // flags for parseLiteral()
  146   enum {
  147     literalSingleSpace = 01,
  148     literalDataTag = 02,
  149     literalMinimumData = 04,
  150     // Keep info about delimiters
  151     literalDelimInfo = 010,
  152     // Ignore references in the literal
  153     literalNoProcess = 020,
  154     // Allow numeric character references to non-SGML characters
  155     literalNonSgml = 040
  156     };
  157   Boolean parseLiteral(Mode litMode, Mode liteMode, size_t maxLength,
  158                const MessageType1 &tooLongMessage,
  159                unsigned flags, Text &text);
  160 
  161   Boolean parseGroupToken(const AllowedGroupTokens &allow,
  162               unsigned nestingLevel,
  163               unsigned declInputLevel,
  164               unsigned groupInputLevel,
  165               GroupToken &gt);
  166   Boolean parseGroupConnector(const AllowedGroupConnectors &allow,
  167                   unsigned declInputLevel,
  168                   unsigned groupInputLevel,
  169                   GroupConnector &gc);
  170   Boolean parseGroup(const AllowedGroupTokens &allowToken,
  171              unsigned declInputLevel,
  172              Param &parm);
  173   Boolean parseModelGroup(unsigned nestingLevel, unsigned declInputLevel,
  174               ModelGroup *&, Mode);
  175   Boolean parseNameGroup(unsigned declInputLevel, Param &);
  176   Boolean parseNameTokenGroup(unsigned declInputLevel, Param &);
  177   Boolean parseDataTagGroup(unsigned nestingLevel, unsigned declInputLevel,
  178                 GroupToken &);
  179   Boolean parseDataTagTemplateGroup(unsigned nestingLevel,
  180                     unsigned declInputLevel, GroupToken &);
  181 
  182   Boolean parseElementNameGroup(unsigned declInputLevel, Param &);
  183   Boolean parseReservedName(const AllowedParams &allow, Param &parm);
  184   Boolean parseIndicatedReservedName(const AllowedParams &allow, Param &parm);
  185   Boolean getReservedName(Syntax::ReservedName *);
  186   Boolean getIndicatedReservedName(Syntax::ReservedName *);
  187   Boolean parseAttributeValueParam(Param &parm);
  188   Boolean parseEntityReference(Boolean isParameter,
  189                    int ignoreLevel,
  190                    ConstPtr<Entity> &entity,
  191                    Ptr<EntityOrigin> &origin);
  192   ContentToken::OccurrenceIndicator getOccurrenceIndicator(Mode);
  193   Boolean parseComment(Mode);
  194   Boolean parseNamedCharRef();
  195   Boolean parseNumericCharRef(Boolean isHex, Char &, Location &);
  196   Boolean translateNumericCharRef(Char &ch, Boolean &isSgmlChar);
  197   Boolean parseDeclarationName(Syntax::ReservedName *, Boolean allowAfdr = 0);
  198   void paramInvalidToken(Token, const AllowedParams &);
  199   void groupTokenInvalidToken(Token, const AllowedGroupTokens &);
  200   void groupConnectorInvalidToken(Token, const AllowedGroupConnectors &);
  201   ElementType *lookupCreateElement(const StringC &);
  202   RankStem *lookupCreateRankStem(const StringC &);
  203   Boolean parseExceptions(unsigned declInputLevel,
  204               Ptr<ElementDefinition> &def);
  205   void parsePcdata();
  206   void parseStartTag();
  207   ElementType *completeRankStem(const StringC &);
  208   void handleRankedElement(const ElementType *);
  209   void parseEmptyStartTag();
  210   void acceptPcdata(const Location &);
  211   void acceptStartTag(const ElementType *, StartElementEvent *,
  212               Boolean netEnabling);
  213   void handleBadStartTag(const ElementType *, StartElementEvent *,
  214              Boolean netEnabling);
  215   void undo(IList<Undo> &);
  216   Boolean tryStartTag(const ElementType *, StartElementEvent *,
  217               Boolean netEnabling, IList<Event> &);
  218   void checkExclusion(const ElementType *e);
  219   Boolean tryImplyTag(const Location &, unsigned &, unsigned &,
  220               IList<Undo> &, IList<Event> &);
  221   void pushElementCheck(const ElementType *, StartElementEvent *,
  222             Boolean netEnabling);
  223   void pushElementCheck(const ElementType *, StartElementEvent *,
  224             IList<Undo> &, IList<Event> &);
  225   void queueElementEvents(IList<Event> &);
  226   Boolean parseAttributeSpec(Mode mode,
  227                  AttributeList &,
  228                  Boolean &netEnabling,
  229                  Ptr<AttributeDefinitionList> &);
  230 
  231   Boolean handleAttributeNameToken(Text &text,
  232                    AttributeList &,
  233                    unsigned &specLength);
  234   struct AttributeParameter {
  235     enum Type {
  236       end,
  237       name,
  238       nameToken,
  239       vi,
  240       recoverUnquoted
  241       };
  242   };
  243 
  244   Boolean parseAttributeParameter(Mode mode,
  245                   Boolean allowVi,
  246                   AttributeParameter::Type &result,
  247                   Boolean &netEnabling);
  248   void extendUnquotedAttributeValue();
  249 
  250   Boolean parseAttributeValueSpec(Mode mode,
  251                   const StringC &name,
  252                   AttributeList &atts,
  253                   unsigned &specLength,
  254                   Ptr<AttributeDefinitionList> &newAttDefList);
  255 
  256   EndElementEvent *parseEndTag();
  257   void parseEndTagClose();
  258   void parseEmptyEndTag();
  259   void parseNullEndTag();
  260   void endAllElements();
  261   void acceptEndTag(EndElementEvent *);
  262   void endTagEmptyElement(const ElementType *,
  263               Boolean netEnabling,
  264               Boolean included,
  265               const Location &startLoc);
  266   void implyCurrentElementEnd(const Location &);
  267   void implyEmptyElementEnd(const ElementType *, Boolean included, const Location &);
  268   void maybeDefineEntity(const Ptr<Entity> &entity);
  269   Notation *lookupCreateNotation(const StringC &name);
  270   Boolean parseExternalEntity(StringC &name,
  271                   Entity::DeclType declType,
  272                   unsigned declInputLevel,
  273                   Param &parm);
  274   ShortReferenceMap *lookupCreateMap(const StringC &);
  275   StringC prettifyDelim(const StringC &delim);
  276   void handleShortref(int index);
  277   Boolean parseProcessingInstruction();
  278   Boolean parseAttributed(unsigned declInputLevel, Param &parm,
  279               Vector<Attributed *> &attributed,
  280               Boolean &isNotation);
  281   Boolean parseDeclaredValue(unsigned declInputLevel, Boolean isNotation,
  282                  Param &parm, Owner<DeclaredValue> &value);
  283   Boolean parseDefaultValue(unsigned declInputLevel, Boolean isNotation,
  284                 Param &parm, const StringC &attributeName,
  285                 Owner<DeclaredValue> &declaredValue,
  286                 Owner<AttributeDefinition> &def,
  287                 Boolean &anyCurrent);
  288   Boolean reportNonSgmlCharacter();
  289   void endInstance();
  290   Boolean implySgmlDecl();
  291   Boolean scanForSgmlDecl(const CharsetInfo &initCharset);
  292   void findMissingMinimum(const CharsetInfo &charset, ISet<WideChar> &);
  293   Boolean parseSgmlDecl();
  294   Boolean sdParseSgmlDeclRef(SdBuilder &, SdParam &, ExternalId &);
  295   Boolean sdParseDocumentCharset(SdBuilder &sdBuilder, SdParam &parm);
  296   Boolean sdParseCapacity(SdBuilder &sdBuilder, SdParam &parm);
  297   Boolean sdParseScope(SdBuilder &sdBuilder, SdParam &parm);
  298   Boolean sdParseSyntax(SdBuilder &sdBuilder, SdParam &parm);
  299   Boolean sdParseExplicitSyntax(SdBuilder &sdBuilder, SdParam &parm);
  300   Boolean sdParseSyntaxCharset(SdBuilder &sdBuilder, SdParam &parm);
  301   Boolean sdParseShunchar(SdBuilder &sdBuilder, SdParam &parm);
  302   Boolean sdParseFunction(SdBuilder &sdBuilder, SdParam &parm);
  303   Boolean sdParseNaming(SdBuilder &sdBuilder, SdParam &parm);
  304   Boolean sdParseDelim(SdBuilder &sdBuilder, SdParam &parm);
  305   Boolean sdParseNames(SdBuilder &sdBuilder, SdParam &parm);
  306   Boolean sdParseQuantity(SdBuilder &sdBuilder, SdParam &parm);
  307   Boolean sdParseEntities(SdBuilder &sdBuilder, SdParam &parm);
  308   Boolean sdParseFeatures(SdBuilder &sd, SdParam &parm);
  309   Boolean sdParseAppinfo(SdBuilder &sd, SdParam &parm);
  310   Boolean sdParseSeealso(SdBuilder &sd, SdParam &parm);
  311   void requireWWW(SdBuilder &sdBuilder);
  312   Boolean parseSdParam(const AllowedSdParams &allow, SdParam &);
  313   Boolean parseSdParamLiteral(Boolean lita, String<SyntaxChar> &str);
  314   Boolean parseSdSystemIdentifier(Boolean lita, Text &);
  315   Boolean stringToNumber(const Char *s, size_t length, unsigned long &);
  316   void sdParamConvertToLiteral(SdParam &parm);
  317   void sdParamInvalidToken(Token token, const AllowedSdParams &);
  318   Boolean sdParseCharset(SdBuilder &sdBuilder, SdParam &parm,
  319              Boolean isDocument,
  320              CharsetDecl &, UnivCharsetDesc &);
  321   Boolean sdParseExternalCharset(Sd &, UnivCharsetDesc &desc);
  322   UnivChar charNameToUniv(Sd &sd, const StringC &name);
  323   Boolean translateSyntax(CharSwitcher &switcher,
  324               const CharsetInfo &syntaxCharset,
  325               const CharsetInfo &docCharset,
  326               WideChar syntaxChar,
  327               Char &docChar);
  328   Boolean translateSyntax(SdBuilder &sdBuilder,
  329               WideChar syntaxChar, Char &docChar);
  330   Boolean translateSyntax(SdBuilder &sdBuilder,
  331               const String<SyntaxChar> &syntaxString,
  332               StringC &docString);
  333   Boolean translateSyntaxNoSwitch(SdBuilder &sdBuilder,
  334                   WideChar syntaxChar, Char &docChar,
  335                   Number &count);
  336   Boolean translateName(SdBuilder &sdBuilder,
  337             const StringC &name,
  338             StringC &str);
  339   void translateRange(SdBuilder &sdBuilder, SyntaxChar start,
  340               SyntaxChar end, ISet<Char> &chars);
  341   UnivChar translateUniv(UnivChar univChar,
  342              CharSwitcher &switcher,
  343              const CharsetInfo &syntaxCharset);
  344   Boolean univToDescCheck(const CharsetInfo &charset, UnivChar from,
  345               Char &to);
  346   Boolean univToDescCheck(const CharsetInfo &charset, UnivChar from,
  347               Char &to, WideChar &count);
  348   void translateDocSet(const CharsetInfo &fromCharset,
  349                const CharsetInfo &toCharset,
  350                const ISet<Char> &fromSet,
  351                ISet<Char> &toSet);
  352   Boolean checkNotFunction(const Syntax &syn, Char c);
  353   Boolean checkGeneralDelim(const Syntax &syn, const StringC &delim);
  354   Boolean checkShortrefDelim(const Syntax &syn,
  355                  const CharsetInfo &charset,
  356                  const StringC &delim);
  357   Boolean checkNmchars(const ISet<Char> &set, const Syntax &syntax);
  358   void intersectCharSets(const ISet<Char> &s1, const ISet<Char> &s2,
  359              ISet<WideChar> &inter);
  360   Boolean checkSwitches(CharSwitcher &switcher,
  361             const CharsetInfo &syntaxCharset);
  362   Boolean checkSwitchesMarkup(CharSwitcher &switcher);
  363 
  364   const StandardSyntaxSpec *lookupSyntax(const PublicId &id);
  365   Boolean referencePublic(const PublicId &id, PublicId::TextClass,
  366               Boolean &givenError);
  367   void checkIdrefs();
  368   void checkTaglen(Index tagStartIndex);
  369   void checkSyntaxNamelen(const Syntax &syn);
  370   void checkSyntaxNames(const Syntax &syn);
  371   void checkElementAttribute(const ElementType *e, size_t checkFrom = 0);
  372   void checkDtd(Dtd &dtd);
  373   Boolean maybeStatusKeyword(const Entity &entity);
  374   void reportAmbiguity(const LeafContentToken *from,
  375                const LeafContentToken *to1,
  376                const LeafContentToken *to2,
  377                unsigned ambigAndDepth);
  378   Boolean parseLinktypeDeclStart();
  379   Boolean parseLinktypeDeclEnd();
  380   Boolean parseLinkDecl();
  381   Boolean parseIdlinkDecl();
  382   Boolean parseLinkSet(Boolean idlink);
  383   void addIdLinkRule(const StringC &id, IdLinkRule &rule);
  384   void addLinkRule(LinkSet *linkSet,
  385            const ElementType *sourceElement,
  386            const ConstPtr<SourceLinkRuleResource> &linkRule);
  387   Boolean parseResultElementSpec(unsigned declInputLevel,
  388                  Param &parm,
  389                  Boolean idlink,
  390                  Boolean &implied,
  391                  const ElementType *&resultType,
  392                  AttributeList &attributes);
  393   LinkSet *lookupCreateLinkSet(const StringC &name);
  394   ElementType *lookupResultElementType(const StringC &name);
  395   void endProlog();
  396   Boolean parseEntityReferenceNameGroup(Boolean &ignore);
  397   Boolean parseTagNameGroup(Boolean &active, Boolean start);
  398   void parseGroupStartTag();
  399   void parseGroupEndTag();
  400   StartElementEvent *doParseStartTag(Boolean &netEnabling);
  401   EndElementEvent *doParseEndTag();
  402   Boolean skipAttributeSpec();
  403   Boolean lookingAtStartTag(StringC &gi);
  404   void implyDtd(const StringC &gi);
  405   void findMissingTag(const ElementType *e, Vector<const ElementType *> &);
  406   unsigned paramsSubdocLevel(const SgmlParser::Params &);
  407   void addCommonAttributes(Dtd &dtd);
  408   Boolean parseAfdrDecl();
  409   void setSdOverrides(Sd &sd);
  410   StringC sysid_;
  411 };
  412 
  413 #ifdef SP_NAMESPACE
  414 }
  415 #endif
  416 
  417 #endif /* not Parser_INCLUDED */