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); } }
} else if (label.equals("import")) { if (!context.permitsImport()) throw reader.unexpected(location, "'import' in " + context); String importString = reader.readString(); if ("public".equals(importString)) { publicImports.add(reader.readString()); } else { imports.add(importString);
/** Reads a value that can be a map, list, string, number, boolean or enum. */ private KindAndValue readKindAndValue() { char peeked = reader.peekChar(); switch (peeked) { case '{': return KindAndValue.of(MAP, readMap('{', '}', ':')); case '[': return KindAndValue.of(LIST, readList()); case '"': case '\'': return KindAndValue.of(STRING, reader.readString()); default: if (Character.isDigit(peeked) || peeked == '-') { return KindAndValue.of(NUMBER, reader.readWord()); } String word = reader.readWord(); switch (word) { case "true": return KindAndValue.of(BOOLEAN, "true"); case "false": return KindAndValue.of(BOOLEAN, "false"); default: return KindAndValue.of(ENUM, word); } } }
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); } }
} else if (label.equals("import")) { if (!context.permitsImport()) throw reader.unexpected(location, "'import' in " + context); String importString = reader.readString(); if ("public".equals(importString)) { publicImports.add(reader.readString()); } else { imports.add(importString);
/** Reads a value that can be a map, list, string, number, boolean or enum. */ private OptionKindAndValue readKindAndValue() { char peeked = reader.peekChar(); switch (peeked) { case '{': return OptionKindAndValue.of(OptionElement.Kind.MAP, readMap('{', '}', ':')); case '[': return OptionKindAndValue.of(OptionElement.Kind.LIST, readList()); case '"': case '\'': return OptionKindAndValue.of(OptionElement.Kind.STRING, reader.readString()); default: if (Character.isDigit(peeked) || peeked == '-') { return OptionKindAndValue.of(OptionElement.Kind.NUMBER, reader.readWord()); } String word = reader.readWord(); switch (word) { case "true": return OptionKindAndValue.of(OptionElement.Kind.BOOLEAN, "true"); case "false": return OptionKindAndValue.of(OptionElement.Kind.BOOLEAN, "false"); default: return OptionKindAndValue.of(OptionElement.Kind.ENUM, word); } } }