diff options
author | Rich Hickey <richhickey@gmail.com> | 2006-06-02 02:21:52 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2006-06-02 02:21:52 +0000 |
commit | 11461aa4fd81e05305ec84ed8747666e3d165fb9 (patch) | |
tree | c1f94a277d7f9f5a6f76f80d0aaa1924de0ec113 /src/cli/runtime | |
parent | 08e27be5bba0400b651ed7877e72ff48bbdd6ccc (diff) |
added support for reader
Diffstat (limited to 'src/cli/runtime')
-rw-r--r-- | src/cli/runtime/LineNumberingTextReader.cs | 57 | ||||
-rw-r--r-- | src/cli/runtime/RT.cs | 55 |
2 files changed, 110 insertions, 2 deletions
diff --git a/src/cli/runtime/LineNumberingTextReader.cs b/src/cli/runtime/LineNumberingTextReader.cs new file mode 100644 index 00000000..5238c6e8 --- /dev/null +++ b/src/cli/runtime/LineNumberingTextReader.cs @@ -0,0 +1,57 @@ +/**
+ * Copyright (c) Rich Hickey. All rights reserved.
+ * The use and distribution terms for this software are covered by the
+ * Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
+ * which can be found in the file CPL.TXT at the root of this distribution.
+ * By using this software in any fashion, you are agreeing to be bound by
+ * the terms of this license.
+ * You must not remove this notice, or any other, from this software.
+ **/
+
+using System;
+using System.IO;
+
+namespace org.clojure.runtime
+ {
+
+
+public class LineNumberingTextReader : TextReader, IDisposable
+ {
+ TextReader impl;
+ int line = 0;
+
+ public LineNumberingTextReader(TextReader r){
+ this.impl = r;
+ }
+
+ public int getLineNumber(){
+ return line;
+ }
+
+ override public int Read(){
+ int ret = impl.Read();
+ if(ret == '\n')
+ ++line;
+ return ret;
+ }
+
+ override public int Peek(){
+ return impl.Peek();
+ }
+
+ public override void Close()
+ {
+ base.Close();
+ impl.Close();
+ }
+
+ void IDisposable.Dispose()
+ {
+ base.Dispose();
+ impl.Dispose();
+ }
+
+ }
+
+
+ }
diff --git a/src/cli/runtime/RT.cs b/src/cli/runtime/RT.cs index 51d40809..ef60aa77 100644 --- a/src/cli/runtime/RT.cs +++ b/src/cli/runtime/RT.cs @@ -12,6 +12,7 @@ using System;
using System.Collections;
+using System.IO;
namespace org.clojure.runtime
{
@@ -22,6 +23,15 @@ public class RT public static Symbol T = Symbol.intern("t");
public static Object[] EMPTY_ARRAY = new Object[0];
+
+ static public readonly Object[] chars;
+
+ static RT(){
+ chars = new Object[256];
+ for(int i=0;i<chars.Length;i++)
+ chars[i] = (char)i;
+ }
+
static public Object eq(Object arg1, Object arg2) {
return (arg1 == arg2)?T:null;
}
@@ -80,7 +90,9 @@ public class RT static public Object box(char x)
{
- return x;
+ if (x < chars.Length)
+ return chars[x];
+ return x;
}
static public Object box(bool x)
@@ -239,6 +251,45 @@ static public int boundedLength(Cons list, int limit) return i;
}
+
+///////////////////////////////// reader support ////////////////////////////////
+
+static Object readRet(int ret){
+ if(ret == -1)
+ return null;
+ return box((char) ret);
+}
+
+static public Object readChar(TextReader r) {
+ int ret = r.Read();
+ return readRet(ret);
+}
+
+static public Object peekChar(TextReader r) {
+ return readRet(r.Peek());
+}
+
+static public int getLineNumber(TextReader r)
+ {
+ if (r is LineNumberingTextReader)
+ return ((LineNumberingTextReader)r).getLineNumber();
+ return 0;
+ }
+
+static public TextReader getLineNumberingReader(TextReader r)
+ {
+ if (isLineNumberingReader(r))
+ return r;
+ return new LineNumberingTextReader(r);
+ }
+
+static public bool isLineNumberingReader(TextReader r)
+ {
+ return r is LineNumberingTextReader;
+ }
+
+/*-------------------------------- values --------------*/
+
static public Object setValues(ThreadLocalData tld, Object arg1)
{
if(tld == null)
@@ -296,7 +347,7 @@ static public Object setValues(ThreadLocalData tld, Object arg1, Object arg2, Ob }
static public Object setValues(ThreadLocalData tld, Object arg1, Object arg2, Object arg3, Object arg4,
- Object arg5, Cons args) /*throws Exception*/
+ Object arg5, Cons args) /**/
{
if(tld == null)
tld = ThreadLocalData.get();
|