00001 #ifndef INC_InputBuffer_hpp__
00002 #define INC_InputBuffer_hpp__
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <antlr/config.hpp>
00012 #include <antlr/CircularQueue.hpp>
00013 #include <string>
00014
00015 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00016 namespace antlr {
00017 #endif
00018
00031 class ANTLR_API InputBuffer {
00032 public:
00034 InputBuffer()
00035 : nMarkers(0)
00036 , markerOffset(0)
00037 , numToConsume(0)
00038 {
00039 }
00040
00041 virtual ~InputBuffer()
00042 {
00043 }
00044
00046 virtual inline void reset( void )
00047 {
00048 nMarkers = 0;
00049 markerOffset = 0;
00050 numToConsume = 0;
00051 queue.clear();
00052 }
00053
00060 inline void commit( void )
00061 {
00062 nMarkers--;
00063 }
00064
00066 virtual inline void consume()
00067 {
00068 numToConsume++;
00069 }
00070
00072 virtual void fill(unsigned int amount);
00073
00075 virtual int getChar()=0;
00076
00078 virtual inline int LA(unsigned int i)
00079 {
00080 fill(i);
00081 return queue.elementAt(markerOffset + i - 1);
00082 }
00083
00087 virtual unsigned int mark();
00089 virtual inline bool isMarked() const
00090 {
00091 return (nMarkers != 0);
00092 }
00096 virtual void rewind(unsigned int mark);
00097
00100 virtual unsigned int entries() const;
00101
00102 ANTLR_USE_NAMESPACE(std)string getLAChars() const;
00103
00104 ANTLR_USE_NAMESPACE(std)string getMarkedChars() const;
00105
00106 protected:
00107
00108
00109
00110
00111 unsigned int nMarkers;
00112
00113
00114 unsigned int markerOffset;
00115
00116
00117 unsigned int numToConsume;
00118
00119
00120 CircularQueue<int> queue;
00121
00123 void syncConsume();
00124
00125 private:
00126 InputBuffer(const InputBuffer& other);
00127 InputBuffer& operator=(const InputBuffer& other);
00128 };
00129
00131 inline void InputBuffer::syncConsume() {
00132 if (numToConsume > 0)
00133 {
00134 if (nMarkers > 0)
00135 markerOffset += numToConsume;
00136 else
00137 queue.removeItems( numToConsume );
00138 numToConsume = 0;
00139 }
00140 }
00141
00142 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00143 }
00144 #endif
00145
00146 #endif //INC_InputBuffer_hpp__