changeset 423:1eafb11a150d

remove Luan.repr()
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 01 May 2015 16:30:28 -0600
parents af82b266fe89
children 750a68eceb1d
files core/src/luan/LuanBit.java core/src/luan/LuanFunction.java core/src/luan/LuanRepr.java core/src/luan/LuanState.java core/src/luan/LuanTable.java core/src/luan/modules/BasicLuan.java core/src/luan/modules/Luan.luan
diffstat 7 files changed, 3 insertions(+), 93 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/LuanBit.java	Fri May 01 16:13:52 2015 -0600
+++ b/core/src/luan/LuanBit.java	Fri May 01 16:30:28 2015 -0600
@@ -104,20 +104,6 @@
 		return Luan.toString(obj);
 	}
 
-	public String repr(Object obj) throws LuanException {
-		if( obj == null )
-			return "nil";
-		if( obj instanceof Boolean )
-			return Luan.toString((Boolean)obj);
-		if( obj instanceof Number )
-			return Luan.toString((Number)obj);
-		if( obj instanceof String )
-			return "\"" + Luan.stringEncode((String)obj) + "\"";
-		if( obj instanceof LuanRepr )
-			return ((LuanRepr)obj).repr(luan);
-		throw exception( "value '" + obj + "' doesn't support repr()" );
-	}
-
 	public LuanFunction getHandlerFunction(String op,LuanTable t) throws LuanException {
 		Object f = t.getHandler(op);
 		if( f == null )
--- a/core/src/luan/LuanFunction.java	Fri May 01 16:13:52 2015 -0600
+++ b/core/src/luan/LuanFunction.java	Fri May 01 16:30:28 2015 -0600
@@ -1,7 +1,7 @@
 package luan;
 
 
-public abstract class LuanFunction implements LuanRepr {
+public abstract class LuanFunction {
 
 	public abstract Object call(LuanState luan,Object[] args) throws LuanException;
 
@@ -11,8 +11,4 @@
 		return "function: " + Integer.toHexString(hashCode());
 	}
 
-	@Override public String repr(LuanState luan) {
-		return "<" + toString() + ">";
-	}
-
 }
--- a/core/src/luan/LuanRepr.java	Fri May 01 16:13:52 2015 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-package luan;
-
-
-public interface LuanRepr {
-	public String repr(LuanState luan) throws LuanException;
-}
--- a/core/src/luan/LuanState.java	Fri May 01 16:13:52 2015 -0600
+++ b/core/src/luan/LuanState.java	Fri May 01 16:30:28 2015 -0600
@@ -48,7 +48,7 @@
 
 	// convenience methods
 
-	final LuanBit JAVA = bit(LuanElement.JAVA);
+	private final LuanBit JAVA = bit(LuanElement.JAVA);
 
 	public LuanException exception(Object msg) {
 		return JAVA.exception(msg);
@@ -78,10 +78,6 @@
 		return JAVA.toString(obj);
 	}
 
-	public String repr(Object obj) throws LuanException {
-		return JAVA.repr(obj);
-	}
-
 	public boolean isLessThan(Object o1,Object o2) throws LuanException {
 		return JAVA.isLessThan(o1,o2);
 	}
--- a/core/src/luan/LuanTable.java	Fri May 01 16:13:52 2015 -0600
+++ b/core/src/luan/LuanTable.java	Fri May 01 16:30:28 2015 -0600
@@ -15,7 +15,7 @@
 import java.util.regex.Pattern;
 
 
-public final class LuanTable implements Iterable<Map.Entry<Object,Object>>, LuanRepr, DeepCloneable<LuanTable> {
+public final class LuanTable implements Iterable<Map.Entry<Object,Object>>, DeepCloneable<LuanTable> {
 	private Map<Object,Object> map = null;
 	private List<Object> list = null;
 	private LuanTable metatable = null;
@@ -333,63 +333,6 @@
 		return isList() ? new LuanTable(new ArrayList<Object>(asList())) : new LuanTable(asMap());
 	}
 
-	@Override public String repr(LuanState luan) throws LuanException {
-		LuanFunction fn = luan.JAVA.getHandlerFunction("__repr",this);
-		if( fn != null )
-			return luan.JAVA.checkString( Luan.first( luan.call(fn,"__repr",new Object[]{this}) ) );
-		return repr( luan, Collections.newSetFromMap(new IdentityHashMap<LuanTable,Boolean>()) );
-	}
-
-	private String repr(LuanState luan,Set<LuanTable> set) throws LuanException {
-		if( !set.add(this) ) {
-			return "\"<circular reference>\"";
-		}
-		StringBuilder sb = new StringBuilder();
-		sb.append('{');
-		boolean isFirst = true;
-		for( Object obj : asList() ) {
-			if( isFirst ) {
-				isFirst = false;
-			} else {
-				sb.append(", ");
-			}
-			sb.append(repr(luan,set,obj));
-		}
-		for( Map.Entry<Object,Object> entry : map().entrySet() ) {
-			if( isFirst ) {
-				isFirst = false;
-			} else {
-				sb.append(", ");
-			}
-			sb.append(reprKey(luan,set,entry.getKey())).append('=').append(repr(luan,set,entry.getValue()));
-		}
-		sb.append('}');
-		return sb.toString();
-	}
-
-	private static final Pattern namePtn = Pattern.compile("[a-zA-Z_][a-zA-Z_0-9]*");
-
-	private String reprKey(LuanState luan,Set<LuanTable> set,Object obj) throws LuanException {
-		if( obj instanceof String ) {
-			String s = (String)obj;
-			if( namePtn.matcher(s).matches() )
-				return s;
-		}
-		return "[" + repr(luan,set,obj) + "]";
-	}
-
-	private String repr(LuanState luan,Set<LuanTable> set,Object obj) throws LuanException {
-		if( obj instanceof LuanTable ) {
-			LuanTable t = (LuanTable)obj;
-			return t.repr(luan,set);
-		} else {
-			String s = luan.repr(obj);
-			if( s == null )
-				s = "<couldn't repr: " + Luan.stringEncode(Luan.toString(obj)) + ">";
-			return s;
-		}
-	}
-
 	@Override public final String toString() {
 		return "table: " + Integer.toHexString(hashCode());
 	}
--- a/core/src/luan/modules/BasicLuan.java	Fri May 01 16:13:52 2015 -0600
+++ b/core/src/luan/modules/BasicLuan.java	Fri May 01 16:30:28 2015 -0600
@@ -183,10 +183,6 @@
 		return v;
 	}
 
-	public static String repr(LuanState luan,Object v) throws LuanException {
-		return luan.repr(v);
-	}
-
 	public static LuanFunction range(LuanState luan,final double from,final double to,Double stepV) throws LuanException {
 		final double step = stepV==null ? 1.0 : stepV;
 		if( step == 0.0 )
--- a/core/src/luan/modules/Luan.luan	Fri May 01 16:13:52 2015 -0600
+++ b/core/src/luan/modules/Luan.luan	Fri May 01 16:30:28 2015 -0600
@@ -22,7 +22,6 @@
 raw_get = BasicLuan.raw_get
 raw_len = BasicLuan.raw_len
 raw_set = BasicLuan.raw_set
-repr = BasicLuan.repr
 set_metatable = BasicLuan.set_metatable
 to_boolean = BasicLuan.to_boolean
 to_number = BasicLuan.to_number