private void advancePastComma(String errMsg) throws IOException { skipWhitespace(); expectChar(',', errMsg); skipWhitespace(); }
private Schema parseArray() throws IOException { expectChar('<', "array must be followed by a '<'"); skipWhitespace(); Schema componentType = parseType(); skipWhitespace(); expectChar('>', "array must end with a '>'"); return Schema.arrayOf(componentType); }
private void advancePastComma(String errMsg) throws IOException { skipWhitespace(); expectChar(',', errMsg); skipWhitespace(); }
private Schema parseArray() throws IOException { expectChar('<', "array must be followed by a '<'"); skipWhitespace(); Schema componentType = parseType(); skipWhitespace(); expectChar('>', "array must end with a '>'"); return Schema.arrayOf(componentType); }
private Schema parseMap() throws IOException { expectChar('<', "map must be followed by a '<'"); skipWhitespace(); Schema keyType = parseType(); // key and value must be separated by a comma advancePastComma("Expected a comma separating map key and value types"); Schema valueType = parseType(); skipWhitespace(); expectChar('>', "map must end with a '>'"); return Schema.mapOf(keyType, valueType); }
private Schema parseMap() throws IOException { expectChar('<', "map must be followed by a '<'"); skipWhitespace(); Schema keyType = parseType(); // key and value must be separated by a comma advancePastComma("Expected a comma separating map key and value types"); Schema valueType = parseType(); skipWhitespace(); expectChar('>', "map must end with a '>'"); return Schema.mapOf(keyType, valueType); }
private Schema parseUnion() throws IOException { expectChar('<', "union must be followed by a '<'"); skipWhitespace(); List<Schema> unionTypes = new ArrayList<>(); // keep going until we see the closing '>' while (true) { unionTypes.add(parseType()); if (tryAdvancePastEndBracket()) { break; } advancePastComma("Expected a comma separating union types"); } return Schema.unionOf(unionTypes); }
private Schema parseUnion() throws IOException { expectChar('<', "union must be followed by a '<'"); skipWhitespace(); List<Schema> unionTypes = new ArrayList<>(); // keep going until we see the closing '>' while (true) { unionTypes.add(parseType()); if (tryAdvancePastEndBracket()) { break; } advancePastComma("Expected a comma separating union types"); } return Schema.unionOf(unionTypes); }
private Schema parseRecord() throws IOException { expectChar('<', "record must be followed with a '<'"); skipWhitespace(); String recordName = "rec" + recordNum; recordNum++; List<Schema.Field> fields = new ArrayList<>(); // keep going until we get to the enclosing '>' while (true) { // colName:type String colName = nextToken(); errorIf(schema.charAt(pos) != ':', "Expecting a ':' between field name and type"); pos++; errorIf(pos >= end, "Unexpected EOF"); fields.add(Schema.Field.of(colName, parseType())); // must be at the end or at a comma if (tryAdvancePastEndBracket()) { break; } advancePastComma("Expected a comma separating record fields"); } return Schema.recordOf(recordName, fields); }
private Schema parseRecord() throws IOException { expectChar('<', "record must be followed with a '<'"); skipWhitespace(); String recordName = "rec" + recordNum; recordNum++; List<Schema.Field> fields = new ArrayList<>(); // keep going until we get to the enclosing '>' while (true) { // colName:type String colName = nextToken(); errorIf(schema.charAt(pos) != ':', "Expecting a ':' between field name and type"); pos++; errorIf(pos >= end, "Unexpected EOF"); fields.add(Schema.Field.of(colName, parseType())); // must be at the end or at a comma if (tryAdvancePastEndBracket()) { break; } advancePastComma("Expected a comma separating record fields"); } return Schema.recordOf(recordName, fields); }