-
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.
- Loading branch information
1 parent
856c641
commit c1b50c3
Showing
4 changed files
with
34 additions
and
14 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,12 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include <fstream> | ||
|
||
json_parsert json_parser; | ||
int yyjsonparse(json_parsert &); | ||
|
||
bool json_parsert::parse() | ||
{ | ||
return yyjsonparse(*this) != 0; | ||
} | ||
|
||
// 'do it all' function | ||
bool parse_json( | ||
|
@@ -19,10 +24,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,22 @@ 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) | ||
{ | ||
|
@@ -50,9 +51,7 @@ class json_parsert:public parsert | |
} | ||
}; | ||
|
||
extern json_parsert json_parser; | ||
|
||
int yyjsonerror(const std::string &error); | ||
int yyjsonerror(json_parsert &, const std::string &error); | ||
|
||
// 'do it all' functions | ||
bool parse_json( | ||
|
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