File tree Expand file tree Collapse file tree 4 files changed +34
-14
lines changed
Expand file tree Collapse file tree 4 files changed +34
-14
lines changed Original file line number Diff line number Diff line change 1010
1111#include < fstream>
1212
13- json_parsert json_parser;
13+ int yyjsonparse (json_parsert &);
14+
15+ bool json_parsert::parse ()
16+ {
17+ return yyjsonparse (*this ) != 0 ;
18+ }
1419
1520// 'do it all' function
1621bool parse_json (
@@ -19,10 +24,10 @@ bool parse_json(
1924 message_handlert &message_handler,
2025 jsont &dest)
2126{
22- json_parser.clear ();
27+ json_parsert json_parser{message_handler};
28+
2329 json_parser.set_file (filename);
2430 json_parser.in =∈
25- json_parser.log .set_message_handler (message_handler);
2631
2732 bool result=json_parser.parse ();
2833
Original file line number Diff line number Diff line change 1515#include < util/parser.h>
1616#include < util/json.h>
1717
18- int yyjsonparse ();
1918void yyjsonrestart (FILE *input_file);
2019
2120class json_parsert :public parsert
2221{
2322public:
23+ explicit json_parsert (message_handlert &message_handler)
24+ : parsert(message_handler)
25+ {
26+ }
27+
2428 typedef std::stack<jsont, std::vector<jsont> > stackt;
2529 stackt stack;
2630
2731 jsont &top () { return stack.top (); }
2832
29- virtual bool parse () override
30- {
31- return yyjsonparse ()!=0 ;
32- }
33+ bool parse () override ;
3334
3435 void push (const jsont &x)
3536 {
@@ -50,9 +51,7 @@ class json_parsert:public parsert
5051 }
5152};
5253
53- extern json_parsert json_parser;
54-
55- int yyjsonerror (const std::string &error);
54+ int yyjsonerror (json_parsert &, const std::string &error);
5655
5756// 'do it all' functions
5857bool parse_json (
Original file line number Diff line number Diff line change 2020
2121#include < util/unicode.h>
2222
23- int yyjsonlex ();
23+ int yyjsonlex (json_parsert &json_parser );
2424extern char *yyjsontext;
2525extern int yyjsonleng; // really an int, not a size_t
2626
@@ -75,14 +75,17 @@ static std::string convert_TOK_NUMBER()
7575 return yyjsontext;
7676}
7777
78- int yyjsonerror (const std::string &error)
78+ int yyjsonerror (json_parsert &json_parser, const std::string &error)
7979{
8080 json_parser.parse_error (error, yyjsontext);
8181 return 0 ;
8282}
8383
8484%}
8585
86+ %parse-param {json_parsert &json_parser}
87+ %lex-param {json_parsert &json_parser}
88+
8689%token TOK_STRING
8790%token TOK_NUMBER
8891%token TOK_TRUE
Original file line number Diff line number Diff line change 2424#pragma warning(disable:4005)
2525#endif
2626
27- #define PARSER json_parser
27+ #define PARSER (* json_parser)
2828
2929#include " json_parser.h"
3030#include " json_y.tab.h"
3333#include < util/pragma_wnull_conversion.def> // IWYU pragma: keep
3434#include < util/pragma_wdeprecated_register.def> // IWYU pragma: keep
3535
36+ static json_parsert *json_parser;
37+
38+ int yyjsonlex (void );
39+
40+ int yyjsonlex (json_parsert &_json_parser)
41+ {
42+ // our scanner is not reentrant
43+ PRECONDITION (!json_parser);
44+ json_parser = &_json_parser;
45+ int result = yyjsonlex ();
46+ json_parser = nullptr ;
47+ return result;
48+ }
3649%}
3750
3851string \"\" | \" {chars }\"
You can’t perform that action at this time.
0 commit comments