ANTLR Support Libraries 2.7.1+
LexerSharedInputState.hpp
Go to the documentation of this file.
1 #ifndef INC_LexerSharedInputState_hpp__
2 #define INC_LexerSharedInputState_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: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/antlr/LexerSharedInputState.hpp#2 $
9  */
10 
11 #include <antlr/config.hpp>
12 #include <antlr/InputBuffer.hpp>
13 #include <antlr/RefCount.hpp>
14 #include <antlr/CharBuffer.hpp>
15 #include <string>
16 
17 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
18 namespace antlr {
19 #endif
20 
27 public:
33  : column(1)
34  , line(1)
35  , tokenStartColumn(1)
36  , tokenStartLine(1)
37  , guessing(0)
38  , filename("")
39  , input(inbuf)
40  , inputResponsible(true)
41  {
42  }
43 
48  : column(1)
49  , line(1)
50  , tokenStartColumn(1)
51  , tokenStartLine(1)
52  , guessing(0)
53  , filename("")
54  , input(&inbuf)
55  , inputResponsible(false)
56  {
57  }
58 
64  : column(1)
65  , line(1)
66  , tokenStartColumn(1)
67  , tokenStartLine(1)
68  , guessing(0)
69  , filename("")
70  , input(new CharBuffer(in))
71  , inputResponsible(true)
72  {
73  }
74 
80  virtual void initialize( ANTLR_USE_NAMESPACE(std)istream& in, const char* file = "" )
81  {
82  column = 1;
83  line = 1;
84  tokenStartColumn = 1;
85  tokenStartLine = 1;
86  guessing = 0;
87  filename = file;
88 
89  if( input && inputResponsible )
90  delete input;
91 
92  input = new CharBuffer(in);
93  inputResponsible = true;
94  }
95 
99  virtual void reset( void )
100  {
101  column = 1;
102  line = 1;
103  tokenStartColumn = 1;
104  tokenStartLine = 1;
105  guessing = 0;
106  input->reset();
107  }
108 
113  void setPosition( int line_, int column_ )
114  {
115  line = line_;
116  column = column_;
117  }
118 
120  {
121  if (inputResponsible)
122  delete input;
123  }
124 
125  int column;
126  int line;
129  int guessing;
132  InputBuffer& getInput();
133 private:
138 
139  // we don't want these:
141  LexerInputState& operator=(const LexerInputState&);
142 };
143 
145 {
146  return *input;
147 }
148 
151 
152 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
153 }
154 #endif
155 
156 #endif //INC_LexerSharedInputState_hpp__
bool inputResponsible
Who is responsible for cleaning up the InputBuffer?
Definition: LexerSharedInputState.hpp:137
virtual void initialize(std ::istream &in, const char *file="")
Definition: LexerSharedInputState.hpp:80
Definition: ANTLRException.hpp:15
int line
Definition: LexerSharedInputState.hpp:126
RefCount< LexerInputState > LexerSharedInputState
A reference counted LexerInputState object.
Definition: LexerSharedInputState.hpp:150
Definition: InputBuffer.hpp:31
int guessing
Definition: LexerSharedInputState.hpp:129
#define ANTLR_API
Definition: config.hpp:22
std ::string filename
Definition: LexerSharedInputState.hpp:131
int tokenStartLine
Definition: LexerSharedInputState.hpp:128
InputBuffer & getInput()
Definition: LexerSharedInputState.hpp:144
int tokenStartColumn
Definition: LexerSharedInputState.hpp:127
void setPosition(int line_, int column_)
Definition: LexerSharedInputState.hpp:113
LexerInputState(InputBuffer &inbuf)
Definition: LexerSharedInputState.hpp:47
LexerInputState(std ::istream &in)
Definition: LexerSharedInputState.hpp:63
virtual void reset(void)
Definition: LexerSharedInputState.hpp:99
int column
Definition: LexerSharedInputState.hpp:125
InputBuffer * input
Input buffer we use.
Definition: LexerSharedInputState.hpp:135
#define ANTLR_USE_NAMESPACE(_x_)
Definition: config.hpp:18
virtual ~LexerInputState()
Definition: LexerSharedInputState.hpp:119
LexerInputState(InputBuffer *inbuf)
Definition: LexerSharedInputState.hpp:32
Definition: CharBuffer.hpp:35
Definition: LexerSharedInputState.hpp:26