1 8 13 package jfun.parsec; 14 15 16 21 final class ParserState extends ParseContext{ 22 23 private final Tok[] input; 24 private final ParsecError[] sys_unexpected; 25 private final int end_index; 28 private final ParsecError eof_unexpected; 29 30 31 private final ShowToken show; 32 33 boolean isEof(){ 34 return at >= input.length; } 36 int length(){return input.length;} 37 int getIndex(){ 38 if(at==input.length) return end_index; 39 return input[at].getIndex(); 40 } 41 42 43 Tok getToken(){ 44 return input[at]; 45 } 46 ParserState(final Object us, final Tok[] input, 48 final int at, final String module, final PositionMap pmap, 49 final int end_index, 50 final String eof_str, final ShowToken show){ 51 super(us, at, module, pmap); 52 this.input = input; 53 this.sys_unexpected = new ParsecError[input.length]; 54 this.show = show; 55 this.end_index = end_index; 56 this.eof_unexpected = ParsecError.raiseSysUnexpected( 57 end_index, eof_str); 58 } 59 ParserState(final Object r, final Object us, final Tok[] input, 60 final int at, final String module, final PositionMap pmap, 61 final int end_index, 62 final String eof_str, final ShowToken show){ 63 super(r, us, at, module, pmap); 64 this.input = input; 65 this.sys_unexpected = new ParsecError[input.length]; 66 this.show = show; 67 this.end_index = end_index; 68 this.eof_unexpected = ParsecError.raiseSysUnexpected( 69 end_index, eof_str); 70 } 71 72 ParsecError getSysUnexpected(){ 73 return getSysUnexpected(at); 74 } 75 private ParsecError getSysUnexpected(final int i){ 76 if(i>=sys_unexpected.length) return eof_unexpected; 77 ParsecError r = sys_unexpected[i]; 78 if(r == null){ 79 final Tok ptok = input[i]; 80 r = ParsecError.raiseSysUnexpected(ptok.getIndex(), 81 show.show(ptok.getToken())); 82 sys_unexpected[i] = r; 83 } 84 return r; 85 } 86 char peekChar(){ 87 throw new IllegalStateException ("parser not on char level."); 88 } 89 char peekChar(int i){ 90 throw new IllegalStateException ("parser not on char level."); 91 } 92 CharSequence getSource(){ 93 throw new IllegalStateException ("parser not on char level."); 94 } 95 } 96 | Popular Tags |