/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk

« back to all changes in this revision

Viewing changes to parse/parabix.20090211/src/engine.h

  • Committer: Suren A. Chilingaryan
  • Date: 2009-09-23 17:13:04 UTC
  • Revision ID: csa@dside.dyndns.org-20090923171304-osvtr4zqb29h11kd
Intel, Tango, Phobos, and RapidXML parsers; Memory benchmark scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  engine.h - parabix parsing engine
2
 
    Copyright (c) 2007, 2008 Robert D. Cameron and Dan Lin
3
 
    Licensed to the public under the Open Software License 3.0.
4
 
    Licensed to International Characters, Inc., under the Academic
5
 
    Free License 3.0.
6
 
 
7
 
*/
8
 
#ifndef ENGINE_H
9
 
#define ENGINE_H
10
 
 
11
 
/*  Parabix provides strings to the application using the WorkingCharacterSet. 
12
 
    This parameter is set by template instantiation; normally only one
13
 
    WorkingCharacterSet parameter is chosen.  However, it is possible
14
 
    to compile different parsers having different WorkingCharacterSet
15
 
    parameters within one run-time code base.
16
 
*/
17
 
 
18
 
enum WorkingCharacterSet {UTF_8, UTF_16, UTF_32};
19
 
 
20
 
#include "xmlmodel.h"
21
 
#include "xmldecl.h"
22
 
#include "byteplex.h"
23
 
#include "bitlex.h"
24
 
#include "xml_error.h"
25
 
#include "contentmodel.h"
26
 
#include "symtab.h"
27
 
 
28
 
#define min(x,y) ((x) <(y) ?(x) :(y) )
29
 
/* A ParsingEngine is the principal class for parsing XML
30
 
data.  */
31
 
 
32
 
template <WorkingCharacterSet W>
33
 
class Parser_Interface {
34
 
public:
35
 
        ~Parser_Interface();
36
 
        static Parser_Interface * ParserFactory(char * filename);
37
 
        static Parser_Interface * ParserFactory(char * filename, Model_Info * m);
38
 
        // Constructor for a subsidiary parser for internal entities.
39
 
        static Parser_Interface * ParserFactory(char * byte_buffer, int byte_count, Entity_Info * e, Model_Info * m);
40
 
        virtual void ParseContent() = 0;
41
 
        virtual void Parse_DocumentContent() = 0;
42
 
        virtual void Parse_WF_Content() = 0;
43
 
        virtual void Parse_AnyContent() = 0;
44
 
        virtual void Parse_MixedContent(symbol_set_t elems) = 0;
45
 
        virtual void Parse_ValidContent(CM_RegExp * cre, int & cur_state) = 0;
46
 
        virtual bool at_EOF() const = 0;
47
 
        virtual void Parse_ExtSubsetDecl() = 0;
48
 
        virtual void Parse_Prolog() = 0;
49
 
        bool has_ByteOrderMark();
50
 
        XML_version get_version();
51
 
        XML_standalone standalone_status();
52
 
        bool has_EncodingDecl();
53
 
        unsigned char * get_Encoding();
54
 
        Model_Info * model_info;
55
 
        Entity_Info * entity_Info;
56
 
 
57
 
 
58
 
        /* Action routine for document start. */
59
 
        void DocumentStart_action();    
60
 
        
61
 
        /* Action routine for document end. */
62
 
        void DocumentEnd_action();
63
 
        
64
 
        /* Action routine for an XML comment in "<!--"  "-->" brackets. */
65
 
        void Comment_action(unsigned char * item, int lgth);
66
 
        
67
 
        /* Action routine called upon recognizing "<![CDATA[" to start a CDATA section. */
68
 
        void CDATA_start_action(unsigned char * CDATA_ptr);
69
 
 
70
 
        /* Action routine called upon recognizing "]]>" to end a CDATA section. */
71
 
        void CDATA_end_action(unsigned char * CDATA_end_ptr);
72
 
        
73
 
        /* Action routine for an XML processing instruction enclosed in "<?" and "?>" brackets. */
74
 
        void PI_action(unsigned char * item, int lgth);
75
 
        
76
 
        /* Action routine for an empty element enclosed in "<" and "/>" brackets. */
77
 
        void EmptyElement_action(unsigned char * item, int lgth);
78
 
        
79
 
        /* Action routine for a start tag enclosed in "<" and ">" brackets. */
80
 
        void StartTag_action(unsigned char * item, int lgth);
81
 
        
82
 
        /* Action routine for an end tag enclosed in "</" and ">" brackets. */
83
 
        void EndTag_action(unsigned char * item, int lgth);
84
 
        
85
 
        /* Action routine for an error item */
86
 
        void Error_action(unsigned char * item, int lgth);
87
 
        
88
 
        /* Action routine for a text item */
89
 
        void Text_action(unsigned char * item, int lgth, bool more);
90
 
        
91
 
        /* Action routine for a character or entity reference.*/
92
 
        void Reference_action(unsigned char * item, int lgth);
93
 
        
94
 
        /* Action routine for an element name occurring immediately after the 
95
 
        opening "<" of a start tag or empty element tag. */
96
 
        void ElementName_action(unsigned char * item, int lgth);
97
 
        
98
 
        /* Action routine for a processing instruction target name occurring immediately 
99
 
        after the opening "<?" of a processing instruction. */
100
 
        void PI_Target_action(unsigned char * item, int lgth);
101
 
        
102
 
        /* Action routine for an individual attribute/value pair occurring in
103
 
        a element start tag or an empty element tag. */
104
 
        void AttributeValue_action(unsigned char * name, int name_lgth, 
105
 
                                   unsigned char * val, int val_lgth);
106
 
        
107
 
        /* Action routine for an individual namespace binding occurring in
108
 
        a element start tag or an empty element tag. */
109
 
        void Namespace_action(unsigned char * name, int name_end, 
110
 
                              unsigned char * URI, int URI_end);
111
 
        
112
 
        /*Action routine for end of buffer events. */
113
 
        void FinalizeBuffer_action();
114
 
        
115
 
        /*Document Type actions.*/
116
 
        void Doctype_action(unsigned char * item, int lgth);
117
 
        void PEReference_action(unsigned char * item, int lgth);
118
 
        
119
 
        void Prolog_action(unsigned char * item, int lgth);
120
 
        
121
 
        void ExtSubsetDecl_action(unsigned char * item, int lgth);
122
 
        
123
 
};
124
 
 
125
 
template <class B, WorkingCharacterSet W>
126
 
class ParsingEngine : public Parser_Interface<W> {
127
 
public:
128
 
        ParsingEngine(Entity_Info * e, Model_Info * m, Byteplex * b, bool is_external);
129
 
        ~ParsingEngine();
130
 
        void ParseContent();
131
 
protected:
132
 
        bool StrictWellFormedness;
133
 
 
134
 
        vector<int> LastAttOccurrence;
135
 
        XML_Decl_Parser<B::Base> * decl_parser;
136
 
        
137
 
        int text_or_markup_start;
138
 
        /* Getters for current point/position information. */
139
 
        int AbsPos() const;
140
 
        int LengthFrom(int start_pos) const;
141
 
        int BufferRelPos() const;
142
 
        unsigned char * cur() const;
143
 
        unsigned char * GetCodeUnitPtr(int pos);
144
 
 
145
 
        bool at_EOF () const;
146
 
        /*Internal helper for text action*/
147
 
        void text_if_nonnull_action(bool more);
148
 
        /* Mutators that advance the input. */
149
 
        void Advance(int n);
150
 
        void ScanTo(int lex_item);
151
 
        void ScanTextTo(int lex_item);  // Specialized version.
152
 
        void AdjustBufferEndForIncompleteSequences();
153
 
        void AdvanceBuffers();
154
 
        /* Parsing routines. */
155
 
 
156
 
        void WF_Error (XML_Constraint errCode);
157
 
        void Validity_Error (XML_Constraint errCode);
158
 
        void Syntax_Error (XML_NonTerminal errNT);
159
 
        
160
 
        void Parse_Comment ();
161
 
        void Parse_StartTag ();
162
 
        void Parse_EndTag ();
163
 
        void Parse_CDATA ();
164
 
        void Parse_PI ();
165
 
        void Parse_CharRef ();  
166
 
        void Parse_EntityRef ();
167
 
        void Parse_EntityRef_inMixed(symbol_set_t elems);
168
 
        void Parse_EntityRef_inAnyContent();
169
 
        
170
 
        /* Parsing routine for Document Type*/
171
 
        void Parse_DocType ();
172
 
        void Parse_ExternalID (char *& SystemLiteral, char *& PubidLiteral);
173
 
        void Parse_SystemLiteral ();
174
 
        void Parse_PubidLiteral ();
175
 
        void Parse_IntSubset ();
176
 
        void Parse_PEReference ();
177
 
        void Parse_Elementdecl ();
178
 
        ContentModel * Parse_RemainingMixed ();
179
 
        Content_RE * Parse_RemainingChildren ();
180
 
        Content_RE * Parse_Cp();
181
 
        void Parse_AttlistDecl ();
182
 
        void Parse_Notation (ATT_info * this_info);
183
 
        void Parse_Enumeration (ATT_info * this_info);
184
 
        void Parse_DefaultDecl (ATT_info * this_info);
185
 
        void Parse_Entitydecl ();
186
 
        void Parse_Notationdecl ();
187
 
        void requireWS ();
188
 
        void Parse_AttValue ();
189
 
        void Parse_GEntityValue(GEntity_info * this_info);
190
 
        void Parse_PEntityValue(PEntity_info * this_info);
191
 
        char * Replace_EntityRef(bool& is_simple);
192
 
        char * Replace_CharRef();
193
 
        void Parse_Prolog();
194
 
        void Parse_DocumentContent();
195
 
        
196
 
        void Parse_WF_Element();
197
 
        void Parse_WF_Content();
198
 
        int Parse_WF_StartTag(bool& is_empty);
199
 
        void Parse_WF_EndTag(int nameID);
200
 
 
201
 
        void Parse_ValidEntityRef(CM_RegExp * cre, int & cur_state);
202
 
        int Parse_ValidElement();
203
 
        void Parse_ValidContent(CM_RegExp * cre, int & cur_state);
204
 
        void Parse_AnyContent();
205
 
        void Parse_MixedContent(symbol_set_t elems);
206
 
        
207
 
        int Parse_ValidStartTag(bool& is_empty);
208
 
        
209
 
        int Parse_Nmtoken();
210
 
        int Parse_Name(); 
211
 
        
212
 
        /*Parsing routine for external entities*/
213
 
        void Parse_ExtSubsetDecl ();
214
 
        
215
 
protected:
216
 
        /* Co-classes */
217
 
 
218
 
        Byteplex * byteplex;    
219
 
        Bitplex * bitplex;
220
 
        Lexer_Interface * lexer;
221
 
        /* Parallel data streams for current buffer full of XML data. */
222
 
        BytePack * x8data;
223
 
        LexicalStreamSet * buf;
224
 
                
225
 
        int buffer_base_pos;
226
 
        int buffer_rel_pos;
227
 
        int buffer_limit_pos;
228
 
};
229
 
 
230
 
 
231
 
#endif