@Override public Node parse(ParseSession session, ParseContext ctx, boolean complete) { // Parse test final Node test = LogicalOrParser.INSTANCE.parse(session, ctx, complete); // Parse '?' this.spaceParser.parse(ctx, complete); if (!ctx.tryLiteral("?")) return test; // Parse true result this.spaceParser.parse(ctx, complete); final Node ifTrue = LogicalOrParser.INSTANCE.parse(session, ctx, complete); // Parse ':' this.spaceParser.parse(ctx, complete); if (!ctx.tryLiteral(":")) throw new ParseException(ctx).addCompletion(": "); // Parse false result this.spaceParser.parse(ctx, complete); final Node ifFalse = LogicalOrParser.INSTANCE.parse(session, ctx, complete); // Return node return new Node() { @Override public Value evaluate(ParseSession session) { return test.evaluate(session).checkBoolean(session, "conditional") ? ifTrue.evaluate(session) : ifFalse.evaluate(session); } }; }
@Override public T fromParseableString(ParseContext context) { context.expect('['); final Object[] values = new Object[this.size]; for (int i = 0; i < this.size; i++) { if (i > 0) context.expect(','); values[i] = this.fieldTypes.get(i).fromParseableString(context); } context.expect(']'); return this.createTuple(values); }