KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > MergedParsecError


1 /*****************************************************************************
2  * Copyright (C) Zephyr Business Solutions Corp. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  *****************************************************************************/

8 /*
9  * Created on Feb 24, 2005
10  *
11  * Author Ben Yu
12  * ZBS
13  */

14 package jfun.parsec;
15
16 /**
17  * To delay the merging of two AbstractParsecError.
18  * The merging is not done until render time.
19  * Zephyr Business Solutions Corp.
20  *
21  * @author Ben Yu
22  *
23  */

24 final class MergedParsecError extends AbstractParsecError {
25   ParsecError render() {
26     return getMerged(err1.render(), err2.render());
27   }
28   AbstractParsecError setExpecting(String JavaDoc s){
29     return ParsecError.raiseExpecting(getIndex(), s, this);
30   }
31   private ParsecError getMerged(ParsecError e1, ParsecError e2){
32     return ParsecError.mergeError(getIndex(), getException(), e1, e2);
33   }
34   private final AbstractParsecError err1;
35   private final AbstractParsecError err2;
36   MergedParsecError(int ind, int pred,
37       final AbstractParsecError err1, final AbstractParsecError err2) {
38     super(false, ind, pred, mergeObj(err1.getException(), err2.getException()));
39     this.err1 = err1;
40     this.err2 = err2;
41   }
42   static Object JavaDoc mergeObj(final Object JavaDoc a, final Object JavaDoc b){
43     return a==null?b:a;
44   }
45 }
46
Popular Tags