1 |
tim |
2469 |
#ifndef INC_TokenStreamHiddenTokenFilter_hpp__ |
2 |
|
|
#define INC_TokenStreamHiddenTokenFilter_hpp__ |
3 |
|
|
|
4 |
|
|
/* ANTLR Translator Generator |
5 |
|
|
* Project led by Terence Parr at http://www.jGuru.com |
6 |
|
|
* Software rights: http://www.antlr.org/license.html |
7 |
|
|
* |
8 |
|
|
* $Id: TokenStreamHiddenTokenFilter.hpp,v 1.1 2005-12-02 15:38:02 tim Exp $ |
9 |
|
|
*/ |
10 |
|
|
|
11 |
|
|
#include <antlr/config.hpp> |
12 |
|
|
#include <antlr/TokenStreamBasicFilter.hpp> |
13 |
|
|
|
14 |
|
|
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE |
15 |
|
|
namespace antlr { |
16 |
|
|
#endif |
17 |
|
|
|
18 |
|
|
/**This object filters a token stream coming from a lexer |
19 |
|
|
* or another TokenStream so that only certain token channels |
20 |
|
|
* get transmitted to the parser. |
21 |
|
|
* |
22 |
|
|
* Any of the channels can be filtered off as "hidden" channels whose |
23 |
|
|
* tokens can be accessed from the parser. |
24 |
|
|
*/ |
25 |
|
|
class ANTLR_API TokenStreamHiddenTokenFilter : public TokenStreamBasicFilter { |
26 |
|
|
// protected BitSet discardMask; |
27 |
|
|
protected: |
28 |
|
|
BitSet hideMask; |
29 |
|
|
|
30 |
|
|
private: |
31 |
|
|
RefToken nextMonitoredToken; |
32 |
|
|
|
33 |
|
|
protected: |
34 |
|
|
/** track tail of hidden list emanating from previous |
35 |
|
|
* monitored token |
36 |
|
|
*/ |
37 |
|
|
RefToken lastHiddenToken; |
38 |
|
|
|
39 |
|
|
RefToken firstHidden; // = null; |
40 |
|
|
|
41 |
|
|
public: |
42 |
|
|
TokenStreamHiddenTokenFilter(TokenStream& input); |
43 |
|
|
|
44 |
|
|
protected: |
45 |
|
|
void consume(); |
46 |
|
|
|
47 |
|
|
private: |
48 |
|
|
void consumeFirst(); |
49 |
|
|
|
50 |
|
|
public: |
51 |
|
|
BitSet getDiscardMask() const; |
52 |
|
|
|
53 |
|
|
/** Return a ptr to the hidden token appearing immediately after |
54 |
|
|
* token t in the input stream. |
55 |
|
|
*/ |
56 |
|
|
RefToken getHiddenAfter(RefToken t); |
57 |
|
|
|
58 |
|
|
/** Return a ptr to the hidden token appearing immediately before |
59 |
|
|
* token t in the input stream. |
60 |
|
|
*/ |
61 |
|
|
RefToken getHiddenBefore(RefToken t); |
62 |
|
|
|
63 |
|
|
BitSet getHideMask() const; |
64 |
|
|
|
65 |
|
|
/** Return the first hidden token if one appears |
66 |
|
|
* before any monitored token. |
67 |
|
|
*/ |
68 |
|
|
RefToken getInitialHiddenToken(); |
69 |
|
|
|
70 |
|
|
void hide(int m); |
71 |
|
|
|
72 |
|
|
void hide(const BitSet& mask); |
73 |
|
|
|
74 |
|
|
protected: |
75 |
|
|
RefToken LA(int i); |
76 |
|
|
|
77 |
|
|
public: |
78 |
|
|
/** Return the next monitored token. |
79 |
|
|
* Test the token following the monitored token. |
80 |
|
|
* If following is another monitored token, save it |
81 |
|
|
* for the next invocation of nextToken (like a single |
82 |
|
|
* lookahead token) and return it then. |
83 |
|
|
* If following is unmonitored, nondiscarded (hidden) |
84 |
|
|
* channel token, add it to the monitored token. |
85 |
|
|
* |
86 |
|
|
* Note: EOF must be a monitored Token. |
87 |
|
|
*/ |
88 |
|
|
RefToken nextToken(); |
89 |
|
|
}; |
90 |
|
|
|
91 |
|
|
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE |
92 |
|
|
} |
93 |
|
|
#endif |
94 |
|
|
|
95 |
|
|
#endif //INC_TokenStreamHiddenTokenFilter_hpp__ |