Argo  1.0
A C++ library for handling JSON.
lexer.hpp
Go to the documentation of this file.
1 #ifndef _json_lexer_hpp_
2 #define _json_lexer_hpp_
3 
4 /*
5  * Copyright (c) 2017 Andrew Haisley
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
27 
28 #include "common.hpp"
29 #include "token.hpp"
30 #include "reader.hpp"
31 
32 namespace NAMESPACE
33 {
41  class lexer
42  {
43  public:
44 
49  lexer(reader &r, size_t max_token_length);
50 
54  virtual ~lexer();
55 
63  const token &next();
64 
70  void put_back_last();
71 
72  private:
73 
78  void consume_white_space();
79 
84  void read_token();
85 
91  void read_number();
92 
96  void read_string();
97 
102  void read_false();
103 
108  void read_true();
109 
114  void read_null();
115 
121  void read_matching(const char *s);
122 
129  void append_to_number_buffer(char *s, size_t &index, int c);
130 
136  size_t read_digits(size_t &index);
137 
142  void throw_number_exception(int c);
143 
145  reader &m_reader;
146 
148  bool m_last_put_back;
149 
151  token m_token;
152 
154  size_t m_max_token_length;
155 
156  /*
157  * Buffer holding the token raw value. This is dynamically allocated so
158  * as to avoid placing a very large object on the stack.
159  */
160  char *m_buffer;
161  };
162 }
163 
164 #endif
A class to read JSON messages from various types of input stream.
Definition: reader.hpp:42
#define NAMESPACE
You can change the namespace of the whole library by changing this value.
Definition: common.hpp:29
The token class.
Common defs needed everywhere and, as far as is possible, platform specific changes.
Lexical tokens read from a JSON message.
Definition: token.hpp:41
A lexical analyser for JSON messages.
Definition: lexer.hpp:41
The reader class.