public class TokenStreamCopyingHiddenTokenFilter
This class provides TokenStreamHiddenTokenFilters with the concept of
tokens which can be copied so that they are seen by both the hidden token
stream as well as the parser itself. This is useful when one wants to use
an existing parser (like the Java parser included with ANTLR) that throws
away some tokens to create a parse tree which can be used to spit out
a copy of the code with only minor modifications.
This code is partially derived from the public domain ANLTR TokenStream
public TokenStreamCopyingHiddenTokenFilter(TokenStream input)
public void copy(int tokenType)
Indicate that all tokens of type tokenType should be copied. The copy
is put in the stream of hidden tokens, and the original is returned in the
stream of normal tokens.
tokenType - integer representing the token type to copied
public CommonHiddenStreamToken partialCloneToken(CommonHiddenStreamToken t)
Create a clone of the important parts of the given token. Note that this
does NOT copy the hiddenBefore and hiddenAfter fields.
t - token to partially clone
newly created partial clone
public void linkAndCopyToken(CommonHiddenStreamToken prev,
public Token nextToken()
Return the next monitored token.
Test the token following the monitored token.
If following is another monitored token, save it
for the next invocation of nextToken (like a single
lookahead token) and return it then.
If following is unmonitored, nondiscarded (hidden)
channel token, add it to the monitored token.
Note: EOF must be a monitored Token.