From 2ff101097feedf85b0ab0163983159200fc146a2 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 14 Dec 2019 21:18:59 -0800 Subject: 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. --- src/unstable/json.h | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'src/unstable/json.h') 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 class Json { private: - Json( Bu::UtfChar &c, Bu::Stream &sInput ); + class ParseState + { + public: + ParseState( Bu::Stream &sInput ) : + c( 0 ), sInput( sInput ), iLine( 1 ), iChar( 0 ) + { + } + + void error( const Bu::String &sTxt ); + + Bu::UtfChar c; + Bu::Stream &sInput; + int iLine; + int iChar; + }; + Json( ParseState &ps ); typedef Bu::Hash JsonHash; typedef Bu::Array JsonList; @@ -90,19 +105,17 @@ namespace Bu bool operator==( const Bu::String &rRhs ); private: - void parse( Bu::UtfChar &c, Bu::Stream &sInput ); - void parseString( Bu::UtfChar &c, Bu::Stream &sInput, - Bu::UtfString &sOut ); - void parseString( Bu::UtfChar &c, Bu::Stream &sInput ); - void parseObject( Bu::UtfChar &c, Bu::Stream &sInput ); - void parseArray( Bu::UtfChar &c, Bu::Stream &sInput ); - void parseNumber( Bu::UtfChar &c, Bu::Stream &sInput ); - void parseLiteral( Bu::UtfChar &c, Bu::Stream &sInput ); - bool readChar( Bu::UtfChar &c, Bu::Stream &sInput ); - void readChar( Bu::UtfChar &c, Bu::Stream &sInput, - const char *sSection ); + void parse( ParseState &ps ); + void parseString( ParseState &ps, Bu::UtfString &sOut ); + void parseString( ParseState &ps ); + void parseObject( ParseState &ps ); + void parseArray( ParseState &ps ); + void parseNumber( ParseState &ps ); + void parseLiteral( ParseState &ps ); + bool readChar( ParseState &ps ); + void readChar( ParseState &ps, const char *sSection ); bool isWs( Bu::UtfChar c ); - void skipWs( Bu::UtfChar &c, Bu::Stream &sInput ); + void skipWs( ParseState &ps ); void writeStr( const Bu::UtfString &sStr, Bu::Stream &sOutput ) const; private: -- cgit v1.2.3