14
14
15
15
#include " xml_parse_tree.h"
16
16
17
- int yyxmlparse ();
18
-
19
17
class xml_parsert :public parsert
20
18
{
21
19
public:
20
+ explicit xml_parsert (message_handlert &message_handler)
21
+ : parsert(message_handler)
22
+ {
23
+ // Simplistic check that we don't attempt to do reentrant parsing as the
24
+ // Bison-generated parser has global state.
25
+ PRECONDITION (++instance_count == 1 );
26
+ stack.push_back (&parse_tree.element );
27
+ }
28
+
29
+ xml_parsert (const xml_parsert &) = delete ;
30
+
31
+ ~xml_parsert () override
32
+ {
33
+ --instance_count;
34
+ }
35
+
22
36
xml_parse_treet parse_tree;
23
37
24
38
std::list<xmlt *> stack;
@@ -28,29 +42,30 @@ class xml_parsert:public parsert
28
42
return *stack.back ();
29
43
}
30
44
31
- virtual bool parse ()
32
- {
33
- return yyxmlparse ()!=0 ;
34
- }
45
+ bool parse () override ;
35
46
36
47
void new_level ()
37
48
{
38
49
current ().elements .push_back (xmlt ());
39
50
stack.push_back (¤t ().elements .back ());
40
51
}
41
52
42
- virtual void clear ()
53
+ // / Clears the parser state. May be removed in future as there should not be a
54
+ // / need to re-use an existing parser object.
55
+ void clear () override
43
56
{
44
57
parse_tree.clear ();
45
58
// set up stack
46
59
stack.clear ();
47
60
stack.push_back (&parse_tree.element );
61
+ parsert::clear ();
48
62
}
49
- };
50
63
51
- extern xml_parsert xml_parser;
64
+ protected:
65
+ static int instance_count;
66
+ };
52
67
53
- int yyxmlerror (const std::string &error );
68
+ int yyxmlerror (xml_parsert &, void *, const std::string &);
54
69
55
70
// 'do it all' functions
56
71
bool parse_xml (
0 commit comments