@Override public T parse(ParserState input) throws ParseException { ExpectationResult result = Parsers.expect(type).parse(input); if (Parsers.nullOrUnexpected(result)) { return null; } ConjureMetrics.incrementCounter(metric); return instance; }
@Override public ListType parse(ParserState input) throws ParseException { ExpectationResult result = Parsers.expect("list").parse(input); if (Parsers.nullOrUnexpected(result)) { return null; } ConjureType itemType = Parsers.liberalBetween("<", TypeParser.INSTANCE, ">").parse(input); ConjureMetrics.incrementCounter(ListType.class); return ListType.of(itemType); } }
@Override public SetType parse(ParserState input) throws ParseException { ExpectationResult result = Parsers.expect("set").parse(input); if (Parsers.nullOrUnexpected(result)) { return null; } ConjureType itemType = Parsers.liberalBetween("<", TypeParser.INSTANCE, ">").parse(input); ConjureMetrics.incrementCounter(SetType.class); return SetType.of(itemType); } }
@Override public OptionalType parse(ParserState input) throws ParseException { ExpectationResult result = Parsers.expect("optional").parse(input); if (Parsers.nullOrUnexpected(result)) { return null; } ConjureType itemType = Parsers.liberalBetween("<", TypeParser.INSTANCE, ">").parse(input); ConjureMetrics.incrementCounter(OptionalType.class); return OptionalType.of(itemType); } }
@Override public MapType parse(ParserState input) throws ParseException { ExpectationResult result = Parsers.expect("map").parse(input); if (Parsers.nullOrUnexpected(result)) { return null; } Parser<KeyValue<ConjureType, ConjureType>> kv = Parsers.liberalBetween( "<", new KeyValueParser<>( Parsers.whitespace(TypeParser.INSTANCE), Parsers.whitespace(Parsers.expect(",")), Parsers.whitespace(TypeParser.INSTANCE)), ">"); KeyValue<ConjureType, ConjureType> types = kv.parse(input); ConjureMetrics.incrementCounter(MapType.class); return MapType.of(types.getKey(), types.getValue()); } }
@Override public ForeignReferenceType parse(ParserState input) throws ParseException { String namespace = NAMESPACE_PARSER.parse(input); if (Parsers.nullOrUnexpected(Parsers.expect(".").parse(input))) { return null; } String ref = TypeReferenceParser.REF_PARSER.parse(input); ConjureMetrics.incrementCounter(ForeignReferenceType.class); return ForeignReferenceType.of(Namespace.of(namespace), TypeName.of(ref)); } }