summaryrefslogtreecommitdiff
path: root/include/lib/modernjson/detail/input/parser.hpp
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-11-26 09:06:31 +0100
committerDaniel Friesel <derf@finalrewind.org>2018-11-26 09:06:31 +0100
commit1542f34f0e0fc53324f6fdc5905f4b77b252a789 (patch)
treed2126bc53f8759c36809ff25b9ae3a19fd7aa362 /include/lib/modernjson/detail/input/parser.hpp
parente7711c06640f098323cab80934c198090e9120a3 (diff)
update nlohmann modernjson to v3.4 (with bson support)
Diffstat (limited to 'include/lib/modernjson/detail/input/parser.hpp')
-rw-r--r--include/lib/modernjson/detail/input/parser.hpp60
1 files changed, 38 insertions, 22 deletions
diff --git a/include/lib/modernjson/detail/input/parser.hpp b/include/lib/modernjson/detail/input/parser.hpp
index a622077..d205bbb 100644
--- a/include/lib/modernjson/detail/input/parser.hpp
+++ b/include/lib/modernjson/detail/input/parser.hpp
@@ -91,7 +91,8 @@ class parser
{
sdp.parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input)));
+ parse_error::create(101, m_lexer.get_position(),
+ exception_message(token_type::end_of_input, "value")));
}
// in case of an error, return discarded value
@@ -119,7 +120,8 @@ class parser
{
sdp.parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input)));
+ parse_error::create(101, m_lexer.get_position(),
+ exception_message(token_type::end_of_input, "value")));
}
// in case of an error, return discarded value
@@ -154,7 +156,8 @@ class parser
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input)));
+ parse_error::create(101, m_lexer.get_position(),
+ exception_message(token_type::end_of_input, "value")));
}
return result;
@@ -164,7 +167,7 @@ class parser
template <typename SAX>
bool sax_parse_internal(SAX* sax)
{
- // stack to remember the hieararchy of structured values we are parsing
+ // stack to remember the hierarchy of structured values we are parsing
// true = array; false = object
std::vector<bool> states;
// value to avoid a goto (see comment where set to true)
@@ -199,14 +202,12 @@ class parser
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string)));
+ parse_error::create(101, m_lexer.get_position(),
+ exception_message(token_type::value_string, "object key")));
}
- else
+ if (JSON_UNLIKELY(not sax->key(m_lexer.get_string())))
{
- if (JSON_UNLIKELY(not sax->key(m_lexer.get_string())))
- {
- return false;
- }
+ return false;
}
// parse separator (:)
@@ -214,7 +215,8 @@ class parser
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator)));
+ parse_error::create(101, m_lexer.get_position(),
+ exception_message(token_type::name_separator, "object separator")));
}
// remember we are now inside an object
@@ -328,14 +330,16 @@ class parser
// using "uninitialized" to avoid "expected" message
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized)));
+ parse_error::create(101, m_lexer.get_position(),
+ exception_message(token_type::uninitialized, "value")));
}
default: // the last token was unexpected
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value)));
+ parse_error::create(101, m_lexer.get_position(),
+ exception_message(token_type::literal_or_value, "value")));
}
}
}
@@ -347,7 +351,7 @@ class parser
// we reached this line after we successfully parsed a value
if (states.empty())
{
- // empty stack: we reached the end of the hieararchy: done
+ // empty stack: we reached the end of the hierarchy: done
return true;
}
else
@@ -383,7 +387,8 @@ class parser
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array)));
+ parse_error::create(101, m_lexer.get_position(),
+ exception_message(token_type::end_array, "array")));
}
}
else // object
@@ -396,7 +401,8 @@ class parser
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string)));
+ parse_error::create(101, m_lexer.get_position(),
+ exception_message(token_type::value_string, "object key")));
}
else
{
@@ -411,7 +417,8 @@ class parser
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator)));
+ parse_error::create(101, m_lexer.get_position(),
+ exception_message(token_type::name_separator, "object separator")));
}
// parse values
@@ -440,7 +447,8 @@ class parser
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object)));
+ parse_error::create(101, m_lexer.get_position(),
+ exception_message(token_type::end_object, "object")));
}
}
}
@@ -453,9 +461,17 @@ class parser
return (last_token = m_lexer.scan());
}
- std::string exception_message(const token_type expected)
+ std::string exception_message(const token_type expected, const std::string& context)
{
- std::string error_msg = "syntax error - ";
+ std::string error_msg = "syntax error ";
+
+ if (not context.empty())
+ {
+ error_msg += "while parsing " + context + " ";
+ }
+
+ error_msg += "- ";
+
if (last_token == token_type::parse_error)
{
error_msg += std::string(m_lexer.get_error_message()) + "; last read: '" +
@@ -484,5 +500,5 @@ class parser
/// whether to throw exceptions in case of errors
const bool allow_exceptions = true;
};
-}
-}
+} // namespace detail
+} // namespace nlohmann