1414
1515#include " xml_parse_tree.h"
1616
17- int yyxmlparse ();
18-
1917class xml_parsert :public parsert
2018{
2119public:
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+
2236 xml_parse_treet parse_tree;
2337
2438 std::list<xmlt *> stack;
@@ -28,29 +42,30 @@ class xml_parsert:public parsert
2842 return *stack.back ();
2943 }
3044
31- virtual bool parse ()
32- {
33- return yyxmlparse ()!=0 ;
34- }
45+ bool parse () override ;
3546
3647 void new_level ()
3748 {
3849 current ().elements .push_back (xmlt ());
3950 stack.push_back (¤t ().elements .back ());
4051 }
4152
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
4356 {
4457 parse_tree.clear ();
4558 // set up stack
4659 stack.clear ();
4760 stack.push_back (&parse_tree.element );
61+ parsert::clear ();
4862 }
49- };
5063
51- extern xml_parsert xml_parser;
64+ protected:
65+ static int instance_count;
66+ };
5267
53- int yyxmlerror (const std::string &error );
68+ int yyxmlerror (xml_parsert &, void *, const std::string &);
5469
5570// 'do it all' functions
5671bool parse_xml (
0 commit comments