-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
json_parsert: construct with message handler
This both avoids an object of static lifetime as well as it fixes the (transitive) use of the deprecated messaget() constructor. Both the parser and lexer are now fully reentrant.
- Loading branch information
1 parent
6438259
commit 63e5910
Showing
4 changed files
with
38 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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,18 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include <fstream> | ||
|
||
json_parsert json_parser; | ||
int yyjsonlex_init_extra(json_parsert *, void **); | ||
int yyjsonlex_destroy(void *); | ||
int yyjsonparse(json_parsert &, void *); | ||
|
||
bool json_parsert::parse() | ||
{ | ||
void *scanner; | ||
yyjsonlex_init_extra(this, &scanner); | ||
bool parse_fail = yyjsonparse(*this, scanner) != 0; | ||
yyjsonlex_destroy(scanner); | ||
return parse_fail; | ||
} | ||
|
||
// 'do it all' function | ||
bool parse_json( | ||
|
@@ -19,10 +30,10 @@ bool parse_json( | |
message_handlert &message_handler, | ||
jsont &dest) | ||
{ | ||
json_parser.clear(); | ||
json_parsert json_parser{message_handler}; | ||
|
||
json_parser.set_file(filename); | ||
json_parser.in=∈ | ||
json_parser.log.set_message_handler(message_handler); | ||
|
||
bool result=json_parser.parse(); | ||
|
||
|
This file contains 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 |
---|---|---|
|
@@ -15,21 +15,20 @@ Author: Daniel Kroening, [email protected] | |
#include <util/parser.h> | ||
#include <util/json.h> | ||
|
||
int yyjsonparse(); | ||
void yyjsonrestart(FILE *input_file); | ||
|
||
class json_parsert:public parsert | ||
{ | ||
public: | ||
explicit json_parsert(message_handlert &message_handler) | ||
: parsert(message_handler) | ||
{ | ||
} | ||
|
||
typedef std::stack<jsont, std::vector<jsont> > stackt; | ||
stackt stack; | ||
|
||
jsont &top() { return stack.top(); } | ||
|
||
virtual bool parse() override | ||
{ | ||
return yyjsonparse()!=0; | ||
} | ||
bool parse() override; | ||
|
||
void push(const jsont &x) | ||
{ | ||
|
@@ -46,14 +45,9 @@ class json_parsert:public parsert | |
virtual void clear() override | ||
{ | ||
stack=stackt(); | ||
yyjsonrestart(nullptr); | ||
} | ||
}; | ||
|
||
extern json_parsert json_parser; | ||
|
||
int yyjsonerror(const std::string &error); | ||
|
||
// 'do it all' functions | ||
bool parse_json( | ||
std::istream &in, | ||
|
This file contains 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 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