KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > antlr > TokenStreamBasicFilter


1 package antlr;
2
3 /* ANTLR Translator Generator
4  * Project led by Terence Parr at http://www.jGuru.com
5  * Software rights: http://www.antlr.org/RIGHTS.html
6  *
7  * $Id: //depot/code/org.antlr/main/main/antlr/TokenStreamBasicFilter.java#4 $
8  */

9
10 import antlr.collections.impl.BitSet;
11
12 /** This object is a TokenStream that passes through all
13  * tokens except for those that you tell it to discard.
14  * There is no buffering of the tokens.
15  */

16 public class TokenStreamBasicFilter implements TokenStream {
17     /** The set of token types to discard */
18     protected BitSet discardMask;
19
20     /** The input stream */
21     protected TokenStream input;
22
23     public TokenStreamBasicFilter(TokenStream input) {
24         this.input = input;
25         discardMask = new BitSet();
26     }
27
28     public void discard(int ttype) {
29         discardMask.add(ttype);
30     }
31
32     public void discard(BitSet mask) {
33         discardMask = mask;
34     }
35
36     public Token nextToken() throws TokenStreamException {
37         Token tok = input.nextToken();
38         while (tok != null && discardMask.member(tok.getType())) {
39             tok = input.nextToken();
40         }
41         return tok;
42     }
43 }
44
Popular Tags