Added ability to order the execution of dictionary adapter behaviors.
[castle.git] / Experiments / Attic / Rook / Castle.Rook.Compiler / Parser / antlr / CharBuffer.cs
blob628680797d63af6eb4f5f843ef4311e614ebb351
1 using System;
2 using System.Runtime.InteropServices;
3 using TextReader = System.IO.TextReader;
4 using IOException = System.IO.IOException;
7 namespace antlr
9 /*ANTLR Translator Generator
10 * Project led by Terence Parr at http://www.jGuru.com
11 * Software rights: http://www.antlr.org/license.html
13 * $Id:$
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.
26 * <p>
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.
32 * <p>
35 // SAS: Move most functionality into InputBuffer -- just the file-specific
36 // stuff is in here
37 public class CharBuffer : InputBuffer
39 // char source
40 [NonSerialized()]
41 internal TextReader input;
43 private const int BUF_SIZE = 16;
44 /// <summary>
45 /// Small buffer used to avoid reading individual chars
46 /// </summary>
47 private char[] buf = new char[BUF_SIZE];
50 /*Create a character buffer */
51 public CharBuffer(TextReader input_) : base()
53 input = input_;
56 /*Ensure that the character buffer is sufficiently full */
57 override public void fill(int amount)
59 try
61 syncConsume();
62 // Fill the buffer sufficiently to hold needed characters
63 int charsToRead = (amount + markerOffset) - queue.Count;
64 int c;
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
73 queue.Add(buf[i]);
75 if (c < BUF_SIZE)
77 queue.Add(CharScanner.EOF_CHAR);
78 break;
80 charsToRead -= c;
83 catch (IOException io)
85 throw new CharStreamIOException(io);