1 8 13 package jfun.parsec; 14 15 16 21 abstract class ParseContext { 22 String getModuleName(){return module;} 23 abstract boolean isEof(); 24 abstract int getIndex(); 25 abstract Tok getToken(); 26 abstract char peekChar(); 27 abstract CharSequence getSource(); 28 abstract ParsecError getSysUnexpected(); 29 protected int at; 30 private int step; 31 private Object userState; 32 private AbstractParsecError err; 33 private Object ret; 34 private final String 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 ret, final Object 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 49 final AbstractParsecError getError() { 50 return err; 51 } 52 55 final void setError(AbstractParsecError err) { 56 this.err = err; 57 } 58 61 final Object getReturn() { 62 return ret; 63 } 64 67 final void setReturn(Object ret) { 68 this.ret = ret; 69 } 70 final boolean hasException(){ 71 return err!=null && err.hasException(); 72 } 73 final Object 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 obj){ 95 userState = obj; 96 } 97 ParseContext(final Object us, final int at, final String 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 ret, final Object us, 106 final int at, final String 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 |