From 3bb7dbfe4d6b03d2cc68a223b98dcd6e89d3ad50 Mon Sep 17 00:00:00 2001 From: michelou Date: Tue, 12 Dec 2006 13:14:08 +0000 Subject: added comma in generated Tuple1.toString method --- src/build/genprod.scala | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) (limited to 'src/build/genprod.scala') diff --git a/src/build/genprod.scala b/src/build/genprod.scala index bf4245b382..5ea86232db 100644 --- a/src/build/genprod.scala +++ b/src/build/genprod.scala @@ -15,6 +15,7 @@ *

* usage: scala -classpath ... genprod PATH * where PATH is the desired output directory + *

* * @author Burak Emir * @version 1.0 @@ -92,14 +93,20 @@ object genprod { import java.io.{File, FileOutputStream} import java.nio.channels.Channels val out = args(0) - for(val node <- allfiles) { + for (val node <- allfiles) { val f = new File(out + File.separator + node.attributes("name")) - f.createNewFile - val fos = new FileOutputStream(f) - val c = fos.getChannel - val w = Channels.newWriter(c, "utf-8") - w.write(node.text) - w.close + try { + f.createNewFile + val fos = new FileOutputStream(f) + val c = fos.getChannel + val w = Channels.newWriter(c, "utf-8") + w.write(node.text) + w.close + } catch { + case e: java.io.IOException => + Console.println(e.getMessage() + ": " + out) + System.exit(-1) + } } } } @@ -239,8 +246,14 @@ case class {tupleClassname(i)}{__typeArgs__}({ __fields__ }) {{ override def toString() = {{ val sb = new compat.StringBuilder - sb.append('{{'){for(val j <- List.range(1,i)) yield .append(_{j}).append(',')}.append(_{i}).append('}}') - sb.toString + { if ({i} == 1) + "sb.append('{').append(_" + {i} + ").append(\",}\")" + else { + val xs = List.range(1, i+1).map(i => ".append(_" + i + ")") + xs.mkString("sb.append('{')", ".append(',')",".append('}')") + } + } + sb.toString }} }} @@ -252,11 +265,12 @@ case class {tupleClassname(i)}{__typeArgs__}({ __fields__ }) {{ /* zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz P R O D U C T zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz */ + object ProductFile { import genprod._ def make(i:Int) = { - val __typeArgs__ = if(i==0) Nil else covariantArgs(i).mkString("[",", ","]") - val __refArgs__ = if(i==0) Nil else targs(i).mkString("[",", ","]") + val __typeArgs__ = if (i==0) Nil else covariantArgs(i).mkString("[",", ","]") + val __refArgs__ = if (i==0) Nil else targs(i).mkString("[",", ","]") /* __ *\ ** ________ ___ / / ___ Scala API ** @@ -275,8 +289,11 @@ package scala import Predef._ object {productClassname(i)} {{ - def unapply{__refArgs__}(x:Any): Option[{productClassname(i)}{__refArgs__}] = - if(x.isInstanceOf[{productClassname(i)}{__refArgs__}]) Some(x.asInstanceOf[{productClassname(i)}{__refArgs__}]) else None + def unapply{__refArgs__}(x: Any): Option[{productClassname(i)}{__refArgs__}] = + if (x.isInstanceOf[{productClassname(i)}{__refArgs__}]) + Some(x.asInstanceOf[{productClassname(i)}{__refArgs__}]) + else + None }} /** {productClassname(i)} is a cartesian product of {i} components @@ -303,7 +320,7 @@ trait {productClassname(i)}{__typeArgs__} extends Product {{ }} {for(val Tuple2(m, t) <- mdefs(i) zip targs(i)) yield - "/** projection of this product */\n def "+m+":"+t+"\n\n " } + "/** projection of this product */\n def " + m + ": " + t + "\n\n" } }} } -- cgit v1.2.3