250
250
AddError(input_->current().line, input_->current().column, error);
253
void Parser::RecordLocation(
254
const Message* descriptor,
255
DescriptorPool::ErrorCollector::ErrorLocation location,
256
int line, int column) {
257
if (source_location_table_ != NULL) {
258
source_location_table_->Add(descriptor, location, line, column);
262
void Parser::RecordLocation(
263
const Message* descriptor,
253
// -------------------------------------------------------------------
255
Parser::LocationRecorder::LocationRecorder(Parser* parser)
257
location_(parser_->source_code_info_->add_location()) {
258
location_->add_span(parser_->input_->current().line);
259
location_->add_span(parser_->input_->current().column);
262
Parser::LocationRecorder::LocationRecorder(const LocationRecorder& parent) {
266
Parser::LocationRecorder::LocationRecorder(const LocationRecorder& parent,
272
Parser::LocationRecorder::LocationRecorder(const LocationRecorder& parent,
273
int path1, int path2) {
279
void Parser::LocationRecorder::Init(const LocationRecorder& parent) {
280
parser_ = parent.parser_;
281
location_ = parser_->source_code_info_->add_location();
282
location_->mutable_path()->CopyFrom(parent.location_->path());
284
location_->add_span(parser_->input_->current().line);
285
location_->add_span(parser_->input_->current().column);
288
Parser::LocationRecorder::~LocationRecorder() {
289
if (location_->span_size() <= 2) {
290
EndAt(parser_->input_->previous());
294
void Parser::LocationRecorder::AddPath(int path_component) {
295
location_->add_path(path_component);
298
void Parser::LocationRecorder::StartAt(const io::Tokenizer::Token& token) {
299
location_->set_span(0, token.line);
300
location_->set_span(1, token.column);
303
void Parser::LocationRecorder::EndAt(const io::Tokenizer::Token& token) {
304
if (token.line != location_->span(0)) {
305
location_->add_span(token.line);
307
location_->add_span(token.end_column);
310
void Parser::LocationRecorder::RecordLegacyLocation(const Message* descriptor,
264
311
DescriptorPool::ErrorCollector::ErrorLocation location) {
265
RecordLocation(descriptor, location,
266
input_->current().line, input_->current().column);
312
if (parser_->source_location_table_ != NULL) {
313
parser_->source_location_table_->Add(
314
descriptor, location, location_->span(0), location_->span(1));
269
318
// -------------------------------------------------------------------
308
357
had_errors_ = false;
309
358
syntax_identifier_.clear();
360
// Note that |file| could be NULL at this point if
361
// stop_after_syntax_identifier_ is true. So, we conservatively allocate
362
// SourceCodeInfo on the stack, then swap it into the FileDescriptorProto
364
SourceCodeInfo source_code_info;
365
source_code_info_ = &source_code_info;
311
367
if (LookingAtType(io::Tokenizer::TYPE_START)) {
312
368
// Advance to first token.
316
if (require_syntax_identifier_ || LookingAt("syntax")) {
317
if (!ParseSyntaxIdentifier()) {
318
// Don't attempt to parse the file if we didn't recognize the syntax
373
LocationRecorder root_location(this);
375
if (require_syntax_identifier_ || LookingAt("syntax")) {
376
if (!ParseSyntaxIdentifier()) {
377
// Don't attempt to parse the file if we didn't recognize the syntax
381
} else if (!stop_after_syntax_identifier_) {
382
syntax_identifier_ = "proto2";
322
} else if (!stop_after_syntax_identifier_) {
323
syntax_identifier_ = "proto2";
326
if (stop_after_syntax_identifier_) return !had_errors_;
328
// Repeatedly parse statements until we reach the end of the file.
330
if (!ParseTopLevelStatement(file)) {
331
// This statement failed to parse. Skip it, but keep looping to parse
335
if (LookingAt("}")) {
336
AddError("Unmatched \"}\".");
385
if (stop_after_syntax_identifier_) return !had_errors_;
387
// Repeatedly parse statements until we reach the end of the file.
389
if (!ParseTopLevelStatement(file, root_location)) {
390
// This statement failed to parse. Skip it, but keep looping to parse
394
if (LookingAt("}")) {
395
AddError("Unmatched \"}\".");
403
source_code_info_ = NULL;
404
source_code_info.Swap(file->mutable_source_code_info());
343
405
return !had_errors_;
366
bool Parser::ParseTopLevelStatement(FileDescriptorProto* file) {
428
bool Parser::ParseTopLevelStatement(FileDescriptorProto* file,
429
const LocationRecorder& root_location) {
367
430
if (TryConsume(";")) {
368
431
// empty statement; ignore
370
433
} else if (LookingAt("message")) {
371
return ParseMessageDefinition(file->add_message_type());
434
LocationRecorder location(root_location,
435
FileDescriptorProto::kMessageTypeFieldNumber, file->message_type_size());
436
return ParseMessageDefinition(file->add_message_type(), location);
372
437
} else if (LookingAt("enum")) {
373
return ParseEnumDefinition(file->add_enum_type());
438
LocationRecorder location(root_location,
439
FileDescriptorProto::kEnumTypeFieldNumber, file->enum_type_size());
440
return ParseEnumDefinition(file->add_enum_type(), location);
374
441
} else if (LookingAt("service")) {
375
return ParseServiceDefinition(file->add_service());
442
LocationRecorder location(root_location,
443
FileDescriptorProto::kServiceFieldNumber, file->service_size());
444
return ParseServiceDefinition(file->add_service(), location);
376
445
} else if (LookingAt("extend")) {
446
LocationRecorder location(root_location,
447
FileDescriptorProto::kExtensionFieldNumber);
377
448
return ParseExtend(file->mutable_extension(),
378
file->mutable_message_type());
449
file->mutable_message_type(),
451
FileDescriptorProto::kMessageTypeFieldNumber,
379
453
} else if (LookingAt("import")) {
380
return ParseImport(file->add_dependency());
454
int index = file->dependency_size();
455
return ParseImport(file->add_dependency(), root_location, index);
381
456
} else if (LookingAt("package")) {
382
return ParsePackage(file);
457
return ParsePackage(file, root_location);
383
458
} else if (LookingAt("option")) {
384
return ParseOption(file->mutable_options());
459
LocationRecorder location(root_location,
460
FileDescriptorProto::kOptionsFieldNumber);
461
return ParseOption(file->mutable_options(), location);
386
463
AddError("Expected top-level statement (e.g. \"message\").");
421
bool Parser::ParseMessageStatement(DescriptorProto* message) {
505
bool Parser::ParseMessageStatement(DescriptorProto* message,
506
const LocationRecorder& message_location) {
422
507
if (TryConsume(";")) {
423
508
// empty statement; ignore
425
510
} else if (LookingAt("message")) {
426
return ParseMessageDefinition(message->add_nested_type());
511
LocationRecorder location(message_location,
512
DescriptorProto::kNestedTypeFieldNumber,
513
message->nested_type_size());
514
return ParseMessageDefinition(message->add_nested_type(), location);
427
515
} else if (LookingAt("enum")) {
428
return ParseEnumDefinition(message->add_enum_type());
516
LocationRecorder location(message_location,
517
DescriptorProto::kEnumTypeFieldNumber,
518
message->enum_type_size());
519
return ParseEnumDefinition(message->add_enum_type(), location);
429
520
} else if (LookingAt("extensions")) {
430
return ParseExtensions(message);
521
LocationRecorder location(message_location,
522
DescriptorProto::kExtensionRangeFieldNumber);
523
return ParseExtensions(message, location);
431
524
} else if (LookingAt("extend")) {
525
LocationRecorder location(message_location,
526
DescriptorProto::kExtensionFieldNumber);
432
527
return ParseExtend(message->mutable_extension(),
433
message->mutable_nested_type());
528
message->mutable_nested_type(),
530
DescriptorProto::kNestedTypeFieldNumber,
434
532
} else if (LookingAt("option")) {
435
return ParseOption(message->mutable_options());
533
LocationRecorder location(message_location,
534
DescriptorProto::kOptionsFieldNumber);
535
return ParseOption(message->mutable_options(), location);
537
LocationRecorder location(message_location,
538
DescriptorProto::kFieldFieldNumber,
539
message->field_size());
437
540
return ParseMessageField(message->add_field(),
438
message->mutable_nested_type());
541
message->mutable_nested_type(),
543
DescriptorProto::kNestedTypeFieldNumber,
442
548
bool Parser::ParseMessageField(FieldDescriptorProto* field,
443
RepeatedPtrField<DescriptorProto>* messages) {
549
RepeatedPtrField<DescriptorProto>* messages,
550
const LocationRecorder& parent_location,
551
int location_field_number_for_nested_type,
552
const LocationRecorder& field_location) {
444
553
// Parse label and type.
445
FieldDescriptorProto::Label label;
446
DO(ParseLabel(&label));
447
field->set_label(label);
449
RecordLocation(field, DescriptorPool::ErrorCollector::TYPE);
450
FieldDescriptorProto::Type type = FieldDescriptorProto::TYPE_INT32;
452
DO(ParseType(&type, &type_name));
453
if (type_name.empty()) {
454
field->set_type(type);
456
field->set_type_name(type_name);
554
io::Tokenizer::Token label_token = input_->current();
556
LocationRecorder location(field_location,
557
FieldDescriptorProto::kLabelFieldNumber);
558
FieldDescriptorProto::Label label;
559
DO(ParseLabel(&label));
560
field->set_label(label);
564
LocationRecorder location(field_location); // add path later
565
location.RecordLegacyLocation(field, DescriptorPool::ErrorCollector::TYPE);
567
FieldDescriptorProto::Type type = FieldDescriptorProto::TYPE_INT32;
569
DO(ParseType(&type, &type_name));
570
if (type_name.empty()) {
571
location.AddPath(FieldDescriptorProto::kTypeFieldNumber);
572
field->set_type(type);
574
location.AddPath(FieldDescriptorProto::kTypeNameFieldNumber);
575
field->set_type_name(type_name);
459
579
// Parse name and '='.
460
RecordLocation(field, DescriptorPool::ErrorCollector::NAME);
461
580
io::Tokenizer::Token name_token = input_->current();
462
DO(ConsumeIdentifier(field->mutable_name(), "Expected field name."));
582
LocationRecorder location(field_location,
583
FieldDescriptorProto::kNameFieldNumber);
584
location.RecordLegacyLocation(field, DescriptorPool::ErrorCollector::NAME);
585
DO(ConsumeIdentifier(field->mutable_name(), "Expected field name."));
463
587
DO(Consume("=", "Missing field number."));
465
589
// Parse field number.
466
RecordLocation(field, DescriptorPool::ErrorCollector::NUMBER);
468
DO(ConsumeInteger(&number, "Expected field number."));
469
field->set_number(number);
591
LocationRecorder location(field_location,
592
FieldDescriptorProto::kNumberFieldNumber);
593
location.RecordLegacyLocation(
594
field, DescriptorPool::ErrorCollector::NUMBER);
596
DO(ConsumeInteger(&number, "Expected field number."));
597
field->set_number(number);
471
600
// Parse options.
472
DO(ParseFieldOptions(field));
601
DO(ParseFieldOptions(field, field_location));
474
603
// Deal with groups.
475
if (type_name.empty() && type == FieldDescriptorProto::TYPE_GROUP) {
604
if (field->has_type() && field->type() == FieldDescriptorProto::TYPE_GROUP) {
605
// Awkward: Since a group declares both a message type and a field, we
606
// have to create overlapping locations.
607
LocationRecorder group_location(parent_location);
608
group_location.StartAt(label_token);
609
group_location.AddPath(location_field_number_for_nested_type);
610
group_location.AddPath(messages->size());
476
612
DescriptorProto* group = messages->Add();
477
613
group->set_name(field->name());
478
615
// Record name location to match the field name's location.
479
RecordLocation(group, DescriptorPool::ErrorCollector::NAME,
480
name_token.line, name_token.column);
617
LocationRecorder location(group_location,
618
DescriptorProto::kNameFieldNumber);
619
location.StartAt(name_token);
620
location.EndAt(name_token);
621
location.RecordLegacyLocation(
622
group, DescriptorPool::ErrorCollector::NAME);
625
// The field's type_name also comes from the name. Confusing!
627
LocationRecorder location(field_location,
628
FieldDescriptorProto::kTypeNameFieldNumber);
629
location.StartAt(name_token);
630
location.EndAt(name_token);
482
633
// As a hack for backwards-compatibility, we force the group name to start
483
634
// with a capital letter and lower-case the field name. New code should
637
bool Parser::ParseOptionNamePart(UninterpretedOption* uninterpreted_option) {
800
bool Parser::ParseOptionNamePart(UninterpretedOption* uninterpreted_option,
801
const LocationRecorder& part_location) {
638
802
UninterpretedOption::NamePart* name = uninterpreted_option->add_name();
639
803
string identifier; // We parse identifiers into this string.
640
804
if (LookingAt("(")) { // This is an extension.
641
805
DO(Consume("("));
642
// An extension name consists of dot-separated identifiers, and may begin
644
if (LookingAtType(io::Tokenizer::TYPE_IDENTIFIER)) {
645
DO(ConsumeIdentifier(&identifier, "Expected identifier."));
646
name->mutable_name_part()->append(identifier);
648
while (LookingAt(".")) {
650
name->mutable_name_part()->append(".");
651
DO(ConsumeIdentifier(&identifier, "Expected identifier."));
652
name->mutable_name_part()->append(identifier);
808
LocationRecorder location(
809
part_location, UninterpretedOption::NamePart::kNamePartFieldNumber);
810
// An extension name consists of dot-separated identifiers, and may begin
812
if (LookingAtType(io::Tokenizer::TYPE_IDENTIFIER)) {
813
DO(ConsumeIdentifier(&identifier, "Expected identifier."));
814
name->mutable_name_part()->append(identifier);
816
while (LookingAt(".")) {
818
name->mutable_name_part()->append(".");
819
DO(ConsumeIdentifier(&identifier, "Expected identifier."));
820
name->mutable_name_part()->append(identifier);
654
824
DO(Consume(")"));
655
825
name->set_is_extension(true);
656
826
} else { // This is a regular field.
827
LocationRecorder location(
828
part_location, UninterpretedOption::NamePart::kNamePartFieldNumber);
657
829
DO(ConsumeIdentifier(&identifier, "Expected identifier."));
658
830
name->mutable_name_part()->append(identifier);
659
831
name->set_is_extension(false);
836
bool Parser::ParseUninterpretedBlock(string* value) {
837
// Note that enclosing braces are not added to *value.
841
if (LookingAt("{")) {
843
} else if (LookingAt("}")) {
845
if (brace_depth == 0) {
850
// TODO(sanjay): Interpret line/column numbers to preserve formatting
851
if (!value->empty()) value->push_back(' ');
852
value->append(input_->current().text);
855
AddError("Unexpected end of stream while parsing aggregate value.");
664
859
// We don't interpret the option here. Instead we store it in an
665
860
// UninterpretedOption, to be interpreted later.
666
bool Parser::ParseOptionAssignment(Message* options) {
861
bool Parser::ParseOptionAssignment(Message* options,
862
const LocationRecorder& options_location) {
667
863
// Create an entry in the uninterpreted_option field.
668
864
const FieldDescriptor* uninterpreted_option_field = options->GetDescriptor()->
669
865
FindFieldByName("uninterpreted_option");
670
866
GOOGLE_CHECK(uninterpreted_option_field != NULL)
671
867
<< "No field named \"uninterpreted_option\" in the Options proto.";
869
const Reflection* reflection = options->GetReflection();
871
LocationRecorder location(
872
options_location, uninterpreted_option_field->number(),
873
reflection->FieldSize(*options, uninterpreted_option_field));
673
875
UninterpretedOption* uninterpreted_option = down_cast<UninterpretedOption*>(
674
876
options->GetReflection()->AddMessage(options,
675
877
uninterpreted_option_field));
677
879
// Parse dot-separated name.
678
RecordLocation(uninterpreted_option,
679
DescriptorPool::ErrorCollector::OPTION_NAME);
681
DO(ParseOptionNamePart(uninterpreted_option));
683
while (LookingAt(".")) {
685
DO(ParseOptionNamePart(uninterpreted_option));
881
LocationRecorder name_location(location,
882
UninterpretedOption::kNameFieldNumber);
883
name_location.RecordLegacyLocation(
884
uninterpreted_option, DescriptorPool::ErrorCollector::OPTION_NAME);
887
LocationRecorder part_location(name_location,
888
uninterpreted_option->name_size());
889
DO(ParseOptionNamePart(uninterpreted_option, part_location));
892
while (LookingAt(".")) {
894
LocationRecorder part_location(name_location,
895
uninterpreted_option->name_size());
896
DO(ParseOptionNamePart(uninterpreted_option, part_location));
688
900
DO(Consume("="));
690
RecordLocation(uninterpreted_option,
691
DescriptorPool::ErrorCollector::OPTION_VALUE);
902
LocationRecorder value_location(location);
903
value_location.RecordLegacyLocation(
904
uninterpreted_option, DescriptorPool::ErrorCollector::OPTION_VALUE);
693
906
// All values are a single token, except for negative numbers, which consist
694
907
// of a single '-' symbol, followed by a positive number.
748
968
case io::Tokenizer::TYPE_SYMBOL:
749
AddError("Expected option value.");
969
if (LookingAt("{")) {
970
value_location.AddPath(UninterpretedOption::kAggregateValueFieldNumber);
971
DO(ParseUninterpretedBlock(
972
uninterpreted_option->mutable_aggregate_value()));
974
AddError("Expected option value.");
756
bool Parser::ParseExtensions(DescriptorProto* message) {
983
bool Parser::ParseExtensions(DescriptorProto* message,
984
const LocationRecorder& extensions_location) {
757
985
// Parse the declaration.
758
986
DO(Consume("extensions"));
989
// Note that kExtensionRangeFieldNumber was already pushed by the parent.
990
LocationRecorder location(extensions_location,
991
message->extension_range_size());
761
993
DescriptorProto::ExtensionRange* range = message->add_extension_range();
762
RecordLocation(range, DescriptorPool::ErrorCollector::NUMBER);
994
location.RecordLegacyLocation(
995
range, DescriptorPool::ErrorCollector::NUMBER);
765
DO(ConsumeInteger(&start, "Expected field number range."));
998
io::Tokenizer::Token start_token;
1001
LocationRecorder start_location(
1002
location, DescriptorProto::ExtensionRange::kStartFieldNumber);
1003
start_token = input_->current();
1004
DO(ConsumeInteger(&start, "Expected field number range."));
767
1007
if (TryConsume("to")) {
1008
LocationRecorder end_location(
1009
location, DescriptorProto::ExtensionRange::kEndFieldNumber);
768
1010
if (TryConsume("max")) {
769
1011
end = FieldDescriptor::kMaxNumber;
771
1013
DO(ConsumeInteger(&end, "Expected integer."));
1016
LocationRecorder end_location(
1017
location, DescriptorProto::ExtensionRange::kEndFieldNumber);
1018
end_location.StartAt(start_token);
1019
end_location.EndAt(start_token);
861
bool Parser::ParseEnumStatement(EnumDescriptorProto* enum_type) {
1130
bool Parser::ParseEnumStatement(EnumDescriptorProto* enum_type,
1131
const LocationRecorder& enum_location) {
862
1132
if (TryConsume(";")) {
863
1133
// empty statement; ignore
865
1135
} else if (LookingAt("option")) {
866
return ParseOption(enum_type->mutable_options());
1136
LocationRecorder location(enum_location,
1137
EnumDescriptorProto::kOptionsFieldNumber);
1138
return ParseOption(enum_type->mutable_options(), location);
868
return ParseEnumConstant(enum_type->add_value());
1140
LocationRecorder location(enum_location,
1141
EnumDescriptorProto::kValueFieldNumber, enum_type->value_size());
1142
return ParseEnumConstant(enum_type->add_value(), location);
872
bool Parser::ParseEnumConstant(EnumValueDescriptorProto* enum_value) {
873
RecordLocation(enum_value, DescriptorPool::ErrorCollector::NAME);
874
DO(ConsumeIdentifier(enum_value->mutable_name(),
875
"Expected enum constant name."));
1146
bool Parser::ParseEnumConstant(EnumValueDescriptorProto* enum_value,
1147
const LocationRecorder& enum_value_location) {
1150
LocationRecorder location(enum_value_location,
1151
EnumValueDescriptorProto::kNameFieldNumber);
1152
location.RecordLegacyLocation(
1153
enum_value, DescriptorPool::ErrorCollector::NAME);
1154
DO(ConsumeIdentifier(enum_value->mutable_name(),
1155
"Expected enum constant name."));
876
1158
DO(Consume("=", "Missing numeric value for enum constant."));
878
bool is_negative = TryConsume("-");
880
DO(ConsumeInteger(&number, "Expected integer."));
881
if (is_negative) number *= -1;
882
enum_value->set_number(number);
884
DO(ParseEnumConstantOptions(enum_value));
1162
LocationRecorder location(
1163
enum_value_location, EnumValueDescriptorProto::kNumberFieldNumber);
1164
location.RecordLegacyLocation(
1165
enum_value, DescriptorPool::ErrorCollector::NUMBER);
1167
bool is_negative = TryConsume("-");
1169
DO(ConsumeInteger(&number, "Expected integer."));
1170
if (is_negative) number *= -1;
1171
enum_value->set_number(number);
1174
DO(ParseEnumConstantOptions(enum_value, enum_value_location));
886
1176
DO(Consume(";"));
891
bool Parser::ParseEnumConstantOptions(EnumValueDescriptorProto* value) {
892
if (!TryConsume("[")) return true;
1181
bool Parser::ParseEnumConstantOptions(
1182
EnumValueDescriptorProto* value,
1183
const LocationRecorder& enum_value_location) {
1184
if (!LookingAt("[")) return true;
1186
LocationRecorder location(
1187
enum_value_location, EnumValueDescriptorProto::kOptionsFieldNumber);
895
DO(ParseOptionAssignment(value->mutable_options()));
1192
DO(ParseOptionAssignment(value->mutable_options(), location));
896
1193
} while (TryConsume(","));
898
1195
DO(Consume("]"));
932
bool Parser::ParseServiceStatement(ServiceDescriptorProto* service) {
1238
bool Parser::ParseServiceStatement(ServiceDescriptorProto* service,
1239
const LocationRecorder& service_location) {
933
1240
if (TryConsume(";")) {
934
1241
// empty statement; ignore
936
1243
} else if (LookingAt("option")) {
937
return ParseOption(service->mutable_options());
1244
LocationRecorder location(
1245
service_location, ServiceDescriptorProto::kOptionsFieldNumber);
1246
return ParseOption(service->mutable_options(), location);
939
return ParseServiceMethod(service->add_method());
1248
LocationRecorder location(service_location,
1249
ServiceDescriptorProto::kMethodFieldNumber, service->method_size());
1250
return ParseServiceMethod(service->add_method(), location);
943
bool Parser::ParseServiceMethod(MethodDescriptorProto* method) {
1254
bool Parser::ParseServiceMethod(MethodDescriptorProto* method,
1255
const LocationRecorder& method_location) {
944
1256
DO(Consume("rpc"));
945
RecordLocation(method, DescriptorPool::ErrorCollector::NAME);
946
DO(ConsumeIdentifier(method->mutable_name(), "Expected method name."));
1259
LocationRecorder location(method_location,
1260
MethodDescriptorProto::kNameFieldNumber);
1261
location.RecordLegacyLocation(
1262
method, DescriptorPool::ErrorCollector::NAME);
1263
DO(ConsumeIdentifier(method->mutable_name(), "Expected method name."));
948
1266
// Parse input type.
949
1267
DO(Consume("("));
950
RecordLocation(method, DescriptorPool::ErrorCollector::INPUT_TYPE);
951
DO(ParseUserDefinedType(method->mutable_input_type()));
1269
LocationRecorder location(method_location,
1270
MethodDescriptorProto::kInputTypeFieldNumber);
1271
location.RecordLegacyLocation(
1272
method, DescriptorPool::ErrorCollector::INPUT_TYPE);
1273
DO(ParseUserDefinedType(method->mutable_input_type()));
952
1275
DO(Consume(")"));
954
1277
// Parse output type.
955
1278
DO(Consume("returns"));
956
1279
DO(Consume("("));
957
RecordLocation(method, DescriptorPool::ErrorCollector::OUTPUT_TYPE);
958
DO(ParseUserDefinedType(method->mutable_output_type()));
1281
LocationRecorder location(method_location,
1282
MethodDescriptorProto::kOutputTypeFieldNumber);
1283
location.RecordLegacyLocation(
1284
method, DescriptorPool::ErrorCollector::OUTPUT_TYPE);
1285
DO(ParseUserDefinedType(method->mutable_output_type()));
959
1287
DO(Consume(")"));
961
1289
if (TryConsume("{")) {
1064
1395
DO(Consume("package"));
1066
RecordLocation(file, DescriptorPool::ErrorCollector::NAME);
1398
LocationRecorder location(root_location,
1399
FileDescriptorProto::kPackageFieldNumber);
1400
location.RecordLegacyLocation(file, DescriptorPool::ErrorCollector::NAME);
1070
DO(ConsumeIdentifier(&identifier, "Expected identifier."));
1071
file->mutable_package()->append(identifier);
1072
if (!TryConsume(".")) break;
1073
file->mutable_package()->append(".");
1404
DO(ConsumeIdentifier(&identifier, "Expected identifier."));
1405
file->mutable_package()->append(identifier);
1406
if (!TryConsume(".")) break;
1407
file->mutable_package()->append(".");
1076
1411
DO(Consume(";"));
1080
bool Parser::ParseImport(string* import_filename) {
1415
bool Parser::ParseImport(string* import_filename,
1416
const LocationRecorder& root_location,
1081
1418
DO(Consume("import"));
1082
DO(ConsumeString(import_filename,
1083
"Expected a string naming the file to import."));
1420
LocationRecorder location(root_location,
1421
FileDescriptorProto::kDependencyFieldNumber,
1423
DO(ConsumeString(import_filename,
1424
"Expected a string naming the file to import."));
1084
1426
DO(Consume(";"));
1088
bool Parser::ParseOption(Message* options) {
1430
bool Parser::ParseOption(Message* options,
1431
const LocationRecorder& options_location) {
1089
1432
DO(Consume("option"));
1090
DO(ParseOptionAssignment(options));
1433
DO(ParseOptionAssignment(options, options_location));
1091
1434
DO(Consume(";"));