1 8 14 package jfun.parsec; 15 16 27 abstract class AbstractParsecError implements java.io.Serializable { 28 final Object getException(){return exception;} 29 final boolean hasException(){return exception!=null;} 30 abstract ParsecError render(); 31 abstract AbstractParsecError setExpecting(String s); 32 final int getPrecedence(){return precedence;} 33 public final int getIndex(){return at;} 34 final boolean noMerge(){return nomerge;} 35 private final boolean nomerge; 36 private final int at; 37 private final int precedence; 38 private final Object exception; 39 AbstractParsecError(final boolean nomerge, final int at, 40 final int pred, final Object exception) { 41 this.nomerge = nomerge; 42 this.at = at; 43 this.precedence = pred; 44 this.exception = exception; 45 } 46 static AbstractParsecError mergeError(final AbstractParsecError e1, 47 final AbstractParsecError e2){ 48 if(e1==null) return e2; 49 if(e2==null) return e1; 50 if(e1==e2) return e1; 51 final int pred = e1.precedence; 52 final int pred2 = e2.precedence; 53 final int at = e1.at; 54 final int at2 = e2.at; 55 if(at==at2){ 56 if(pred2>pred){ 57 return e2; 58 } 59 else if(pred>pred2){ 60 return e1; 61 } 62 } 64 else if(at > at2){ 65 return e1; 69 } 70 else if(at < at2){ 71 return e2; 75 } 76 if(e1.nomerge && e2.nomerge){ 77 return e1; 78 } 79 return new MergedParsecError(at, pred, e1, e2); 80 } 81 } 82 | Popular Tags |