diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2014-12-05 13:52:40 +0100 |
---|---|---|
committer | Andreas Stöckel <andreas@somweyr.de> | 2014-12-05 13:52:40 +0100 |
commit | ddbea4164e126739f39658627c04e7e23b71e090 (patch) | |
tree | bdac63cf2a1c73fd3f67fa03fc821ef4eaf93b83 /src/core/variant | |
parent | 3d6058315f7f0da9994e35c144d0acb76a252472 (diff) | |
parent | 9cb01624a4efe2063d5870f41e033476d9368b6d (diff) |
fixed conflict
Diffstat (limited to 'src/core/variant')
-rw-r--r-- | src/core/variant/Reader.cpp | 14 | ||||
-rw-r--r-- | src/core/variant/Reader.hpp | 54 |
2 files changed, 21 insertions, 47 deletions
diff --git a/src/core/variant/Reader.cpp b/src/core/variant/Reader.cpp index 6142ecf..e9a58a1 100644 --- a/src/core/variant/Reader.cpp +++ b/src/core/variant/Reader.cpp @@ -26,12 +26,17 @@ namespace ousia { namespace variant { +static const char *ERR_UNEXPECTED_CHARACTER = "Unexpected character"; +static const char *ERR_UNEXPECTED_END = "Unexpected end"; +static const char *ERR_UNTERMINATED = "Unterminated literal"; + static const int STATE_INIT = 0; static const int STATE_IN_STRING = 1; static const int STATE_ESCAPE = 2; static std::pair<Err, std::string> parseString( - BufferedCharReader &reader, const unordered_set<char> *delims = nullptr) + BufferedCharReader &reader, const unordered_set<char> *delims = nullptr, + Logger *logger = nullptr) { // Initialize the internal state Err errCode = Err::OK; @@ -51,9 +56,13 @@ static std::pair<Err, std::string> parseString( quote = c; state = STATE_IN_STRING; } else if (delims && delims.count(c)) { + Logger.log(ERR_UNTERMINATED, reader); return std::make_pair(Err::UNEXPECTED_END, res.str()); + } else if (Utils::isWhitespace(c)) { + reader.consumePeek(); + continue; } - reader.consumePeek(); + return std::make_pair(Err::UNEXPECTED_CHARACTER, res.str()); break; case STATE_IN_STRING: if (c == q) { @@ -171,7 +180,6 @@ static std::pair<Err, Variant> parseGeneric(BufferedCharReader &reader, } return std::make_pair(Err::UNEXPECTED_END, res.str()); } - } } diff --git a/src/core/variant/Reader.hpp b/src/core/variant/Reader.hpp index 3f945f0..339127f 100644 --- a/src/core/variant/Reader.hpp +++ b/src/core/variant/Reader.hpp @@ -32,6 +32,7 @@ #include <utility> #include <core/BufferedCharReader.hpp> +#include <core/Logger.hpp> #include "Variant.hpp" @@ -40,44 +41,6 @@ namespace variant { class Reader { public: - // TODO: Pass logger instance instead of using error codes? - - /** - * The Err enum describes possible error codes that may be encountered when - * parsing the microtypes. - */ - enum class Err : int { - /** - * Reached the end of the stream, but expected more data. - */ - ERR_UNEXPECTED_END = -1, - - /** - * The stream is malformed. - */ - ERR_MALFORMED = -2, - - /** - * Unexpected character. - */ - ERR_UNEXPECTED_CHARACTER = -3, - - /** - * Unterminated literal. - */ - ERR_UNTERMINATED = -4, - - /** - * Invalid escape character. - */ - ERR_INVALID_ESCAPE = -5, - - /** - * A value of the requested type was extracted successfully. - */ - OK = 0 - }; - /** * Parses a string which may either be enclosed by " or ', unescapes * entities in the string as specified for JavaScript. @@ -91,9 +54,10 @@ public: * outside). If nullptr is given, no delimiter is used and a complete string * is read. */ - static std::pair<Err, std::string> parseString( + static std::pair<bool, std::string> parseString( BufferedCharReader &reader, - const unordered_set<char> *delims = nullptr); + const unordered_set<char> *delims = nullptr, + Logger *logger = nullptr); /** * Extracts an unescaped string from the given buffered char reader @@ -106,8 +70,9 @@ public: * @param delims is a set of characters which will terminate the string. * These characters are not included in the result. May not be nullptr. */ - static std::pair<Err, std::string> parseUnescapedString( - BufferedCharReader &reader, const unordered_set<char> *delims); + static std::pair<bool, std::string> parseUnescapedString( + BufferedCharReader &reader, const unordered_set<char> *delims, + Logger *logger = nullptr); /** * Tries to parse the most specific item from the given stream until one of @@ -120,8 +85,9 @@ public: * @param delims is a set of characters which will terminate the string. * These characters are not included in the result. May not be nullptr. */ - static std::pair<Err, Variant> parseGeneric( - BufferedCharReader &reader, const unordered_set<char> *delims); + static std::pair<bool, Variant> parseGeneric( + BufferedCharReader &reader, const unordered_set<char> *delims, + Logger *logger = nullptr); }; } } |