xref: /trunk/main/xml2cmp/source/xcd/parse.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
1*dd7bc091SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*dd7bc091SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*dd7bc091SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*dd7bc091SAndrew Rist  * distributed with this work for additional information
6*dd7bc091SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*dd7bc091SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*dd7bc091SAndrew Rist  * "License"); you may not use this file except in compliance
9*dd7bc091SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*dd7bc091SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*dd7bc091SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*dd7bc091SAndrew Rist  * software distributed under the License is distributed on an
15*dd7bc091SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*dd7bc091SAndrew Rist  * KIND, either express or implied.  See the License for the
17*dd7bc091SAndrew Rist  * specific language governing permissions and limitations
18*dd7bc091SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*dd7bc091SAndrew Rist  *************************************************************/
21*dd7bc091SAndrew Rist 
22*dd7bc091SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef X2C_PARSE_HXX
25cdf0e10cSrcweir #define X2C_PARSE_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir // USED SERVICES
30cdf0e10cSrcweir     // BASE CLASSES
31cdf0e10cSrcweir     // COMPONENTS
32cdf0e10cSrcweir #include "filebuff.hxx"
33cdf0e10cSrcweir #include "../support/sistr.hxx"
34cdf0e10cSrcweir #include "../support/list.hxx"
35cdf0e10cSrcweir     // PARAMETERS
36cdf0e10cSrcweir 
37cdf0e10cSrcweir 
38cdf0e10cSrcweir class XmlElement;
39cdf0e10cSrcweir class ListElement;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir class X2CParser
42cdf0e10cSrcweir {
43cdf0e10cSrcweir   public:
44cdf0e10cSrcweir     typedef XmlElement * (*F_CREATE)(const Simstr &);
45cdf0e10cSrcweir 
46cdf0e10cSrcweir                         X2CParser(
47cdf0e10cSrcweir                             XmlElement &        o_rDocumentData );
48cdf0e10cSrcweir                         ~X2CParser();
49cdf0e10cSrcweir 
50cdf0e10cSrcweir     bool                LoadFile(
51cdf0e10cSrcweir                             const char *        i_sFilename );
52cdf0e10cSrcweir     void                Parse();
53cdf0e10cSrcweir     bool                Parse(
54cdf0e10cSrcweir                             const char *        i_sFilename );
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 
PureText() const57cdf0e10cSrcweir     const char *        PureText() const        { return aFile.operator const char*(); }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     void                Parse_Sequence(
60cdf0e10cSrcweir                            DynamicList<XmlElement> &
61cdf0e10cSrcweir                                                 o_rElements,
62cdf0e10cSrcweir                            const Simstr &       i_sElementName );
63cdf0e10cSrcweir     void                Parse_FreeChoice(
64cdf0e10cSrcweir                             DynamicList<XmlElement> &
65cdf0e10cSrcweir                                                 o_rElements );
66cdf0e10cSrcweir     void                Parse_List(
67cdf0e10cSrcweir                             ListElement &       o_rListElem );
68cdf0e10cSrcweir     void                Parse_Text(
69cdf0e10cSrcweir                             Simstr &            o_sText,
70cdf0e10cSrcweir                             const Simstr &      i_sElementName,
71cdf0e10cSrcweir                             bool                i_bReverseName );
72cdf0e10cSrcweir     void                Parse_MultipleText(
73cdf0e10cSrcweir                             List<Simstr> &      o_rTexts,
74cdf0e10cSrcweir                             const Simstr &      i_sElementName,
75cdf0e10cSrcweir                             bool                i_bReverseName );
76cdf0e10cSrcweir     void                Parse_SglAttr(
77cdf0e10cSrcweir                             Simstr &            o_sAttrValue,
78cdf0e10cSrcweir                             const Simstr &      i_sElementName,
79cdf0e10cSrcweir                             const Simstr &      i_sAttrName );
80cdf0e10cSrcweir     void                Parse_MultipleAttr(
81cdf0e10cSrcweir                             List<Simstr> &      o_rAttrValues,
82cdf0e10cSrcweir                             const Simstr &      i_sElementName,
83cdf0e10cSrcweir                             const List<Simstr> &
84cdf0e10cSrcweir                                                 i_rAttrNames );
85cdf0e10cSrcweir 
86cdf0e10cSrcweir   private:
87cdf0e10cSrcweir     void                Parse_XmlDeclaration();
88cdf0e10cSrcweir     void                Parse_Doctype();
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     void                Get_Attribute(
91cdf0e10cSrcweir                             Simstr &            o_rAttrValue,
92cdf0e10cSrcweir                             Simstr &            o_rAttrName );
93cdf0e10cSrcweir     bool                IsText(
94cdf0e10cSrcweir                             const char *        i_sComparedText );
95cdf0e10cSrcweir     bool                IsBeginTag(
96cdf0e10cSrcweir                             const char *        i_sTagName );
97cdf0e10cSrcweir     bool                IsEndTag(
98cdf0e10cSrcweir                             const char *        i_sTagName );
99cdf0e10cSrcweir     void                Goto(
100cdf0e10cSrcweir                             char                i_cNext );
101cdf0e10cSrcweir     void                Goto_And_Pass(
102cdf0e10cSrcweir                             char                i_cNext );
103cdf0e10cSrcweir     void                Move(
104cdf0e10cSrcweir                             int                 i_nForward );
105cdf0e10cSrcweir     void                Pass_White();
106cdf0e10cSrcweir     void                GetTextTill(
107cdf0e10cSrcweir                             Simstr &            o_rText,
108cdf0e10cSrcweir                             char                i_cEnd,
109cdf0e10cSrcweir                             bool                i_bReverseName = false );
110cdf0e10cSrcweir     /// @return false in case of empty tag with no attributes.
111cdf0e10cSrcweir     bool                CheckAndPassBeginTag(
112cdf0e10cSrcweir                             const char *        i_sElementName );
113cdf0e10cSrcweir     void                CheckAndPassEndTag(
114cdf0e10cSrcweir                             const char *        i_sElementName );
115cdf0e10cSrcweir     /// @precond IsBeginTag() == true.
116cdf0e10cSrcweir     bool                IsAbsoluteEmpty() const;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     void                SyntaxError(
120cdf0e10cSrcweir                             const char *        i_sText );
121cdf0e10cSrcweir     void                TestCurChar();
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     // DATA
124cdf0e10cSrcweir     Simstr              sFileName;
125cdf0e10cSrcweir     unsigned            nFileLine;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     Buffer              aFile;
128cdf0e10cSrcweir     XmlElement *        pDocumentData;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     char                sWord[8192];
131cdf0e10cSrcweir     const char *        text;
132cdf0e10cSrcweir };
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 
136cdf0e10cSrcweir // IMPLEMENTATION
137cdf0e10cSrcweir 
138cdf0e10cSrcweir #endif
139