2 using System
.Runtime
.InteropServices
;
3 using TextReader
= System
.IO
.TextReader
;
4 using IOException
= System
.IO
.IOException
;
9 /*ANTLR Translator Generator
10 * Project led by Terence Parr at http://www.jGuru.com
11 * Software rights: http://www.antlr.org/license.html
17 // ANTLR C# Code Generator by Micheal Jordan
18 // Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
19 // Anthony Oguntimehin
21 // With many thanks to Eric V. Smith from the ANTLR list.
24 /*A Stream of characters fed to the lexer from a InputStream that can
25 * be rewound via mark()/rewind() methods.
27 * A dynamic array is used to buffer up all the input characters. Normally,
28 * "k" characters are stored in the buffer. More characters may be stored during
29 * guess mode (testing syntactic predicate), or when LT(i>k) is referenced.
30 * Consumption of characters is deferred. In other words, reading the next
31 * character is not done by conume(), but deferred until needed by LA or LT.
35 // SAS: Move most functionality into InputBuffer -- just the file-specific
37 public class CharBuffer
: InputBuffer
41 internal TextReader input
;
43 private const int BUF_SIZE
= 16;
45 /// Small buffer used to avoid reading individual chars
47 private char[] buf
= new char[BUF_SIZE
];
50 /*Create a character buffer */
51 public CharBuffer(TextReader input_
) : base()
56 /*Ensure that the character buffer is sufficiently full */
57 override public void fill(int amount
)
62 // Fill the buffer sufficiently to hold needed characters
63 int charsToRead
= (amount
+ markerOffset
) - queue
.Count
;
66 while (charsToRead
> 0)
68 // Read a few characters
69 c
= input
.Read(buf
, 0, BUF_SIZE
);
70 for (int i
= 0; i
< c
; i
++)
72 // Append the next character
77 queue
.Add(CharScanner
.EOF_CHAR
);
83 catch (IOException io
)
85 throw new CharStreamIOException(io
);