KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > ParseContext


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 Dec 16, 2004
10  *
11  * Author Ben Yu
12  */

13 package jfun.parsec;
14
15
16 /**
17  * @author Ben Yu
18  *
19  * Dec 16, 2004
20  */

21 abstract class ParseContext {
22   String JavaDoc getModuleName(){return module;}
23   abstract boolean isEof();
24   abstract int getIndex();
25   abstract Tok getToken();
26   abstract char peekChar();
27   abstract CharSequence JavaDoc getSource();
28   abstract ParsecError getSysUnexpected();
29   protected int at;
30   private int step;
31   private Object JavaDoc userState;
32   private AbstractParsecError err;
33   private Object JavaDoc ret;
34   private final String JavaDoc module;
35   private final PositionMap pmap;
36   final PositionMap getPositionMap(){
37     return pmap;
38   }
39   final void set(final int step, final int at, final Object JavaDoc ret, final Object JavaDoc userState, final AbstractParsecError err){
40     this.step = step;
41     this.at = at;
42     this.ret = ret;
43     this.userState = userState;
44     this.err = err;
45   }
46   /**
47    * @return Returns the err.
48    */

49   final AbstractParsecError getError() {
50     return err;
51   }
52   /**
53    * @param err The err to set.
54    */

55   final void setError(AbstractParsecError err) {
56     this.err = err;
57   }
58   /**
59    * @return Returns the ret.
60    */

61   final Object JavaDoc getReturn() {
62     return ret;
63   }
64   /**
65    * @param ret The ret to set.
66    */

67   final void setReturn(Object JavaDoc ret) {
68     this.ret = ret;
69   }
70   final boolean hasException(){
71     return err!=null && err.hasException();
72   }
73   //private final Message[] msgs;
74
final Object JavaDoc getUserState(){return userState;}
75
76   
77   final int getStep(){return step;}
78   final int getAt(){return at;}
79   final void setAt(int step, int a){
80     this.step = step;
81     this.at = a;
82   }
83   final void setStep(int s){
84     this.step = s;
85   }
86   final void next(){
87     at ++;
88     step ++;
89   }
90   final void next(int n){
91     at += n;
92     if(n>0) step++;
93   }
94   final void setUserState(final Object JavaDoc obj){
95     userState = obj;
96   }
97   //caller should not change input after it is passed in.
98
ParseContext(final Object JavaDoc us, final int at, final String JavaDoc module, final PositionMap pmap){
99     this.userState = us;
100     this.step = 0;
101     this.at = at;
102     this.module = module;
103     this.pmap = pmap;
104   }
105   ParseContext(final Object JavaDoc ret, final Object JavaDoc us,
106       final int at, final String JavaDoc module, final PositionMap pmap){
107     this.ret = ret;
108     this.userState = us;
109     this.step = 0;
110     this.at = at;
111     this.module = module;
112     this.pmap = pmap;
113   }
114   final void prependError(final AbstractParsecError err){
115     this.err = AbstractParsecError.mergeError(err, this.err);
116   }
117   final void appendError(final AbstractParsecError err){
118     this.err = AbstractParsecError.mergeError(this.err, err);
119   }
120 }
121
Popular Tags