01: package persistence.antlr;
02:
03: /* ANTLR Translator Generator
04: * Project led by Terence Parr at http://www.jGuru.com
05: * Software rights: http://www.antlr.org/license.html
06: *
07: */
08:
09: import persistence.antlr.collections.impl.BitSet;
10:
11: /** This object is a TokenStream that passes through all
12: * tokens except for those that you tell it to discard.
13: * There is no buffering of the tokens.
14: */
15: public class TokenStreamBasicFilter implements TokenStream {
16: /** The set of token types to discard */
17: protected BitSet discardMask;
18:
19: /** The input stream */
20: protected TokenStream input;
21:
22: public TokenStreamBasicFilter(TokenStream input) {
23: this .input = input;
24: discardMask = new BitSet();
25: }
26:
27: public void discard(int ttype) {
28: discardMask.add(ttype);
29: }
30:
31: public void discard(BitSet mask) {
32: discardMask = mask;
33: }
34:
35: public Token nextToken() throws TokenStreamException {
36: Token tok = input.nextToken();
37: while (tok != null && discardMask.member(tok.getType())) {
38: tok = input.nextToken();
39: }
40: return tok;
41: }
42: }
|