1 #ifndef INC_TokenStreamSelector_hpp__
2 #define INC_TokenStreamSelector_hpp__
4 /* ANTLR Translator Generator
5 * Project led by Terence Parr at http://www.jGuru.com
6 * Software rights: http://www.antlr.org/license.html
8 * $Id: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/antlr/TokenStreamSelector.hpp#2 $
11 #include <antlr/config.hpp>
12 #include <antlr/TokenStream.hpp>
16 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
20 /** A token stream MUX (multiplexor) knows about n token streams
21 * and can multiplex them onto the same channel for use by token
22 * stream consumer like a parser. This is a way to have multiple
23 * lexers break up the same input stream for a single parser.
24 * Or, you can have multiple instances of the same lexer handle
25 * multiple input streams; this works great for includes.
27 class ANTLR_API TokenStreamSelector : public TokenStream {
29 /** The set of inputs to the MUX */
30 #ifdef OS_NO_ALLOCATOR
31 typedef ANTLR_USE_NAMESPACE(std)less<ANTLR_USE_NAMESPACE(std)string> lessp;
32 typedef ANTLR_USE_NAMESPACE(std)map<ANTLR_USE_NAMESPACE(std)string,TokenStream*,lessp> inputStreamNames_coll;
34 typedef ANTLR_USE_NAMESPACE(std)map<ANTLR_USE_NAMESPACE(std)string,TokenStream*> inputStreamNames_coll;
36 inputStreamNames_coll inputStreamNames;
38 /** The currently-selected token stream input */
41 /** Used to track stack of input streams */
42 #ifdef OS_NO_ALLOCATOR
43 typedef ANTLR_USE_NAMESPACE(std)stack<TokenStream*, ANTLR_USE_NAMESPACE(std)deque<TokenStream*> > streamStack_coll;
45 typedef ANTLR_USE_NAMESPACE(std)stack<TokenStream*> streamStack_coll;
47 streamStack_coll streamStack;
50 TokenStreamSelector();
51 ~TokenStreamSelector();
53 void addInputStream(TokenStream* stream, const ANTLR_USE_NAMESPACE(std)string& key);
55 /// Return the stream from which tokens are being pulled at the moment.
56 TokenStream* getCurrentStream() const;
58 TokenStream* getStream(const ANTLR_USE_NAMESPACE(std)string& sname) const;
64 void push(TokenStream* stream);
66 void push(const ANTLR_USE_NAMESPACE(std)string& sname);
68 /** Abort recognition of current Token and try again.
69 * A stream can push a new stream (for include files
70 * for example, and then retry(), which will cause
71 * the current stream to abort back to this.nextToken().
72 * this.nextToken() then asks for a token from the
73 * current stream, which is the new "substream."
77 /** Set the stream without pushing old stream */
78 void select(TokenStream* stream);
80 void select(const ANTLR_USE_NAMESPACE(std)string& sname);
83 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
87 #endif //INC_TokenStreamSelector_hpp__