{
public static Table build(Item item)
{
BuilderLib.checkTagged(item, Tags.tagTable, "Not a (table ...)") ;
ItemList list = item.getList() ;
int start = 1 ;
if ( list.size() == 1 )
// Null table;
return TableFactory.createEmpty() ;
// Maybe vars.
List<Var> vars = null ;
if ( list.size() > 1 )
{
Item item0 = list.get(1) ;
if ( item0.isTagged(Tags.tagVars) )
{
vars = BuilderNode.buildVarList(item0) ;
list = list.cdr() ;
}
}
if ( list.size() == 2 && list.get(1).isSymbol() )
{
// Short hand for well known tables
String symbol = list.get(1).getSymbol() ;
if ( symbol.equals("unit") )
return TableFactory.createUnit() ;
if ( symbol.equals("empty") )
return TableFactory.createEmpty() ;
BuilderLib.broken(list, "Don't recognized table symbol") ;
}
Table table = TableFactory.create(vars) ;
int count = 0 ;
Binding lastBinding = null ;
for ( int i = start ; i < list.size() ; i++ )
{
Item itemRow = list.get(i) ;
Binding b = BuilderBinding.build(itemRow) ;
table.addBinding(b) ;
lastBinding = b ;
count++ ;
}