diff core/src/luan/LuanTable.java @ 423:1eafb11a150d

remove Luan.repr()
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 01 May 2015 16:30:28 -0600
parents af82b266fe89
children 0a2fb80907f9
line wrap: on
line diff
--- 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());
 	}