|
|
|
@ -1796,10 +1796,27 @@ bool Parser::ParseReserved(DescriptorProto* message, |
|
|
|
|
// Parse the declaration.
|
|
|
|
|
DO(Consume("reserved")); |
|
|
|
|
if (LookingAtType(io::Tokenizer::TYPE_STRING)) { |
|
|
|
|
if (syntax_identifier_ == "editions") { |
|
|
|
|
RecordError( |
|
|
|
|
"Reserved names must be identifiers in editions, not string " |
|
|
|
|
"literals."); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
LocationRecorder location(message_location, |
|
|
|
|
DescriptorProto::kReservedNameFieldNumber); |
|
|
|
|
location.StartAt(start_token); |
|
|
|
|
return ParseReservedNames(message, location); |
|
|
|
|
} else if (LookingAtType(io::Tokenizer::TYPE_IDENTIFIER)) { |
|
|
|
|
if (syntax_identifier_ != "editions") { |
|
|
|
|
RecordError( |
|
|
|
|
"Reserved names must be string literals. (Only editions supports " |
|
|
|
|
"identifiers.)"); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
LocationRecorder location(message_location, |
|
|
|
|
DescriptorProto::kReservedNameFieldNumber); |
|
|
|
|
location.StartAt(start_token); |
|
|
|
|
return ParseReservedIdentifiers(message, location); |
|
|
|
|
} else { |
|
|
|
|
LocationRecorder location(message_location, |
|
|
|
|
DescriptorProto::kReservedRangeFieldNumber); |
|
|
|
@ -1828,7 +1845,25 @@ bool Parser::ParseReservedNames(DescriptorProto* message, |
|
|
|
|
const LocationRecorder& parent_location) { |
|
|
|
|
do { |
|
|
|
|
LocationRecorder location(parent_location, message->reserved_name_size()); |
|
|
|
|
DO(ParseReservedName(message->add_reserved_name(), "Expected field name.")); |
|
|
|
|
DO(ParseReservedName(message->add_reserved_name(), |
|
|
|
|
"Expected field name string literal.")); |
|
|
|
|
} while (TryConsume(",")); |
|
|
|
|
DO(ConsumeEndOfDeclaration(";", &parent_location)); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Parser::ParseReservedIdentifier(std::string* name, |
|
|
|
|
absl::string_view error_message) { |
|
|
|
|
DO(ConsumeIdentifier(name, error_message)); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Parser::ParseReservedIdentifiers(DescriptorProto* message, |
|
|
|
|
const LocationRecorder& parent_location) { |
|
|
|
|
do { |
|
|
|
|
LocationRecorder location(parent_location, message->reserved_name_size()); |
|
|
|
|
DO(ParseReservedIdentifier(message->add_reserved_name(), |
|
|
|
|
"Expected field name identifier.")); |
|
|
|
|
} while (TryConsume(",")); |
|
|
|
|
DO(ConsumeEndOfDeclaration(";", &parent_location)); |
|
|
|
|
return true; |
|
|
|
@ -1889,10 +1924,27 @@ bool Parser::ParseReserved(EnumDescriptorProto* proto, |
|
|
|
|
// Parse the declaration.
|
|
|
|
|
DO(Consume("reserved")); |
|
|
|
|
if (LookingAtType(io::Tokenizer::TYPE_STRING)) { |
|
|
|
|
if (syntax_identifier_ == "editions") { |
|
|
|
|
RecordError( |
|
|
|
|
"Reserved names must be identifiers in editions, not string " |
|
|
|
|
"literals."); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
LocationRecorder location(enum_location, |
|
|
|
|
EnumDescriptorProto::kReservedNameFieldNumber); |
|
|
|
|
location.StartAt(start_token); |
|
|
|
|
return ParseReservedNames(proto, location); |
|
|
|
|
} else if (LookingAtType(io::Tokenizer::TYPE_IDENTIFIER)) { |
|
|
|
|
if (syntax_identifier_ != "editions") { |
|
|
|
|
RecordError( |
|
|
|
|
"Reserved names must be string literals. (Only editions supports " |
|
|
|
|
"identifiers.)"); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
LocationRecorder location(enum_location, |
|
|
|
|
EnumDescriptorProto::kReservedNameFieldNumber); |
|
|
|
|
location.StartAt(start_token); |
|
|
|
|
return ParseReservedIdentifiers(proto, location); |
|
|
|
|
} else { |
|
|
|
|
LocationRecorder location(enum_location, |
|
|
|
|
EnumDescriptorProto::kReservedRangeFieldNumber); |
|
|
|
@ -1905,7 +1957,19 @@ bool Parser::ParseReservedNames(EnumDescriptorProto* proto, |
|
|
|
|
const LocationRecorder& parent_location) { |
|
|
|
|
do { |
|
|
|
|
LocationRecorder location(parent_location, proto->reserved_name_size()); |
|
|
|
|
DO(ParseReservedName(proto->add_reserved_name(), "Expected enum value.")); |
|
|
|
|
DO(ParseReservedName(proto->add_reserved_name(), |
|
|
|
|
"Expected enum value string literal.")); |
|
|
|
|
} while (TryConsume(",")); |
|
|
|
|
DO(ConsumeEndOfDeclaration(";", &parent_location)); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Parser::ParseReservedIdentifiers(EnumDescriptorProto* proto, |
|
|
|
|
const LocationRecorder& parent_location) { |
|
|
|
|
do { |
|
|
|
|
LocationRecorder location(parent_location, proto->reserved_name_size()); |
|
|
|
|
DO(ParseReservedIdentifier(proto->add_reserved_name(), |
|
|
|
|
"Expected enum value identifier.")); |
|
|
|
|
} while (TryConsume(",")); |
|
|
|
|
DO(ConsumeEndOfDeclaration(";", &parent_location)); |
|
|
|
|
return true; |
|
|
|
|