1*16467b97STreehugger Robot /** \file 2*16467b97STreehugger Robot * Defines the interface for an ANTLR3 common token stream. Custom token streams should create 3*16467b97STreehugger Robot * one of these and then override any functions by installing their own pointers 4*16467b97STreehugger Robot * to implement the various functions. 5*16467b97STreehugger Robot */ 6*16467b97STreehugger Robot #ifndef _ANTLR3_TOKENSTREAM_HPP 7*16467b97STreehugger Robot #define _ANTLR3_TOKENSTREAM_HPP 8*16467b97STreehugger Robot 9*16467b97STreehugger Robot // [The "BSD licence"] 10*16467b97STreehugger Robot // Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB 11*16467b97STreehugger Robot 12*16467b97STreehugger Robot // 13*16467b97STreehugger Robot // All rights reserved. 14*16467b97STreehugger Robot // 15*16467b97STreehugger Robot // Redistribution and use in source and binary forms, with or without 16*16467b97STreehugger Robot // modification, are permitted provided that the following conditions 17*16467b97STreehugger Robot // are met: 18*16467b97STreehugger Robot // 1. Redistributions of source code must retain the above copyright 19*16467b97STreehugger Robot // notice, this list of conditions and the following disclaimer. 20*16467b97STreehugger Robot // 2. Redistributions in binary form must reproduce the above copyright 21*16467b97STreehugger Robot // notice, this list of conditions and the following disclaimer in the 22*16467b97STreehugger Robot // documentation and/or other materials provided with the distribution. 23*16467b97STreehugger Robot // 3. The name of the author may not be used to endorse or promote products 24*16467b97STreehugger Robot // derived from this software without specific prior written permission. 25*16467b97STreehugger Robot // 26*16467b97STreehugger Robot // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 27*16467b97STreehugger Robot // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 28*16467b97STreehugger Robot // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 29*16467b97STreehugger Robot // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 30*16467b97STreehugger Robot // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 31*16467b97STreehugger Robot // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32*16467b97STreehugger Robot // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33*16467b97STreehugger Robot // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34*16467b97STreehugger Robot // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 35*16467b97STreehugger Robot // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36*16467b97STreehugger Robot 37*16467b97STreehugger Robot #include "antlr3defs.hpp" 38*16467b97STreehugger Robot 39*16467b97STreehugger Robot /** Definition of a token source, which has a pointer to a function that 40*16467b97STreehugger Robot * returns the next token (using a token factory if it is going to be 41*16467b97STreehugger Robot * efficient) and a pointer to an ANTLR3_INPUT_STREAM. This is slightly 42*16467b97STreehugger Robot * different to the Java interface because we have no way to implement 43*16467b97STreehugger Robot * multiple interfaces without defining them in the interface structure 44*16467b97STreehugger Robot * or casting (void *), which is too convoluted. 45*16467b97STreehugger Robot */ 46*16467b97STreehugger Robot ANTLR_BEGIN_NAMESPACE() 47*16467b97STreehugger Robot 48*16467b97STreehugger Robot //We are not making it subclass AllocPolicy, as this will always be a base class 49*16467b97STreehugger Robot template<class ImplTraits> 50*16467b97STreehugger Robot class TokenSource 51*16467b97STreehugger Robot { 52*16467b97STreehugger Robot public: 53*16467b97STreehugger Robot typedef typename ImplTraits::CommonTokenType TokenType; 54*16467b97STreehugger Robot typedef TokenType CommonTokenType; 55*16467b97STreehugger Robot typedef typename ImplTraits::StringType StringType; 56*16467b97STreehugger Robot typedef typename ImplTraits::LexerType LexerType; 57*16467b97STreehugger Robot 58*16467b97STreehugger Robot private: 59*16467b97STreehugger Robot /** A special pre-allocated token, which signifies End Of Tokens. Because this must 60*16467b97STreehugger Robot * be set up with the current input index and so on, we embed the structure and 61*16467b97STreehugger Robot * return the address of it. It is marked as factoryMade, so that it is never 62*16467b97STreehugger Robot * attempted to be freed. 63*16467b97STreehugger Robot */ 64*16467b97STreehugger Robot TokenType m_eofToken; 65*16467b97STreehugger Robot 66*16467b97STreehugger Robot /// A special pre-allocated token, which is returned by mTokens() if the 67*16467b97STreehugger Robot /// lexer rule said to just skip the generated token altogether. 68*16467b97STreehugger Robot /// Having this single token stops us wasting memory by have the token factory 69*16467b97STreehugger Robot /// actually create something that we are going to SKIP(); anyway. 70*16467b97STreehugger Robot /// 71*16467b97STreehugger Robot TokenType m_skipToken; 72*16467b97STreehugger Robot 73*16467b97STreehugger Robot /** When the token source is constructed, it is populated with the file 74*16467b97STreehugger Robot * name from whence the tokens were produced by the lexer. This pointer is a 75*16467b97STreehugger Robot * copy of the one supplied by the CharStream (and may be NULL) so should 76*16467b97STreehugger Robot * not be manipulated other than to copy or print it. 77*16467b97STreehugger Robot */ 78*16467b97STreehugger Robot StringType m_fileName; 79*16467b97STreehugger Robot 80*16467b97STreehugger Robot public: 81*16467b97STreehugger Robot TokenType& get_eofToken(); 82*16467b97STreehugger Robot const TokenType& get_eofToken() const; 83*16467b97STreehugger Robot TokenType& get_skipToken(); 84*16467b97STreehugger Robot StringType& get_fileName(); 85*16467b97STreehugger Robot LexerType* get_super(); 86*16467b97STreehugger Robot 87*16467b97STreehugger Robot void set_fileName( const StringType& fileName ); 88*16467b97STreehugger Robot 89*16467b97STreehugger Robot /** 90*16467b97STreehugger Robot * \brief 91*16467b97STreehugger Robot * Default implementation of the nextToken() call for a lexer. 92*16467b97STreehugger Robot * 93*16467b97STreehugger Robot * \param toksource 94*16467b97STreehugger Robot * Points to the implementation of a token source. The lexer is 95*16467b97STreehugger Robot * addressed by the super structure pointer. 96*16467b97STreehugger Robot * 97*16467b97STreehugger Robot * \returns 98*16467b97STreehugger Robot * The next token in the current input stream or the EOF token 99*16467b97STreehugger Robot * if there are no more tokens in any input stream in the stack. 100*16467b97STreehugger Robot * 101*16467b97STreehugger Robot * Write detailed description for nextToken here. 102*16467b97STreehugger Robot * 103*16467b97STreehugger Robot * \remarks 104*16467b97STreehugger Robot * Write remarks for nextToken here. 105*16467b97STreehugger Robot * 106*16467b97STreehugger Robot * \see nextTokenStr 107*16467b97STreehugger Robot */ 108*16467b97STreehugger Robot TokenType* nextToken(); 109*16467b97STreehugger Robot CommonTokenType* nextToken( BoolForwarder<true> /*isFiltered*/ ); 110*16467b97STreehugger Robot CommonTokenType* nextToken( BoolForwarder<false> /*isFiltered*/ ); 111*16467b97STreehugger Robot 112*16467b97STreehugger Robot /// 113*16467b97STreehugger Robot /// \brief 114*16467b97STreehugger Robot /// Returns the next available token from the current input stream. 115*16467b97STreehugger Robot /// 116*16467b97STreehugger Robot /// \param toksource 117*16467b97STreehugger Robot /// Points to the implementation of a token source. The lexer is 118*16467b97STreehugger Robot /// addressed by the super structure pointer. 119*16467b97STreehugger Robot /// 120*16467b97STreehugger Robot /// \returns 121*16467b97STreehugger Robot /// The next token in the current input stream or the EOF token 122*16467b97STreehugger Robot /// if there are no more tokens. 123*16467b97STreehugger Robot /// 124*16467b97STreehugger Robot /// \remarks 125*16467b97STreehugger Robot /// Write remarks for nextToken here. 126*16467b97STreehugger Robot /// 127*16467b97STreehugger Robot /// \see nextToken 128*16467b97STreehugger Robot /// 129*16467b97STreehugger Robot TokenType* nextTokenStr(); 130*16467b97STreehugger Robot 131*16467b97STreehugger Robot protected: 132*16467b97STreehugger Robot TokenSource(); 133*16467b97STreehugger Robot }; 134*16467b97STreehugger Robot 135*16467b97STreehugger Robot /** Definition of the ANTLR3 common token stream interface. 136*16467b97STreehugger Robot * \remark 137*16467b97STreehugger Robot * Much of the documentation for this interface is stolen from Ter's Java implementation. 138*16467b97STreehugger Robot */ 139*16467b97STreehugger Robot template<class ImplTraits> 140*16467b97STreehugger Robot class TokenStream : public ImplTraits::TokenIntStreamType 141*16467b97STreehugger Robot { 142*16467b97STreehugger Robot public: 143*16467b97STreehugger Robot typedef typename ImplTraits::TokenSourceType TokenSourceType; 144*16467b97STreehugger Robot typedef typename ImplTraits::TokenIntStreamType IntStreamType; 145*16467b97STreehugger Robot typedef typename ImplTraits::CommonTokenType TokenType; 146*16467b97STreehugger Robot typedef TokenType UnitType; 147*16467b97STreehugger Robot typedef typename ImplTraits::StringType StringType; 148*16467b97STreehugger Robot typedef typename ImplTraits::DebugEventListenerType DebugEventListenerType; 149*16467b97STreehugger Robot typedef typename ImplTraits::TokenStreamType TokenStreamType; 150*16467b97STreehugger Robot typedef typename ImplTraits::ParserType ComponentType; 151*16467b97STreehugger Robot 152*16467b97STreehugger Robot protected: 153*16467b97STreehugger Robot /** Pointer to the token source for this stream 154*16467b97STreehugger Robot */ 155*16467b97STreehugger Robot TokenSourceType* m_tokenSource; 156*16467b97STreehugger Robot 157*16467b97STreehugger Robot /// Debugger interface, is this is a debugging token stream 158*16467b97STreehugger Robot /// 159*16467b97STreehugger Robot DebugEventListenerType* m_debugger; 160*16467b97STreehugger Robot 161*16467b97STreehugger Robot /// Indicates the initial stream state for dbgConsume() 162*16467b97STreehugger Robot /// 163*16467b97STreehugger Robot bool m_initialStreamState; 164*16467b97STreehugger Robot 165*16467b97STreehugger Robot public: 166*16467b97STreehugger Robot TokenStream(TokenSourceType* source, DebugEventListenerType* debugger); 167*16467b97STreehugger Robot IntStreamType* get_istream(); 168*16467b97STreehugger Robot TokenSourceType* get_tokenSource() const; 169*16467b97STreehugger Robot void set_tokenSource( TokenSourceType* tokenSource ); 170*16467b97STreehugger Robot 171*16467b97STreehugger Robot /** Get Token at current input pointer + i ahead where i=1 is next Token. 172*16467b97STreehugger Robot * i<0 indicates tokens in the past. So -1 is previous token and -2 is 173*16467b97STreehugger Robot * two tokens ago. LT(0) is undefined. For i>=n, return Token.EOFToken. 174*16467b97STreehugger Robot * Return null for LT(0) and any index that results in an absolute address 175*16467b97STreehugger Robot * that is negative. 176*16467b97STreehugger Robot */ 177*16467b97STreehugger Robot const TokenType* _LT(ANTLR_INT32 k); 178*16467b97STreehugger Robot 179*16467b97STreehugger Robot /** Where is this stream pulling tokens from? This is not the name, but 180*16467b97STreehugger Robot * a pointer into an interface that contains a ANTLR3_TOKEN_SOURCE interface. 181*16467b97STreehugger Robot * The Token Source interface contains a pointer to the input stream and a pointer 182*16467b97STreehugger Robot * to a function that returns the next token. 183*16467b97STreehugger Robot */ 184*16467b97STreehugger Robot TokenSourceType* getTokenSource(); 185*16467b97STreehugger Robot 186*16467b97STreehugger Robot /** Function that installs a token source for teh stream 187*16467b97STreehugger Robot */ 188*16467b97STreehugger Robot void setTokenSource(TokenSourceType* tokenSource); 189*16467b97STreehugger Robot 190*16467b97STreehugger Robot /** Return the text of all the tokens in the stream, as the old tramp in 191*16467b97STreehugger Robot * Leeds market used to say; "Get the lot!" 192*16467b97STreehugger Robot */ 193*16467b97STreehugger Robot StringType toString(); 194*16467b97STreehugger Robot 195*16467b97STreehugger Robot /** Return the text of all tokens from start to stop, inclusive. 196*16467b97STreehugger Robot * If the stream does not buffer all the tokens then it can just 197*16467b97STreehugger Robot * return an empty ANTLR3_STRING or NULL; Grammars should not access $ruleLabel.text in 198*16467b97STreehugger Robot * an action in that case. 199*16467b97STreehugger Robot */ 200*16467b97STreehugger Robot StringType toStringSS(ANTLR_MARKER start, ANTLR_MARKER stop); 201*16467b97STreehugger Robot 202*16467b97STreehugger Robot /** Because the user is not required to use a token with an index stored 203*16467b97STreehugger Robot * in it, we must provide a means for two token objects themselves to 204*16467b97STreehugger Robot * indicate the start/end location. Most often this will just delegate 205*16467b97STreehugger Robot * to the other toString(int,int). This is also parallel with 206*16467b97STreehugger Robot * the pTREENODE_STREAM->toString(Object,Object). 207*16467b97STreehugger Robot */ 208*16467b97STreehugger Robot StringType toStringTT(const TokenType* start, const TokenType* stop); 209*16467b97STreehugger Robot 210*16467b97STreehugger Robot 211*16467b97STreehugger Robot /** Function that sets the token stream into debugging mode 212*16467b97STreehugger Robot */ 213*16467b97STreehugger Robot void setDebugListener(DebugEventListenerType* debugger); 214*16467b97STreehugger Robot 215*16467b97STreehugger Robot TokenStream(); 216*16467b97STreehugger Robot 217*16467b97STreehugger Robot }; 218*16467b97STreehugger Robot 219*16467b97STreehugger Robot /** Common token stream is an implementation of ANTLR_TOKEN_STREAM for the default 220*16467b97STreehugger Robot * parsers and recognizers. You may of course build your own implementation if 221*16467b97STreehugger Robot * you are so inclined. 222*16467b97STreehugger Robot */ 223*16467b97STreehugger Robot template<bool TOKENS_ACCESSED_FROM_OWNING_RULE, class ListType, class MapType> 224*16467b97STreehugger Robot class TokenStoreSelector 225*16467b97STreehugger Robot { 226*16467b97STreehugger Robot public: 227*16467b97STreehugger Robot typedef ListType TokensType; 228*16467b97STreehugger Robot }; 229*16467b97STreehugger Robot 230*16467b97STreehugger Robot template<class ListType, class MapType> 231*16467b97STreehugger Robot class TokenStoreSelector<true, ListType, MapType> 232*16467b97STreehugger Robot { 233*16467b97STreehugger Robot public: 234*16467b97STreehugger Robot typedef MapType TokensType; 235*16467b97STreehugger Robot }; 236*16467b97STreehugger Robot 237*16467b97STreehugger Robot template<class ImplTraits> 238*16467b97STreehugger Robot class CommonTokenStream : public TokenStream<ImplTraits> 239*16467b97STreehugger Robot { 240*16467b97STreehugger Robot public: 241*16467b97STreehugger Robot typedef typename ImplTraits::AllocPolicyType AllocPolicyType; 242*16467b97STreehugger Robot typedef typename ImplTraits::BitsetType BitsetType; 243*16467b97STreehugger Robot typedef typename ImplTraits::CommonTokenType TokenType; 244*16467b97STreehugger Robot typedef typename ImplTraits::TokenSourceType TokenSourceType; 245*16467b97STreehugger Robot typedef typename ImplTraits::DebugEventListenerType DebugEventListenerType; 246*16467b97STreehugger Robot typedef typename AllocPolicyType::template ListType<TokenType> TokensListType; 247*16467b97STreehugger Robot typedef typename AllocPolicyType::template OrderedMapType<ANTLR_MARKER, TokenType> TokensMapType; 248*16467b97STreehugger Robot typedef typename TokenStoreSelector< ImplTraits::TOKENS_ACCESSED_FROM_OWNING_RULE, 249*16467b97STreehugger Robot TokensListType, TokensMapType >::TokensType TokensType; 250*16467b97STreehugger Robot 251*16467b97STreehugger Robot typedef typename AllocPolicyType::template UnOrderedMapType<ANTLR_UINT32, ANTLR_UINT32> ChannelOverridesType; 252*16467b97STreehugger Robot typedef typename AllocPolicyType::template OrderedSetType<ANTLR_UINT32> DiscardSetType; 253*16467b97STreehugger Robot typedef typename AllocPolicyType::template ListType<ANTLR_UINT32> IntListType; 254*16467b97STreehugger Robot typedef TokenStream<ImplTraits> BaseType; 255*16467b97STreehugger Robot 256*16467b97STreehugger Robot private: 257*16467b97STreehugger Robot /** Records every single token pulled from the source indexed by the token index. 258*16467b97STreehugger Robot * There might be more efficient ways to do this, such as referencing directly in to 259*16467b97STreehugger Robot * the token factory pools, but for now this is convenient and the ANTLR3_LIST is not 260*16467b97STreehugger Robot * a huge overhead as it only stores pointers anyway, but allows for iterations and 261*16467b97STreehugger Robot * so on. 262*16467b97STreehugger Robot */ 263*16467b97STreehugger Robot TokensType m_tokens; 264*16467b97STreehugger Robot 265*16467b97STreehugger Robot /** Override map of tokens. If a token type has an entry in here, then 266*16467b97STreehugger Robot * the pointer in the table points to an int, being the override channel number 267*16467b97STreehugger Robot * that should always be used for this token type. 268*16467b97STreehugger Robot */ 269*16467b97STreehugger Robot ChannelOverridesType m_channelOverrides; 270*16467b97STreehugger Robot 271*16467b97STreehugger Robot /** Discared set. If a token has an entry in this table, then it is thrown 272*16467b97STreehugger Robot * away (data pointer is always NULL). 273*16467b97STreehugger Robot */ 274*16467b97STreehugger Robot DiscardSetType m_discardSet; 275*16467b97STreehugger Robot 276*16467b97STreehugger Robot /* The channel number that this token stream is tuned to. For instance, whitespace 277*16467b97STreehugger Robot * is usually tuned to channel 99, which no token stream would normally tune to and 278*16467b97STreehugger Robot * so it is thrown away. 279*16467b97STreehugger Robot */ 280*16467b97STreehugger Robot ANTLR_UINT32 m_channel; 281*16467b97STreehugger Robot 282*16467b97STreehugger Robot /** The index into the tokens list of the current token (the next one that will be 283*16467b97STreehugger Robot * consumed. p = -1 indicates that the token list is empty. 284*16467b97STreehugger Robot */ 285*16467b97STreehugger Robot ANTLR_INT32 m_p; 286*16467b97STreehugger Robot 287*16467b97STreehugger Robot /* The total number of tokens issued till now. For streams that delete tokens, 288*16467b97STreehugger Robot this helps in issuing the index 289*16467b97STreehugger Robot */ 290*16467b97STreehugger Robot ANTLR_UINT32 m_nissued; 291*16467b97STreehugger Robot 292*16467b97STreehugger Robot /** If this flag is set to true, then tokens that the stream sees that are not 293*16467b97STreehugger Robot * in the channel that this stream is tuned to, are not tracked in the 294*16467b97STreehugger Robot * tokens table. When set to false, ALL tokens are added to the tracking. 295*16467b97STreehugger Robot */ 296*16467b97STreehugger Robot bool m_discardOffChannel; 297*16467b97STreehugger Robot 298*16467b97STreehugger Robot public: 299*16467b97STreehugger Robot CommonTokenStream(ANTLR_UINT32 hint, TokenSourceType* source = NULL, 300*16467b97STreehugger Robot DebugEventListenerType* debugger = NULL); 301*16467b97STreehugger Robot ~CommonTokenStream(); 302*16467b97STreehugger Robot TokensType& get_tokens(); 303*16467b97STreehugger Robot const TokensType& get_tokens() const; 304*16467b97STreehugger Robot DiscardSetType& get_discardSet(); 305*16467b97STreehugger Robot const DiscardSetType& get_discardSet() const; 306*16467b97STreehugger Robot ANTLR_INT32 get_p() const; 307*16467b97STreehugger Robot void set_p( ANTLR_INT32 p ); 308*16467b97STreehugger Robot void inc_p(); 309*16467b97STreehugger Robot void dec_p(); 310*16467b97STreehugger Robot 311*16467b97STreehugger Robot /** A simple filter mechanism whereby you can tell this token stream 312*16467b97STreehugger Robot * to force all tokens of type ttype to be on channel. For example, 313*16467b97STreehugger Robot * when interpreting, we cannot exec actions so we need to tell 314*16467b97STreehugger Robot * the stream to force all WS and NEWLINE to be a different, ignored 315*16467b97STreehugger Robot * channel. 316*16467b97STreehugger Robot */ 317*16467b97STreehugger Robot void setTokenTypeChannel(ANTLR_UINT32 ttype, ANTLR_UINT32 channel); 318*16467b97STreehugger Robot 319*16467b97STreehugger Robot /** Add a particular token type to the discard set. If a token is found to belong 320*16467b97STreehugger Robot * to this set, then it is skipped/thrown away 321*16467b97STreehugger Robot */ 322*16467b97STreehugger Robot void discardTokenType(ANTLR_INT32 ttype); 323*16467b97STreehugger Robot 324*16467b97STreehugger Robot //This will discard tokens of a particular rule after the rule execution completion 325*16467b97STreehugger Robot void discardTokens( ANTLR_MARKER start, ANTLR_MARKER stop ); 326*16467b97STreehugger Robot void discardTokens( ANTLR_MARKER start, ANTLR_MARKER stop, 327*16467b97STreehugger Robot BoolForwarder<true> tokens_accessed_from_owning_rule ); 328*16467b97STreehugger Robot void discardTokens( ANTLR_MARKER start, ANTLR_MARKER stop, 329*16467b97STreehugger Robot BoolForwarder<false> tokens_accessed_from_owning_rule ); 330*16467b97STreehugger Robot 331*16467b97STreehugger Robot void insertToken( const TokenType& tok ); 332*16467b97STreehugger Robot void insertToken( const TokenType& tok, BoolForwarder<true> tokens_accessed_from_owning_rule ); 333*16467b97STreehugger Robot void insertToken( const TokenType& tok, BoolForwarder<false> tokens_accessed_from_owning_rule ); 334*16467b97STreehugger Robot 335*16467b97STreehugger Robot /** Get a token at an absolute index i; 0..n-1. This is really only 336*16467b97STreehugger Robot * needed for profiling and debugging and token stream rewriting. 337*16467b97STreehugger Robot * If you don't want to buffer up tokens, then this method makes no 338*16467b97STreehugger Robot * sense for you. Naturally you can't use the rewrite stream feature. 339*16467b97STreehugger Robot * I believe DebugTokenStream can easily be altered to not use 340*16467b97STreehugger Robot * this method, removing the dependency. 341*16467b97STreehugger Robot */ 342*16467b97STreehugger Robot const TokenType* get(ANTLR_MARKER i); 343*16467b97STreehugger Robot const TokenType* getToken(ANTLR_MARKER i); 344*16467b97STreehugger Robot const TokenType* getToken( ANTLR_MARKER tok_idx, BoolForwarder<true> tokens_accessed_from_owning_rule ); 345*16467b97STreehugger Robot const TokenType* getToken( ANTLR_MARKER tok_idx, BoolForwarder<false> tokens_accessed_from_owning_rule ); 346*16467b97STreehugger Robot 347*16467b97STreehugger Robot /** Signal to discard off channel tokens from here on in. 348*16467b97STreehugger Robot */ 349*16467b97STreehugger Robot void discardOffChannelToks(bool discard); 350*16467b97STreehugger Robot 351*16467b97STreehugger Robot /** Function that returns a pointer to the ANTLR3_LIST of all tokens 352*16467b97STreehugger Robot * in the stream (this causes the buffer to fill if we have not get any yet) 353*16467b97STreehugger Robot */ 354*16467b97STreehugger Robot TokensType* getTokens(); 355*16467b97STreehugger Robot 356*16467b97STreehugger Robot /** Function that returns all the tokens between a start and a stop index. 357*16467b97STreehugger Robot */ 358*16467b97STreehugger Robot void getTokenRange(ANTLR_UINT32 start, ANTLR_UINT32 stop, TokensListType& tokenRange); 359*16467b97STreehugger Robot 360*16467b97STreehugger Robot /** Function that returns all the tokens indicated by the specified bitset, within a range of tokens 361*16467b97STreehugger Robot */ 362*16467b97STreehugger Robot void getTokensSet(ANTLR_UINT32 start, ANTLR_UINT32 stop, BitsetType* types, TokensListType& tokenSet); 363*16467b97STreehugger Robot 364*16467b97STreehugger Robot /** Function that returns all the tokens indicated by being a member of the supplied List 365*16467b97STreehugger Robot */ 366*16467b97STreehugger Robot void getTokensList(ANTLR_UINT32 start, ANTLR_UINT32 stop, 367*16467b97STreehugger Robot const IntListType& list, TokensListType& tokenList); 368*16467b97STreehugger Robot 369*16467b97STreehugger Robot /** Function that returns all tokens of a certain type within a range. 370*16467b97STreehugger Robot */ 371*16467b97STreehugger Robot void getTokensType(ANTLR_UINT32 start, ANTLR_UINT32 stop, ANTLR_UINT32 type, TokensListType& tokens); 372*16467b97STreehugger Robot 373*16467b97STreehugger Robot /** Function that resets the token stream so that it can be reused, but 374*16467b97STreehugger Robot * but that does not free up any resources, such as the token factory 375*16467b97STreehugger Robot * the factory pool and so on. This prevents the need to keep freeing 376*16467b97STreehugger Robot * and reallocating the token pools if the thing you are building is 377*16467b97STreehugger Robot * a multi-shot dameon or somethign like that. It is much faster to 378*16467b97STreehugger Robot * just reuse all the vectors. 379*16467b97STreehugger Robot */ 380*16467b97STreehugger Robot void reset(); 381*16467b97STreehugger Robot 382*16467b97STreehugger Robot const TokenType* LB(ANTLR_INT32 k); 383*16467b97STreehugger Robot 384*16467b97STreehugger Robot 385*16467b97STreehugger Robot void fillBufferExt(); 386*16467b97STreehugger Robot void fillBuffer(); 387*16467b97STreehugger Robot 388*16467b97STreehugger Robot bool hasReachedFillbufferTarget( ANTLR_UINT32 cnt, BoolForwarder<true> tokens_accessed_from_owning_rule ); 389*16467b97STreehugger Robot bool hasReachedFillbufferTarget( ANTLR_UINT32 cnt, BoolForwarder<false> tokens_accessed_from_owning_rule ); 390*16467b97STreehugger Robot 391*16467b97STreehugger Robot ANTLR_UINT32 skipOffTokenChannels(ANTLR_INT32 i); 392*16467b97STreehugger Robot ANTLR_UINT32 skipOffTokenChannelsReverse(ANTLR_INT32 x); 393*16467b97STreehugger Robot ANTLR_MARKER index_impl(); 394*16467b97STreehugger Robot }; 395*16467b97STreehugger Robot 396*16467b97STreehugger Robot class TokenAccessException : public std::exception 397*16467b97STreehugger Robot { what() const398*16467b97STreehugger Robot virtual const char* what() const throw() 399*16467b97STreehugger Robot { 400*16467b97STreehugger Robot return " Attempted access on Deleted Token"; 401*16467b97STreehugger Robot } 402*16467b97STreehugger Robot }; 403*16467b97STreehugger Robot 404*16467b97STreehugger Robot ANTLR_END_NAMESPACE() 405*16467b97STreehugger Robot 406*16467b97STreehugger Robot #include "antlr3tokenstream.inl" 407*16467b97STreehugger Robot 408*16467b97STreehugger Robot #endif 409