-
Notifications
You must be signed in to change notification settings - Fork 277
xml_parsert: construct with message handler #8135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,20 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include <fstream> | ||
|
||
xml_parsert xml_parser; | ||
int xml_parsert::instance_count = 0; | ||
|
||
int yyxmllex_init_extra(xml_parsert *, void **); | ||
int yyxmllex_destroy(void *); | ||
int yyxmlparse(xml_parsert &, void *); | ||
|
||
bool xml_parsert::parse() | ||
{ | ||
void *scanner; | ||
yyxmllex_init_extra(this, &scanner); | ||
bool parse_fail = yyxmlparse(*this, scanner) != 0; | ||
yyxmllex_destroy(scanner); | ||
return parse_fail; | ||
} | ||
|
||
// 'do it all' function | ||
bool parse_xml( | ||
|
@@ -19,19 +32,16 @@ bool parse_xml( | |
message_handlert &message_handler, | ||
xmlt &dest) | ||
{ | ||
xml_parser.clear(); | ||
xml_parsert xml_parser{message_handler}; | ||
|
||
xml_parser.set_file(filename); | ||
xml_parser.in=∈ | ||
xml_parser.log.set_message_handler(message_handler); | ||
|
||
bool result=yyxmlparse()!=0; | ||
bool result = xml_parser.parse(); | ||
|
||
// save result | ||
xml_parser.parse_tree.element.swap(dest); | ||
|
||
// save some memory | ||
xml_parser.clear(); | ||
|
||
return result; | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,25 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include "xml_parse_tree.h" | ||
|
||
int yyxmlparse(); | ||
|
||
class xml_parsert:public parsert | ||
{ | ||
public: | ||
explicit xml_parsert(message_handlert &message_handler) | ||
: parsert(message_handler) | ||
{ | ||
// Simplistic check that we don't attempt to do reentrant parsing as the | ||
// Bison-generated parser has global state. | ||
PRECONDITION(++instance_count == 1); | ||
stack.push_back(&parse_tree.element); | ||
} | ||
|
||
xml_parsert(const xml_parsert &) = delete; | ||
|
||
~xml_parsert() override | ||
{ | ||
--instance_count; | ||
} | ||
|
||
xml_parse_treet parse_tree; | ||
|
||
std::list<xmlt *> stack; | ||
|
@@ -28,29 +42,30 @@ class xml_parsert:public parsert | |
return *stack.back(); | ||
} | ||
|
||
virtual bool parse() | ||
{ | ||
return yyxmlparse()!=0; | ||
} | ||
bool parse() override; | ||
|
||
void new_level() | ||
{ | ||
current().elements.push_back(xmlt()); | ||
stack.push_back(¤t().elements.back()); | ||
} | ||
|
||
virtual void clear() | ||
/// Clears the parser state. May be removed in future as there should not be a | ||
/// need to re-use an existing parser object. | ||
void clear() override | ||
tautschnig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
parse_tree.clear(); | ||
// set up stack | ||
stack.clear(); | ||
stack.push_back(&parse_tree.element); | ||
parsert::clear(); | ||
} | ||
}; | ||
|
||
extern xml_parsert xml_parser; | ||
protected: | ||
static int instance_count; | ||
}; | ||
|
||
int yyxmlerror(const std::string &error); | ||
int yyxmlerror(xml_parsert &, void *, const std::string &); | ||
|
||
// 'do it all' functions | ||
bool parse_xml( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.