diff options
author | Wouter van Oortmerssen <wvo@google.com> | 2016-01-08 15:18:51 -0800 |
---|---|---|
committer | Wouter van Oortmerssen <wvo@google.com> | 2016-01-19 14:05:27 -0800 |
commit | 049f3f7907e9fc8eb1ecd7c3775139de65552585 (patch) | |
tree | 6723a14f75b7bf9b6d1b42064d5927a90c96b572 /src | |
parent | e848137ded3524c60faa6def429807faae5340e0 (diff) | |
download | flatbuffers-049f3f7907e9fc8eb1ecd7c3775139de65552585.tar.gz flatbuffers-049f3f7907e9fc8eb1ecd7c3775139de65552585.tar.bz2 flatbuffers-049f3f7907e9fc8eb1ecd7c3775139de65552585.zip |
Added support for parsing JSON null value.
These cause the field in question to be skipped.
Bug: 16550393
Change-Id: Id05104e89818ee773b8a91fdcc86e18061b9a82f
Tested: on Linux.
Diffstat (limited to 'src')
-rw-r--r-- | src/idl_parser.cpp | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index e4013e8d..2312c3ac 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -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; |