JsonLex.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Lex.hpp"
4 
5 #include <stack>
6 
7 namespace iv
8 {
9 
10 class JsonLex
11 {
12 public:
14 
15  enum Token
16  {
22 
25 
29 
31  };
32 
33  JsonLex( Instance * inst );
34  Instance * instance() const;
35 
36  Lex const & lex() const;
37 
38  void Init( std::istream & in );
39  bool Failed();
40  void LogicFail( const char * message ){ this->_lex.LogicFail( message ); }
41 
42  // IsNext
43  bool IsNext( Token );
44 
45  // Accept
46  void Accept( Token );
47 
48  std::string AcceptTableKey();
49 
50  int AcceptInteger();
51  double AcceptDouble();
52  std::string AcceptString();
53  bool AcceptBool();
54  void AcceptNull();
55 
56 private:
57  enum class Next
58  {
59  Value,
60  TableKey,
61 
62  TableEnd,
63  ArrayEnd,
64  Eof
65  };
66 
67  enum class LayerType
68  {
69  Array,
70  Table
71  };
72 
73  void value_ended();
74  void JsonFail();
75 
76 private:
77  Lex _lex;
78  Next next;
79  std::stack< LayerType > layer_types;
80 };
81 
82 }