cprover
json_parser.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 
10 #ifndef CPROVER_JSON_JSON_PARSER_H
11 #define CPROVER_JSON_JSON_PARSER_H
12 
13 #include <cassert>
14 #include <stack>
15 
16 #include <util/parser.h>
17 #include <util/json.h>
18 
19 int yyjsonparse();
20 
21 class json_parsert:public parsert
22 {
23 public:
24  typedef std::stack<jsont, std::vector<jsont> > stackt;
25  stackt stack;
26 
27  jsont &top() { return stack.top(); }
28 
29  virtual bool parse() override
30  {
31  return yyjsonparse()!=0;
32  }
33 
34  void push(const jsont &x)
35  {
36  stack.push(x);
37  }
38 
39  void pop(jsont &dest)
40  {
41  assert(!stack.empty());
42  dest.swap(stack.top());
43  stack.pop();
44  }
45 
46  virtual void clear() override
47  {
48  stack=stackt();
49  }
50 };
51 
53 
54 int yyjsonerror(const std::string &error);
55 
56 // 'do it all' functions
57 bool parse_json(
58  std::istream &in,
59  const std::string &filename,
61  jsont &dest);
62 
63 bool parse_json(
64  const std::string &filename,
65  message_handlert &message_handler,
66  jsont &dest);
67 
68 #endif // CPROVER_JSON_JSON_PARSER_H
virtual bool parse() override
Definition: json_parser.h:29
std::stack< jsont, std::vector< jsont > > stackt
Definition: json_parser.h:24
jsont & top()
Definition: json_parser.h:27
std::istream * in
Definition: parser.h:26
void push(const jsont &x)
Definition: json_parser.h:34
json_parsert json_parser
Definition: json_parser.cpp:13
Definition: json.h:21
bool parse_json(std::istream &in, const std::string &filename, message_handlert &message_handler, jsont &dest)
Definition: json_parser.cpp:16
Definition: parser.h:23
Parser utilities.
stackt stack
Definition: json_parser.h:25
int yyjsonerror(const std::string &error)
Definition: json_y.tab.cpp:125
void pop(jsont &dest)
Definition: json_parser.h:39
virtual void clear() override
Definition: json_parser.h:46
mstreamt & error()
Definition: message.h:223
void swap(jsont &other)
Definition: json.cpp:136
int yyjsonparse()
message_handlert * message_handler
Definition: message.h:259