1 /* Generated By:JavaCC: Do not edit this line. CharStream.h Version 6.0 */
2 /* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
7 #ifndef INITIAL_BUFFER_SIZE
8 #define INITIAL_BUFFER_SIZE 4096
15 * This class describes a character stream that maintains line and
16 * column number positions of the characters. It also has the capability
17 * to backup the stream to some extent. An implementation of this
18 * class is used in the TokenManager implementation generated by
21 * All the methods except backup can be implemented in any fashion. backup
22 * needs to be implemented correctly for the correct operation of the lexer.
23 * Rest of the methods are all used to get information like line number,
24 * column number and the string that constitutes a token and are not used
25 * by the lexer. Hence their implementation won't affect the generated lexer's
32 void setTabSize(int i) { tabSize = i; }
33 int getTabSize(int) { return tabSize; }
34 virtual int getColumn() { return trackLineColumn ? bufcolumn[bufpos] : -1; }
35 virtual int getLine() { return trackLineColumn ? bufline[bufpos] : -1; }
36 virtual int getEndColumn() { return trackLineColumn ? bufcolumn[bufpos] : -1; }
37 virtual int getEndLine() { return trackLineColumn ? bufline[bufpos] : -1; }
38 virtual int getBeginColumn() { return trackLineColumn ? bufcolumn[tokenBegin] : -1; }
39 virtual int getBeginLine() { return trackLineColumn ? bufline[tokenBegin] : -1; }
41 virtual bool getTrackLineColumn() { return trackLineColumn; }
42 virtual void setTrackLineColumn(bool val) { trackLineColumn = val; }
45 * Backs up the input stream by amount steps. Lexer calls this method if it
46 * had already read some characters, but could not use them to match a
47 * (longer) token. So, they will be used again as the prefix of the next
48 * token and it is the implemetation's responsibility to do this right.
50 virtual inline void backup(int amount) {
59 * Returns the next character that marks the beginning of the next token.
60 * All characters must remain in the buffer between two successive calls
61 * to this method to implement backup correctly.
63 virtual inline JAVACC_CHAR_TYPE BeginToken() {
65 JAVACC_CHAR_TYPE c = readChar();
72 * Returns the next character from the selected input. The method
73 * of selecting the input is the responsibility of the class
74 * implementing this class.
76 virtual inline JAVACC_CHAR_TYPE readChar() {
80 if (bufpos == bufsize) {
84 return buffer[bufpos];
88 if (bufpos >= maxNextCharInd) {
92 JAVACC_CHAR_TYPE c = buffer[bufpos];
94 if (trackLineColumn) {
102 virtual void ExpandBuff(bool wrapAround);
103 virtual void FillBuff();
106 * Returns a string made up of characters from the marked token beginning
107 * to the current buffer position. Implementations can return
108 * anything that they want to. For example, for efficiency, one might decide
109 * to just return NULL, which is a valid implementation.
111 virtual JAVACC_STRING_TYPE GetImage() {
112 if (bufpos >= tokenBegin)
113 return JAVACC_STRING_TYPE(buffer + tokenBegin, bufpos - tokenBegin + 1);
115 return JAVACC_STRING_TYPE(buffer + tokenBegin, bufsize - tokenBegin)
116 .append(buffer, bufpos + 1);
120 * Returns an array of characters that make up the suffix of length 'len' for
121 * the currently matched token. This is used to build up the matched string
122 * for use in actions in the case of MORE. A simple and inefficient
123 * implementation of this is as follows :
125 virtual JAVACC_STRING_TYPE GetSuffix(int len) {
126 if ((bufpos + 1) >= len) {
127 return JAVACC_STRING_TYPE(buffer + bufpos - len + 1, len);
129 return JAVACC_STRING_TYPE(buffer + bufsize - (len - bufpos - 1), len - bufpos - 1)
130 .append(buffer, bufpos + 1);
134 * The lexer calls this function to indicate that it is done with the stream
135 * and hence implementations can free any resources held by this class.
137 virtual void DeleteBuffers();
139 virtual ~CharStream() {
147 return inBuf == 0 && bufpos + 1 >= maxNextCharInd &&
148 inputStream->endOfInput();
151 CharStream(const JAVACC_CHAR_TYPE *buf, int sz, int startline,
152 int startcolumn, int buffersize) :
153 bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
154 buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
155 prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
156 inBuf(0),tabSize(8), trackLineColumn(true) {
157 ReInit(JAVACC_STRING_TYPE(buf, sz), startline, startcolumn, buffersize);
160 CharStream(const JAVACC_CHAR_TYPE *buf, int sz, int startline, int startcolumn) :
161 bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
162 buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
163 prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
164 inBuf(0),tabSize(8), trackLineColumn(true) {
165 ReInit(JAVACC_STRING_TYPE(buf, sz), startline, startcolumn, INITIAL_BUFFER_SIZE);
168 CharStream(const JAVACC_STRING_TYPE& str, int startline,
169 int startcolumn, int buffersize) :
170 bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
171 buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
172 prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
173 inBuf(0),tabSize(8), trackLineColumn(true) {
174 ReInit(str, startline, startcolumn, buffersize);
177 CharStream(const JAVACC_STRING_TYPE& str, int startline, int startcolumn) :
178 bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
179 buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
180 prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
181 inBuf(0) ,tabSize(8), trackLineColumn(true){
182 ReInit(str, startline, startcolumn, INITIAL_BUFFER_SIZE);
185 CharStream(ReaderStream *input_stream, int startline,
186 int startcolumn, int) :
187 bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
188 buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
189 prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
190 inBuf(0),tabSize(8), trackLineColumn(true) {
191 ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
194 CharStream(ReaderStream *input_stream, int startline, int startcolumn) :
195 bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
196 buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
197 prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
198 inBuf(0),tabSize(8), trackLineColumn(true) {
199 ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
202 CharStream(ReaderStream *input_stream) :
203 bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
204 buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
205 prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
206 inBuf(0),tabSize(8), trackLineColumn(true) {
207 ReInit(input_stream, 1, 1, INITIAL_BUFFER_SIZE);
210 virtual void ReInit(ReaderStream *input_stream, int startline, int startcolumn,
213 virtual void ReInit(ReaderStream *input_stream, int startline,
215 ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
218 virtual void ReInit(ReaderStream *input_stream) {
219 ReInit(input_stream, 1, 1, INITIAL_BUFFER_SIZE);
222 virtual void ReInit(const JAVACC_STRING_TYPE& str, int startline,
223 int startcolumn, int buffersize);
225 virtual void ReInit(const JAVACC_STRING_TYPE& str, int startline,
227 ReInit(str, startline, startcolumn, INITIAL_BUFFER_SIZE);
230 virtual void adjustBeginLineColumn(int newLine, int newCol);
233 virtual void UpdateLineColumn(JAVACC_CHAR_TYPE c);
237 ReaderStream *inputStream;
239 JAVACC_CHAR_TYPE * buffer;
251 bool trackLineColumn;
257 /* JavaCC - OriginalChecksum=5eaf75ef6a2c7859369c80cf6fd037e0 (do not edit this line) */