Added support for parsing JSON null value.

These cause the field in question to be skipped.

Bug: 16550393
Change-Id: Id05104e89818ee773b8a91fdcc86e18061b9a82f
Tested: on Linux.
This commit is contained in:
Wouter van Oortmerssen
2016-01-08 15:18:51 -08:00
parent e848137ded
commit 049f3f7907
4 changed files with 30 additions and 16 deletions

View File

@@ -151,7 +151,8 @@ std::string Namespace::GetFullyQualifiedName(const std::string &name,
TD(FileIdentifier, 267, "file_identifier") \
TD(FileExtension, 268, "file_extension") \
TD(Include, 269, "include") \
TD(Attribute, 270, "attribute")
TD(Attribute, 270, "attribute") \
TD(Null, 271, "null")
#ifdef __GNUC__
__extension__ // Stop GCC complaining about trailing comma with -Wpendantic.
#endif
@@ -343,6 +344,10 @@ CheckedError Parser::Next() {
token_ = kTokenFileExtension;
return NoError();
}
if (attribute_ == "null") {
token_ = kTokenNull;
return NoError();
}
// If not, it is a user-defined identifier:
token_ = kTokenIdentifier;
return NoError();
@@ -688,19 +693,23 @@ CheckedError Parser::ParseTable(const StructDef &struct_def, std::string *value,
}
} else {
EXPECT(':');
Value val = field->value;
ECHECK(ParseAnyValue(val, field, fieldn));
size_t i = field_stack_.size();
// Hardcoded insertion-sort with error-check.
// If fields are specified in order, then this loop exits immediately.
for (; i > field_stack_.size() - fieldn; i--) {
auto existing_field = field_stack_[i - 1].second;
if (existing_field == field)
return Error("field set more than once: " + field->name);
if (existing_field->value.offset < field->value.offset) break;
if (Is(kTokenNull)) {
NEXT(); // Ignore this field.
} else {
Value val = field->value;
ECHECK(ParseAnyValue(val, field, fieldn));
size_t i = field_stack_.size();
// Hardcoded insertion-sort with error-check.
// If fields are specified in order, then this loop exits immediately.
for (; i > field_stack_.size() - fieldn; i--) {
auto existing_field = field_stack_[i - 1].second;
if (existing_field == field)
return Error("field set more than once: " + field->name);
if (existing_field->value.offset < field->value.offset) break;
}
field_stack_.insert(field_stack_.begin() + i, std::make_pair(val, field));
fieldn++;
}
field_stack_.insert(field_stack_.begin() + i, std::make_pair(val, field));
fieldn++;
}
if (Is('}')) { NEXT(); break; }
EXPECT(',');
@@ -1542,10 +1551,10 @@ CheckedError Parser::SkipJsonObject() {
CheckedError Parser::SkipJsonArray() {
EXPECT('[');
for (;;) {
if (Is(']')) break;
ECHECK(SkipAnyJsonValue());
if (Is(']')) break;