public RuntimeException unexpected(String message) { return unexpected(location(), message); }
private void readDeclaration(String documentation) { Location location = reader.location(); String label = reader.readWord(); if (label.equals("package")) { if (packageName != null) throw reader.unexpected(location, "too many package names"); packageName = reader.readName(); reader.require(';'); } else if (label.equals("import")) { String importString = reader.readString(); imports.add(importString); reader.require(';'); } else if (label.equals("type")) { typeConfigs.add(readTypeConfig(location, documentation)); } else { throw reader.unexpected(location, "unexpected label: " + label); } }
private OneOfElement readOneOf(String documentation) { OneOfElement.Builder builder = OneOfElement.builder() .name(reader.readName()) .documentation(documentation); ImmutableList.Builder<FieldElement> fields = ImmutableList.builder(); ImmutableList.Builder<GroupElement> groups = ImmutableList.builder(); reader.require('{'); while (true) { String nestedDocumentation = reader.readDocumentation(); if (reader.peekChar('}')) break; Location location = reader.location(); String type = reader.readDataType(); if (type.equals("group")) { groups.add(readGroup(location, nestedDocumentation, null)); } else { fields.add(readField(location, nestedDocumentation, null, type)); } } return builder.fields(fields.build()) .groups(groups.build()) .build(); }
private GroupElement readGroup(Location location, String documentation, Field.Label label) { String name = reader.readWord(); reader.require('='); int tag = reader.readInt(); GroupElement.Builder builder = GroupElement.builder(location) .label(label) .name(name) .tag(tag) .documentation(documentation); ImmutableList.Builder<FieldElement> fields = ImmutableList.builder(); reader.require('{'); while (true) { String nestedDocumentation = reader.readDocumentation(); if (reader.peekChar('}')) break; Location fieldLocation = reader.location(); String fieldLabel = reader.readWord(); Object field = readField(nestedDocumentation, fieldLocation, fieldLabel); if (!(field instanceof FieldElement)) { throw reader.unexpected("expected field declaration, was " + field); } fields.add((FieldElement) field); } return builder.fields(fields.build()) .build(); }
Location location = reader.location(); String label = reader.readWord();
Location wordLocation = reader.location(); String word = reader.readWord(); switch (word) {
public RuntimeException unexpected(String message) { return unexpected(location(), message); }
private void readDeclaration(String documentation) { Location location = reader.location(); String label = reader.readWord(); if ("package".equals(label)) { if (packageName != null) { throw reader.unexpected(location, "too many package names"); } packageName = reader.readName(); reader.require(';'); } else if ("import".equals(label)) { String importString = reader.readString(); imports.add(importString); reader.require(';'); } else if ("type".equals(label)) { typeConfigs.add(readTypeConfig(location, documentation)); } else { throw reader.unexpected(location, "unexpected label: " + label); } }
private OneOfElement readOneOf(String documentation) { OneOfElement.Builder builder = OneOfElement.builder() .name(reader.readName()) .documentation(documentation); ImmutableList.Builder<FieldElement> fields = ImmutableList.builder(); ImmutableList.Builder<GroupElement> groups = ImmutableList.builder(); reader.require('{'); while (true) { String nestedDocumentation = reader.readDocumentation(); if (reader.peekChar('}')) break; Location location = reader.location(); String type = reader.readDataType(); if (type.equals("group")) { groups.add(readGroup(nestedDocumentation, null)); } else { fields.add(readField(location, nestedDocumentation, null, type)); } } return builder.fields(fields.build()) .groups(groups.build()) .build(); }
private GroupElement readGroup(String documentation, Field.Label label) { String name = reader.readWord(); reader.require('='); int tag = reader.readInt(); GroupElement.Builder builder = GroupElement.builder() .label(label) .name(name) .tag(tag) .documentation(documentation); ImmutableList.Builder<FieldElement> fields = ImmutableList.builder(); reader.require('{'); while (true) { String nestedDocumentation = reader.readDocumentation(); if (reader.peekChar('}')) break; Location location = reader.location(); String fieldLabel = reader.readWord(); Object field = readField(nestedDocumentation, location, fieldLabel); if (!(field instanceof FieldElement)) { throw reader.unexpected("expected field declaration, was " + field); } fields.add((FieldElement) field); } return builder.fields(fields.build()) .build(); }
Location location = reader.location(); String label = reader.readWord();
Location wordLocation = reader.location(); String word = reader.readWord(); switch (word) {