1 4 package jfun.parsec; 5 6 final class IfElseParser<R, C> extends Parser<R> { 7 private final Parser<? extends R> no; 8 9 private final Parser<C> p; 10 11 private final ToParser<? super C, R> yes; 12 13 IfElseParser(String n, Parser<? extends R> no, Parser<C> p, ToParser<? super C, R> yes) { 14 super(n); 15 this.no = no; 16 this.p = p; 17 this.yes = yes; 18 } 19 20 boolean apply(final ParseContext ctxt, final int look_ahead) { 21 final Object ustate = ctxt.getUserState(); 22 final Object ret = ctxt.getReturn(); 23 final int step = ctxt.getStep(); 24 final int at = ctxt.getAt(); 25 final AbstractParsecError error = ctxt.getError(); 26 if (p.parse(ctxt)) 27 return yes.toParser(p.getReturn(ctxt)).parse(ctxt); 28 return ParserInternals.recover(look_ahead, no, ctxt, step, at, ret, ustate, error); 29 } 30 31 boolean apply(final ParseContext ctxt) { 32 return apply(ctxt, 1); 33 } 34 } | Popular Tags |