1 #ifndef INC_LexerSharedInputState_hpp__
2 #define INC_LexerSharedInputState_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/LexerSharedInputState.hpp#2 $
11 #include <antlr/config.hpp>
12 #include <antlr/InputBuffer.hpp>
13 #include <antlr/RefCount.hpp>
14 #include <antlr/CharBuffer.hpp>
17 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
21 /** This object contains the data associated with an
22 * input stream of characters. Multiple lexers
23 * share a single LexerSharedInputState to lex
24 * the same input stream.
26 class ANTLR_API LexerInputState {
28 /** Construct a new LexerInputState
29 * @param inbuf the InputBuffer to read from. The object is deleted together
30 * with the LexerInputState object.
32 LexerInputState(InputBuffer* inbuf)
40 , inputResponsible(true)
44 /** Construct a new LexerInputState
45 * @param inbuf the InputBuffer to read from.
47 LexerInputState(InputBuffer& inbuf)
55 , inputResponsible(false)
59 /** Construct a new LexerInputState
60 * @param in an istream to read from.
61 * @see antlr.CharBuffer
63 LexerInputState(ANTLR_USE_NAMESPACE(std)istream& in)
70 , input(new CharBuffer(in))
71 , inputResponsible(true)
75 /** Reset the LexerInputState with a specified stream and filename.
76 * This method is a hack, dunno what I was thinking when I added it.
77 * This should actually be done in a subclass.
80 virtual void initialize( ANTLR_USE_NAMESPACE(std)istream& in, const char* file = "" )
89 if( input && inputResponsible )
92 input = new CharBuffer(in);
93 inputResponsible = true;
96 /** Reset the LexerInputState to initial state.
97 * The underlying InputBuffer is also reset.
99 virtual void reset( void )
103 tokenStartColumn = 1;
109 /** Set the file position of the SharedLexerInputState.
110 * @param line_ line number to be set
111 * @param column_ column number to be set
113 void setPosition( int line_, int column_ )
119 virtual ~LexerInputState()
121 if (inputResponsible)
127 int tokenStartColumn;
130 /** What file (if known) caused the problem? */
131 ANTLR_USE_NAMESPACE(std)string filename;
132 InputBuffer& getInput();
134 /// Input buffer we use
136 /// Who is responsible for cleaning up the InputBuffer?
137 bool inputResponsible;
139 // we don't want these:
140 LexerInputState(const LexerInputState&);
141 LexerInputState& operator=(const LexerInputState&);
144 inline InputBuffer& LexerInputState::getInput()
149 /// A reference counted LexerInputState object
150 typedef RefCount<LexerInputState> LexerSharedInputState;
152 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
156 #endif //INC_LexerSharedInputState_hpp__