2 * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 /* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 5.0 */
\r
9 /* JavaCCOptions:STATIC=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
\r
10 package org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse;
\r
13 * An implementation of interface CharStream, where the stream is assumed to
\r
14 * contain only ASCII characters (without unicode processing).
\r
17 public class SimpleCharStream
\r
19 /** Whether parser is static. */
\r
20 public static final boolean staticFlag = true;
\r
22 static int available;
\r
23 static int tokenBegin;
\r
24 /** Position in buffer. */
\r
25 static public int bufpos = -1;
\r
26 static protected int bufline[];
\r
27 static protected int bufcolumn[];
\r
29 static protected int column = 0;
\r
30 static protected int line = 1;
\r
32 static protected boolean prevCharIsCR = false;
\r
33 static protected boolean prevCharIsLF = false;
\r
35 static protected java.io.Reader inputStream;
\r
37 static protected char[] buffer;
\r
38 static protected int maxNextCharInd = 0;
\r
39 static protected int inBuf = 0;
\r
40 static protected int tabSize = 8;
\r
42 static protected void setTabSize(int i) { tabSize = i; }
\r
43 static protected int getTabSize(int i) { return tabSize; }
\r
46 static protected void ExpandBuff(boolean wrapAround)
\r
48 char[] newbuffer = new char[bufsize + 2048];
\r
49 int newbufline[] = new int[bufsize + 2048];
\r
50 int newbufcolumn[] = new int[bufsize + 2048];
\r
56 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
\r
57 System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
\r
60 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
\r
61 System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
\r
62 bufline = newbufline;
\r
64 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
\r
65 System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
\r
66 bufcolumn = newbufcolumn;
\r
68 maxNextCharInd = (bufpos += (bufsize - tokenBegin));
\r
72 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
\r
75 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
\r
76 bufline = newbufline;
\r
78 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
\r
79 bufcolumn = newbufcolumn;
\r
81 maxNextCharInd = (bufpos -= tokenBegin);
\r
86 throw new Error(t.getMessage());
\r
91 available = bufsize;
\r
95 static protected void FillBuff() throws java.io.IOException
\r
97 if (maxNextCharInd == available)
\r
99 if (available == bufsize)
\r
101 if (tokenBegin > 2048)
\r
103 bufpos = maxNextCharInd = 0;
\r
104 available = tokenBegin;
\r
106 else if (tokenBegin < 0)
\r
107 bufpos = maxNextCharInd = 0;
\r
111 else if (available > tokenBegin)
\r
112 available = bufsize;
\r
113 else if ((tokenBegin - available) < 2048)
\r
116 available = tokenBegin;
\r
121 if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1)
\r
123 inputStream.close();
\r
124 throw new java.io.IOException();
\r
127 maxNextCharInd += i;
\r
130 catch(java.io.IOException e) {
\r
133 if (tokenBegin == -1)
\r
134 tokenBegin = bufpos;
\r
140 static public char BeginToken() throws java.io.IOException
\r
143 char c = readChar();
\r
144 tokenBegin = bufpos;
\r
149 static protected void UpdateLineColumn(char c)
\r
155 prevCharIsLF = false;
\r
156 line += (column = 1);
\r
158 else if (prevCharIsCR)
\r
160 prevCharIsCR = false;
\r
163 prevCharIsLF = true;
\r
166 line += (column = 1);
\r
172 prevCharIsCR = true;
\r
175 prevCharIsLF = true;
\r
179 column += (tabSize - (column % tabSize));
\r
185 bufline[bufpos] = line;
\r
186 bufcolumn[bufpos] = column;
\r
189 /** Read a character. */
\r
190 static public char readChar() throws java.io.IOException
\r
196 if (++bufpos == bufsize)
\r
199 return buffer[bufpos];
\r
202 if (++bufpos >= maxNextCharInd)
\r
205 char c = buffer[bufpos];
\r
207 UpdateLineColumn(c);
\r
214 * @see #getEndColumn
\r
217 static public int getColumn() {
\r
218 return bufcolumn[bufpos];
\r
227 static public int getLine() {
\r
228 return bufline[bufpos];
\r
231 /** Get token end column number. */
\r
232 static public int getEndColumn() {
\r
233 return bufcolumn[bufpos];
\r
236 /** Get token end line number. */
\r
237 static public int getEndLine() {
\r
238 return bufline[bufpos];
\r
241 /** Get token beginning column number. */
\r
242 static public int getBeginColumn() {
\r
243 return bufcolumn[tokenBegin];
\r
246 /** Get token beginning line number. */
\r
247 static public int getBeginLine() {
\r
248 return bufline[tokenBegin];
\r
251 /** Backup a number of characters. */
\r
252 static public void backup(int amount) {
\r
255 if ((bufpos -= amount) < 0)
\r
259 /** Constructor. */
\r
260 public SimpleCharStream(java.io.Reader dstream, int startline,
\r
261 int startcolumn, int buffersize)
\r
263 if (inputStream != null)
\r
264 throw new Error("\n ERROR: Second call to the constructor of a static SimpleCharStream.\n" +
\r
265 " You must either use ReInit() or set the JavaCC option STATIC to false\n" +
\r
266 " during the generation of this class.");
\r
267 inputStream = dstream;
\r
269 column = startcolumn - 1;
\r
271 available = bufsize = buffersize;
\r
272 buffer = new char[buffersize];
\r
273 bufline = new int[buffersize];
\r
274 bufcolumn = new int[buffersize];
\r
277 /** Constructor. */
\r
278 public SimpleCharStream(java.io.Reader dstream, int startline,
\r
281 this(dstream, startline, startcolumn, 4096);
\r
284 /** Constructor. */
\r
285 public SimpleCharStream(java.io.Reader dstream)
\r
287 this(dstream, 1, 1, 4096);
\r
290 /** Reinitialise. */
\r
291 public void ReInit(java.io.Reader dstream, int startline,
\r
292 int startcolumn, int buffersize)
\r
294 inputStream = dstream;
\r
296 column = startcolumn - 1;
\r
298 if (buffer == null || buffersize != buffer.length)
\r
300 available = bufsize = buffersize;
\r
301 buffer = new char[buffersize];
\r
302 bufline = new int[buffersize];
\r
303 bufcolumn = new int[buffersize];
\r
305 prevCharIsLF = prevCharIsCR = false;
\r
306 tokenBegin = inBuf = maxNextCharInd = 0;
\r
310 /** Reinitialise. */
\r
311 public void ReInit(java.io.Reader dstream, int startline,
\r
314 ReInit(dstream, startline, startcolumn, 4096);
\r
317 /** Reinitialise. */
\r
318 public void ReInit(java.io.Reader dstream)
\r
320 ReInit(dstream, 1, 1, 4096);
\r
322 /** Constructor. */
\r
323 public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
\r
324 int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
\r
326 this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
\r
329 /** Constructor. */
\r
330 public SimpleCharStream(java.io.InputStream dstream, int startline,
\r
331 int startcolumn, int buffersize)
\r
333 this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
\r
336 /** Constructor. */
\r
337 public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
\r
338 int startcolumn) throws java.io.UnsupportedEncodingException
\r
340 this(dstream, encoding, startline, startcolumn, 4096);
\r
343 /** Constructor. */
\r
344 public SimpleCharStream(java.io.InputStream dstream, int startline,
\r
347 this(dstream, startline, startcolumn, 4096);
\r
350 /** Constructor. */
\r
351 public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
\r
353 this(dstream, encoding, 1, 1, 4096);
\r
356 /** Constructor. */
\r
357 public SimpleCharStream(java.io.InputStream dstream)
\r
359 this(dstream, 1, 1, 4096);
\r
362 /** Reinitialise. */
\r
363 public void ReInit(java.io.InputStream dstream, String encoding, int startline,
\r
364 int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
\r
366 ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
\r
369 /** Reinitialise. */
\r
370 public void ReInit(java.io.InputStream dstream, int startline,
\r
371 int startcolumn, int buffersize)
\r
373 ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
\r
376 /** Reinitialise. */
\r
377 public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
\r
379 ReInit(dstream, encoding, 1, 1, 4096);
\r
382 /** Reinitialise. */
\r
383 public void ReInit(java.io.InputStream dstream)
\r
385 ReInit(dstream, 1, 1, 4096);
\r
387 /** Reinitialise. */
\r
388 public void ReInit(java.io.InputStream dstream, String encoding, int startline,
\r
389 int startcolumn) throws java.io.UnsupportedEncodingException
\r
391 ReInit(dstream, encoding, startline, startcolumn, 4096);
\r
393 /** Reinitialise. */
\r
394 public void ReInit(java.io.InputStream dstream, int startline,
\r
397 ReInit(dstream, startline, startcolumn, 4096);
\r
399 /** Get token literal value. */
\r
400 static public String GetImage()
\r
402 if (bufpos >= tokenBegin)
\r
403 return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
\r
405 return new String(buffer, tokenBegin, bufsize - tokenBegin) +
\r
406 new String(buffer, 0, bufpos + 1);
\r
409 /** Get the suffix. */
\r
410 static public char[] GetSuffix(int len)
\r
412 char[] ret = new char[len];
\r
414 if ((bufpos + 1) >= len)
\r
415 System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
\r
418 System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
\r
420 System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
\r
426 /** Reset buffer when finished. */
\r
427 static public void Done()
\r
435 * Method to adjust line and column numbers for the start of a token.
\r
437 static public void adjustBeginLineColumn(int newLine, int newCol)
\r
439 int start = tokenBegin;
\r
442 if (bufpos >= tokenBegin)
\r
444 len = bufpos - tokenBegin + inBuf + 1;
\r
448 len = bufsize - tokenBegin + bufpos + 1 + inBuf;
\r
451 int i = 0, j = 0, k = 0;
\r
452 int nextColDiff = 0, columnDiff = 0;
\r
454 while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
\r
456 bufline[j] = newLine;
\r
457 nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
\r
458 bufcolumn[j] = newCol + columnDiff;
\r
459 columnDiff = nextColDiff;
\r
465 bufline[j] = newLine++;
\r
466 bufcolumn[j] = newCol + columnDiff;
\r
470 if (bufline[j = start % bufsize] != bufline[++start % bufsize])
\r
471 bufline[j] = newLine++;
\r
473 bufline[j] = newLine;
\r
478 column = bufcolumn[j];
\r
482 /* JavaCC - OriginalChecksum=3d5e5b74f810fa0f4ef70d18e9bc8601 (do not edit this line) */
\r