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 
20 void yyjsonrestart(FILE *input_file);
21 
22 class json_parsert:public parsert
23 {
24 public:
25  typedef std::stack<jsont, std::vector<jsont> > stackt;
27 
28  jsont &top() { return stack.top(); }
29 
30  virtual bool parse() override
31  {
32  return yyjsonparse()!=0;
33  }
34 
35  void push(const jsont &x)
36  {
37  stack.push(x);
38  }
39 
40  void pop(jsont &dest)
41  {
42  assert(!stack.empty());
43  dest.swap(stack.top());
44  stack.pop();
45  }
46 
47  virtual void clear() override
48  {
49  stack=stackt();
50  yyjsonrestart(nullptr);
51  }
52 };
53 
55 
56 int yyjsonerror(const std::string &error);
57 
58 // 'do it all' functions
59 bool parse_json(
60  std::istream &in,
61  const std::string &filename,
62  message_handlert &message_handler,
63  jsont &dest);
64 
65 bool parse_json(
66  const std::string &filename,
67  message_handlert &message_handler,
68  jsont &dest);
69 
70 #endif // CPROVER_JSON_JSON_PARSER_H
json_parser
json_parsert json_parser
Definition: json_parser.cpp:13
parse_json
bool parse_json(std::istream &in, const std::string &filename, message_handlert &message_handler, jsont &dest)
Definition: json_parser.cpp:16
json_parsert
Definition: json_parser.h:23
json_parsert::push
void push(const jsont &x)
Definition: json_parser.h:35
jsont
Definition: json.h:27
json_parsert::clear
virtual void clear() override
Definition: json_parser.h:47
json_parsert::stack
stackt stack
Definition: json_parser.h:26
jsont::swap
void swap(jsont &other)
Definition: json.cpp:161
yyjsonerror
int yyjsonerror(const std::string &error)
message_handlert
Definition: message.h:28
parsert
Definition: parser.h:24
yyjsonrestart
void yyjsonrestart(FILE *input_file)
json_parsert::parse
virtual bool parse() override
Definition: json_parser.h:30
parser.h
Parser utilities.
json.h
json_parsert::pop
void pop(jsont &dest)
Definition: json_parser.h:40
json_parsert::stackt
std::stack< jsont, std::vector< jsont > > stackt
Definition: json_parser.h:25
yyjsonparse
int yyjsonparse()
json_parsert::top
jsont & top()
Definition: json_parser.h:28