aboutsummaryrefslogtreecommitdiff
path: root/src/unstable/json.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2019-12-14 21:18:59 -0800
committerMike Buland <eichlan@xagasoft.com>2019-12-14 21:18:59 -0800
commit2ff101097feedf85b0ab0163983159200fc146a2 (patch)
treeb766200d04833e866a65e91945950bbb31f5e969 /src/unstable/json.h
parent8f9337568befa81e82e97abd4d2d75e3a5c5fbe9 (diff)
downloadlibbu++-2ff101097feedf85b0ab0163983159200fc146a2.tar.gz
libbu++-2ff101097feedf85b0ab0163983159200fc146a2.tar.bz2
libbu++-2ff101097feedf85b0ab0163983159200fc146a2.tar.xz
libbu++-2ff101097feedf85b0ab0163983159200fc146a2.zip
Json provides line/char in errors now.
All errors are also rewoked and the parser state is tracked much better. Also fixed a parser issue where it would error correctly, but report it poorly when an object started with something other than a string.
Diffstat (limited to '')
-rw-r--r--src/unstable/json.h39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/unstable/json.h b/src/unstable/json.h
index 5373bcf..a973f74 100644
--- a/src/unstable/json.h
+++ b/src/unstable/json.h
@@ -16,7 +16,22 @@ namespace Bu
16 class Json 16 class Json
17 { 17 {
18 private: 18 private:
19 Json( Bu::UtfChar &c, Bu::Stream &sInput ); 19 class ParseState
20 {
21 public:
22 ParseState( Bu::Stream &sInput ) :
23 c( 0 ), sInput( sInput ), iLine( 1 ), iChar( 0 )
24 {
25 }
26
27 void error( const Bu::String &sTxt );
28
29 Bu::UtfChar c;
30 Bu::Stream &sInput;
31 int iLine;
32 int iChar;
33 };
34 Json( ParseState &ps );
20 typedef Bu::Hash<Bu::UtfString, Json *> JsonHash; 35 typedef Bu::Hash<Bu::UtfString, Json *> JsonHash;
21 typedef Bu::Array<Json *> JsonList; 36 typedef Bu::Array<Json *> JsonList;
22 37
@@ -90,19 +105,17 @@ namespace Bu
90 bool operator==( const Bu::String &rRhs ); 105 bool operator==( const Bu::String &rRhs );
91 106
92 private: 107 private:
93 void parse( Bu::UtfChar &c, Bu::Stream &sInput ); 108 void parse( ParseState &ps );
94 void parseString( Bu::UtfChar &c, Bu::Stream &sInput, 109 void parseString( ParseState &ps, Bu::UtfString &sOut );
95 Bu::UtfString &sOut ); 110 void parseString( ParseState &ps );
96 void parseString( Bu::UtfChar &c, Bu::Stream &sInput ); 111 void parseObject( ParseState &ps );
97 void parseObject( Bu::UtfChar &c, Bu::Stream &sInput ); 112 void parseArray( ParseState &ps );
98 void parseArray( Bu::UtfChar &c, Bu::Stream &sInput ); 113 void parseNumber( ParseState &ps );
99 void parseNumber( Bu::UtfChar &c, Bu::Stream &sInput ); 114 void parseLiteral( ParseState &ps );
100 void parseLiteral( Bu::UtfChar &c, Bu::Stream &sInput ); 115 bool readChar( ParseState &ps );
101 bool readChar( Bu::UtfChar &c, Bu::Stream &sInput ); 116 void readChar( ParseState &ps, const char *sSection );
102 void readChar( Bu::UtfChar &c, Bu::Stream &sInput,
103 const char *sSection );
104 bool isWs( Bu::UtfChar c ); 117 bool isWs( Bu::UtfChar c );
105 void skipWs( Bu::UtfChar &c, Bu::Stream &sInput ); 118 void skipWs( ParseState &ps );
106 void writeStr( const Bu::UtfString &sStr, Bu::Stream &sOutput ) const; 119 void writeStr( const Bu::UtfString &sStr, Bu::Stream &sOutput ) const;
107 120
108 private: 121 private: