@Override public ResolvingAction flatten(Map<Sequence, Sequence> map, Map<Sequence, List<Fixup>> map2) { return new ResolvingAction(writer.flatten(map, map2), reader.flatten(map, map2)); }
@Override public UnionAdjustAction flatten(Map<Sequence, Sequence> map, Map<Sequence, List<Fixup>> map2) { return new UnionAdjustAction(rindex, symToParse.flatten(map, map2)); }
@Override public Alternative flatten(Map<Sequence, Sequence> map, Map<Sequence, List<Fixup>> map2) { Symbol[] ss = new Symbol[symbols.length]; for (int i = 0; i < ss.length; i++) { ss[i] = symbols[i].flatten(map, map2); } return new Alternative(ss, labels); } }
@Override public void writeIndex(int unionIndex) throws IOException { parser.advance(Symbol.UNION); Symbol.Alternative top = (Symbol.Alternative) parser.popSymbol(); Symbol symbol = top.getSymbol(unionIndex); if (symbol != Symbol.NULL) { out.writeStartObject(); out.writeFieldName(top.getLabel(unionIndex)); parser.pushSymbol(Symbol.UNION_END); } parser.pushSymbol(symbol); }
JsonEncoder(Schema sc, JsonGenerator out) throws IOException { configure(out); this.parser = new Parser(new JsonGrammarGenerator().generate(sc), this); }
@Override public int readIndex() throws IOException { parser.advance(Symbol.UNION); Symbol.UnionAdjustAction top = (Symbol.UnionAdjustAction) parser.popSymbol(); parser.pushSymbol(top.symToParse); return top.rindex; }
/** * Resolves the writer schema <tt>writer</tt> and the reader schema * <tt>reader</tt> and returns the start symbol for the grammar generated. * @param writer The schema used by the writer * @param reader The schema used by the reader * @return The start symbol for the resolving grammar * @throws IOException */ public final Symbol generate(Schema writer, Schema reader) throws IOException { return Symbol.root(generate(writer, reader, new HashMap<>())); }
@Override public SkipAction flatten(Map<Sequence, Sequence> map, Map<Sequence, List<Fixup>> map2) { return new SkipAction(symToSkip.flatten(map, map2)); }
@Override protected void encode(Encoder e, Schema s, JsonNode n) throws IOException { ResolvingGrammarGenerator.encode(e, s, n); } });
/** * A convenience method to construct a sequence. * @param production The constituent symbols of the sequence. */ static Symbol seq(Symbol... production) { return new Sequence(production); }
private Repeater(Symbol end, Symbol... sequenceToRepeat) { super(Kind.REPEATER, makeProduction(sequenceToRepeat)); this.end = end; production[0] = this; }
/** * A convenience method to construct a repeater. * @param symsToRepeat The symbols to repeat in the repeater. */ static Symbol repeat(Symbol endSymbol, Symbol... symsToRepeat) { return new Repeater(endSymbol, symsToRepeat); }
/** * A convenience method to construct an ErrorAction. * @param e */ static Symbol error(String e) { return new ErrorAction(e); }
@Override public final int flattenedSize() { return flattenedSize(production, 0); } }
/** Re-initialize, reading from a new underlying Decoder. */ public ValidatingDecoder configure(Decoder in) throws IOException { this.parser.reset(); this.in = in; return this; }
/** * Pushes <tt>sym</tt> on to the stack. */ public void pushSymbol(Symbol sym) { if (pos == stack.length) { expandStack(); } stack[pos++] = sym; }
@Override public ResolvingAction flatten(Map<Sequence, Sequence> map, Map<Sequence, List<Fixup>> map2) { return new ResolvingAction(writer.flatten(map, map2), reader.flatten(map, map2)); }
@Override public UnionAdjustAction flatten(Map<Sequence, Sequence> map, Map<Sequence, List<Fixup>> map2) { return new UnionAdjustAction(rindex, symToParse.flatten(map, map2)); }
@Override public Alternative flatten(Map<Sequence, Sequence> map, Map<Sequence, List<Fixup>> map2) { Symbol[] ss = new Symbol[symbols.length]; for (int i = 0; i < ss.length; i++) { ss[i] = symbols[i].flatten(map, map2); } return new Alternative(ss, labels); } }
@Override public SkipAction flatten(Map<Sequence, Sequence> map, Map<Sequence, List<Fixup>> map2) { return new SkipAction(symToSkip.flatten(map, map2)); }