summaryrefslogtreecommitdiff
path: root/src/cli/runtime/LineNumberingTextReader.cs
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2006-06-15 22:04:43 +0000
committerRich Hickey <richhickey@gmail.com>2006-06-15 22:04:43 +0000
commit3d54fc288b133949a5f49a078641ca07e7ccf3d0 (patch)
treef1eca839a2d880ed42281075ecdd9a0e2f48cef4 /src/cli/runtime/LineNumberingTextReader.cs
parenta6945186568b8265f775e448778255d16daba8db (diff)
reader in sync both platforms, symbols, vars, hostnames, numbers, strings, chars, lists, comments
Diffstat (limited to 'src/cli/runtime/LineNumberingTextReader.cs')
-rw-r--r--src/cli/runtime/LineNumberingTextReader.cs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/cli/runtime/LineNumberingTextReader.cs b/src/cli/runtime/LineNumberingTextReader.cs
index 7ccdc874..71f05e8d 100644
--- a/src/cli/runtime/LineNumberingTextReader.cs
+++ b/src/cli/runtime/LineNumberingTextReader.cs
@@ -19,6 +19,8 @@ public class LineNumberingTextReader : TextReader, IDisposable
{
TextReader impl;
int line = 0;
+ int unreadChar;
+ bool haveUnread = false;
public LineNumberingTextReader(TextReader r){
this.impl = r;
@@ -29,11 +31,27 @@ public class LineNumberingTextReader : TextReader, IDisposable
}
override public int Read(){
- int ret = impl.Read();
+ int ret;
+ if(haveUnread)
+ {
+ ret = unreadChar;
+ haveUnread = false;
+ }
+ else
+ ret = impl.Read();
if(ret == '\n')
++line;
return ret;
}
+
+ public void unread(int ch){
+ if(haveUnread)
+ throw new InvalidOperationException("Can't unread more than once in a row");
+ unreadChar = ch;
+ haveUnread = true;
+ if (ch == '\n')
+ --line;
+ }
override public int Peek(){
return impl.Peek();