Drizzled Public API Documentation

reader.h
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2  *
3  * JSON Library, originally from http://jsoncpp.sourceforge.net/
4  *
5  * Copyright (C) 2011 Stewart Smith
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following disclaimer
17  * in the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * * The names of its contributors may not be used to endorse or
21  * promote products derived from this software without specific prior
22  * written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 
38 #pragma once
39 
40 #include "features.h"
41 #include "value.h"
42 #include <deque>
43 #include <stack>
44 #include <string>
45 #include <iosfwd>
46 
47 namespace Json {
48 
52  class JSON_API Reader
53  {
54  public:
55  typedef char Char;
56  typedef const Char *Location;
57 
61  Reader();
62 
66  Reader( const Features &features );
67 
78  bool parse( const std::string &document,
79  Value &root,
80  bool collectComments = true );
81 
92  bool parse( const char *beginDoc, const char *endDoc,
93  Value &root,
94  bool collectComments = true );
95 
98  bool parse( std::istream &is,
99  Value &root,
100  bool collectComments = true );
101 
107  std::string getFormatedErrorMessages() const;
108 
109  private:
110  enum TokenType
111  {
112  tokenEndOfStream = 0,
113  tokenObjectBegin,
114  tokenObjectEnd,
115  tokenArrayBegin,
116  tokenArrayEnd,
117  tokenString,
118  tokenNumber,
119  tokenTrue,
120  tokenFalse,
121  tokenNull,
122  tokenArraySeparator,
123  tokenMemberSeparator,
124  tokenComment,
125  tokenError
126  };
127 
128  class Token
129  {
130  public:
131  TokenType type_;
132  Location start_;
133  Location end_;
134  };
135 
136  class ErrorInfo
137  {
138  public:
139  Token token_;
140  std::string message_;
141  Location extra_;
142  };
143 
144  typedef std::deque<ErrorInfo> Errors;
145 
146  bool expectToken( TokenType type, Token &token, const char *message );
147  bool readToken( Token &token );
148  void skipSpaces();
149  bool match( Location pattern,
150  int patternLength );
151  bool readComment();
152  bool readCStyleComment();
153  bool readCppStyleComment();
154  bool readString();
155  void readNumber();
156  bool readValue();
157  bool readObject( Token &token );
158  bool readArray( Token &token );
159  bool decodeNumber( Token &token );
160  bool decodeString( Token &token );
161  bool decodeString( Token &token, std::string &decoded );
162  bool decodeDouble( Token &token );
163  bool decodeUnicodeCodePoint( Token &token,
164  Location &current,
165  Location end,
166  unsigned int &unicode );
167  bool decodeUnicodeEscapeSequence( Token &token,
168  Location &current,
169  Location end,
170  unsigned int &unicode );
171  bool addError( const std::string &message,
172  Token &token,
173  Location extra = 0 );
174  bool recoverFromError( TokenType skipUntilToken );
175  bool addErrorAndRecover( const std::string &message,
176  Token &token,
177  TokenType skipUntilToken );
178  void skipUntilSpace();
179  Value &currentValue();
180  Char getNextChar();
181  void getLocationLineAndColumn( Location location,
182  int &line,
183  int &column ) const;
184  std::string getLocationLineAndColumn( Location location ) const;
185  void addComment( Location begin,
186  Location end,
187  CommentPlacement placement );
188  void skipCommentTokens( Token &token );
189 
190  typedef std::stack<Value *> Nodes;
191  Nodes nodes_;
192  Errors errors_;
193  std::string document_;
194  Location begin_;
195  Location end_;
196  Location current_;
197  Location lastValueEnd_;
198  Value *lastValue_;
199  std::string commentsBefore_;
200  Features features_;
201  bool collectComments_;
202  };
203 
228  std::istream& operator>>( std::istream&, Value& );
229 
230 } // namespace Json
void parse(Session &, str_ref)
Definition: sql_parse.cc:747
Represents a JSON value.
Definition: value.h:149
Configuration passed to reader and writer. This configuration object can be used to force the Reader ...
Definition: features.h:50
JSON (JavaScript Object Notation).
Definition: features.h:44
std::istream & operator>>(std::istream &sin, Value &root)
Read from 'sin' into 'root'.
CommentPlacement
Definition: value.h:73
Unserialize a JSON document into a Value.
Definition: reader.h:52