Add maps syntax support Change-Id: I7a01d3f541e7601da62763fe6860a4f4c49444c5
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/MapSyntaxTest.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/MapSyntaxTest.java new file mode 100644 index 0000000..2bc0901 --- /dev/null +++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/MapSyntaxTest.java
@@ -0,0 +1,39 @@ +/* + * Copyright (c) 2014 Google Inc. + * + * All rights reserved. This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package com.google.eclipse.protobuf.bugs; + +import static com.google.eclipse.protobuf.junit.core.UnitTestModule.unitTestModule; +import static com.google.eclipse.protobuf.junit.core.XtextRule.overrideRuntimeModuleWith; +import static org.junit.Assert.assertTrue; + +import com.google.eclipse.protobuf.junit.core.XtextRule; +import com.google.eclipse.protobuf.validation.ProtobufJavaValidator; +import com.google.inject.Inject; + +import org.eclipse.emf.common.util.BasicDiagnostic; +import org.junit.Rule; +import org.junit.Test; + +/** + * Test that the parser correctly handles map syntax. + */ +public class MapSyntaxTest { + @Rule public XtextRule xtext = overrideRuntimeModuleWith(unitTestModule()); + + @Inject private ProtobufJavaValidator validator; + + // syntax = "proto2"; + // + // message Foo { + // optional map<string, Bar> bar_map = 1; + // } + @Test public void shouldAllowMapFields() { + boolean isValid = validator.validate(xtext.root(), new BasicDiagnostic(), null); + assertTrue(isValid); + } +}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext index dddd42f..0ce144f 100644 --- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext +++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
@@ -96,7 +96,7 @@ optional | required | repeated; TypeLink: - ScalarTypeLink | ComplexTypeLink; + ScalarTypeLink | ComplexTypeLink | MapTypeLink; ScalarTypeLink: target=ScalarType; @@ -107,6 +107,12 @@ ComplexTypeLink: target=[ComplexType|QualifiedName]; + +MapTypeLink: + target=MapType; + +MapType: + =>'map' '<' fromType=TypeLink ',' toType=TypeLink '>'; Enum: =>'enum' name=Name '{'