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