summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2003-12-03 12:20:57 +0000
committerburaq <buraq@epfl.ch>2003-12-03 12:20:57 +0000
commit6ab80e73d356da9f10e36f8640221bf7a2660316 (patch)
treed7ca308b47bc2508d66182849cc42a5c86dfa742 /sources
parent0861b9b3990cce69ba39f261291b0e1601cc22bb (diff)
downloadscala-6ab80e73d356da9f10e36f8640221bf7a2660316.tar.gz
scala-6ab80e73d356da9f10e36f8640221bf7a2660316.tar.bz2
scala-6ab80e73d356da9f10e36f8640221bf7a2660316.zip
adapted to whitespace handling
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/tools/dtd2scala/DeclToScala.scala143
-rw-r--r--sources/scala/tools/dtd2scala/template/ObjectTemplate.scala.xml92
2 files changed, 93 insertions, 142 deletions
diff --git a/sources/scala/tools/dtd2scala/DeclToScala.scala b/sources/scala/tools/dtd2scala/DeclToScala.scala
index f80d1c8376..a6711e97b4 100644
--- a/sources/scala/tools/dtd2scala/DeclToScala.scala
+++ b/sources/scala/tools/dtd2scala/DeclToScala.scala
@@ -29,106 +29,66 @@ class DeclToScala(fOut:PrintWriter,
var curAttribs: Map[String,AttrDecl] = null ; /* of current elem */
def write:Unit = {
- def writeNode( x:Node ):Unit = x match {
- case Text(text) =>
- fOut.print( text );
- case n:AttributedNode =>
- n.label match {
- case "template" => {
- lookup.update("objectName", objectName);
- lookup.update("compressDefault", compress.toString());
- n.children.elements.foreach { n => writeNode(n) }
- }
- case "elementBinding" => {
- for( val decl <- elemMap.values.elements ) {
- fOut.println();
- printIndent();
- lookup += "elementName" -> decl.name;
- lookup += "elementContainsText" -> decl.containsText.toString();
- lookup += "elementContentModel" -> decl.contentModel;
- curAttribs = decl.attribs;
- n.children.elements.foreach{ n => writeNode( n ) }
+ def writeNode( x:Node ):Unit = {
+ /*Console.println("visiting "+x);*/
+ x match {
+ case Text(text) =>
+ fOut.print( text );
+ case n:AttributedNode =>
+ n.label match {
+ case "template" => {
+ lookup.update("objectName", objectName);
+ lookup.update("compressDefault", compress.toString());
+ n.children.elements.foreach { n => writeNode(n) }
}
- curAttribs = null;
- lookup -= "elementName";
- lookup -= "elementContainsText";
- }
-
- case "attributeAssign" => {
- for( val aDecl <- curAttribs.keys.elements ) {
- lookup += "attributeName" -> aDecl;
- n.children.elements.foreach{ n => writeNode( n ) }
+ case "elementBinding" => {
+ for( val decl <- elemMap.values.elements ) {
+ lookup += "elementName" -> decl.name;
+ lookup += "elementContainsText" -> decl.containsText.toString();
+ lookup += "elementContentModel" -> decl.contentModel;
+ curAttribs = decl.attribs;
+ n.children.elements.foreach{ n => writeNode( n ) }
+ }
+ curAttribs = null;
+ lookup -= "elementName";
+ lookup -= "elementContainsText";
}
- lookup -= "attributeName";
- }
-
- case "attributeBinding" => {
- for( val aDecl <- curAttribs.keys.elements ) {
- lookup += "attributeName" -> aDecl;
- n.children.elements.foreach{ n => writeNode( n ) }
+ case "attributeAssign" => {
+ for( val aDecl <- curAttribs.keys.elements ) {
+ lookup += "attributeName" -> aDecl;
+ n.children.elements.foreach{ n => writeNode( n ) }
+ }
+ lookup -= "attributeName";
}
- lookup -= "attributeName";
- }
- case "ccstring" => {
- fOut.print( cookedCap( lookup( n("ref").get ) ));
- }
- case "cstring" => {
- fOut.print( cooked( lookup( n("ref").get ) ));
- }
- case "string" => {
- fOut.print( lookup( n("ref").get ) );
- }
- case "qstring" => {
-
- fOut.print("\"");
- fOut.print( lookup( n("ref").get ) );
- fOut.print("\"");
+ case "attributeBinding" => {
+ for( val aDecl <- curAttribs.keys.elements ) {
+ lookup += "attributeName" -> aDecl;
+ n.children.elements.foreach{ n => writeNode( n ) }
+ }
+ lookup -= "attributeName";
+ }
+ case "ccstring" => {
+ fOut.print( cookedCap( lookup( n("ref").get ) ));
+ }
+ case "cstring" => {
+ fOut.print( cooked( lookup( n("ref").get ) ));
+ }
+ case "string" => {
+ fOut.print( lookup( n("ref").get ) );
+ }
+ case "qstring" => {
+ fOut.print("\"");
+ fOut.print( lookup( n("ref").get ) );
+ fOut.print("\"");
+ }
+ case _ => error("what shall I do with a \""+n.label+"\" node ?")
}
- case "br" => { fOut.println(); printIndent() }
- case "inc" => fIndent = fIndent + IND_STEP
- case "dec" => fIndent = fIndent - IND_STEP
- case _ => error("what shall I do with a \""+n.label+"\" node ?")
- }
+ }
}
-
writeNode( tmpl )
}
}
- final val IND_STEP:int = 5;
-
- var fIndent:int = 0;
-
- /*
- // convenience ! overloaded constructors, have to appear *before*
- // the class def and need the "final" modifier
-
- fOut.println( "final def "+clazzName+"(ch:Seq[Element]):"+clazzName+" = new "+clazzName+"( null[scala.Map[String,String]], ch ) ;" );
-
- printIndent();
-
- fOut.println( "final def "+clazzName+"( el:Element ):"+clazzName+" = new "+clazzName+"( null[scala.Map[String,String]], el::Nil[Element] ) ;" );
-
- printIndent();
-
- // might contain text
- if( decl.contentModel.indexOf("#PCDATA") != -1 ) {
-
- fOut.println( "final def "+clazzName+"( text:String ):"+clazzName+" = new "+clazzName+"( PCDATA( text ) );" );
- printIndent();
-
- }
-
- */
-
-
- /** Prints the indent. */
- def printIndent():Unit = {
- for (val i<-List.range(0, fIndent)) {
- fOut.print(' ');
- }
- }
-
/** runs translation. */
def run:Unit = {
new objectTemplate {
@@ -150,6 +110,7 @@ class DeclToScala(fOut:PrintWriter,
//
// cooking raw names
//
+
/* replace dash, colons with underscore, keywords with appended $ */
private def cooked( ckd:StringBuffer, raw:String, off:int ):String = {
for( val i <- List.range( off, raw.length()) ) {
diff --git a/sources/scala/tools/dtd2scala/template/ObjectTemplate.scala.xml b/sources/scala/tools/dtd2scala/template/ObjectTemplate.scala.xml
index 7de018711c..37ab3b6b9a 100644
--- a/sources/scala/tools/dtd2scala/template/ObjectTemplate.scala.xml
+++ b/sources/scala/tools/dtd2scala/template/ObjectTemplate.scala.xml
@@ -7,82 +7,72 @@
<!ENTITY qAttributeName '<qstring ref="attributeName"/>'>
<!ENTITY cAttributeName '<cstring ref="attributeName"/>'>
<!ENTITY space '<![CDATA[ ]]>'>
- <!ENTITY br '<br/>'>
+ <!ENTITY br ''>
]>
<!-- generalize to abstract syntax instead of concrete ? -->
<!-- the formatting should be done by a code beautifier -->
<template>
/* this file is generated from a DTD using ObjectTemplate.scala.xml */
- <br/>
<!-- package/ -->
import scala.xml._ ;&br;
-import scala.collection.Map ;<br/>
-import scala.collection.mutable.HashMap ;<br/>
- <br/>
+import scala.collection.Map ;
+import scala.collection.mutable.HashMap ;
+
/** the following elements are bound
<elementBinding>
- * &elementName; : &elementContentModel; {
- <attributeBinding>&attributeName;</attributeBinding>&space;
- }
+ * &elementName; : &elementContentModel; {<attributeBinding>&attributeName;</attributeBinding>&space;}
</elementBinding>
**/
- <br/>
- object <string ref="objectName"/> {<inc/><br/>
+
+ object <string ref="objectName"/> {
type childrenT = scala.Seq[scala.xml.Node];
- type attribMapT = HashMap[String,String];<br/>
- type NodeConstructorType = (childrenT,attribMapT) =&gt; scala.xml.Node;<br/>
+ type attribMapT = HashMap[String,String];
+ type NodeConstructorType = (childrenT,attribMapT) =&gt; scala.xml.Node;
<elementBinding>
def constr_&ccElementName;( ch:childrenT, attrs:attribMapT ) =
- new &ccElementName;(ch:_*) { <inc/><br/>
- def attributes : Map[String,String] = attrs; <br/>
+ new &ccElementName;(ch:_*) {
+ def attributes : Map[String,String] = attrs;
<attributeAssign>
- override val &cAttributeName; = attrs.get(&qAttributeName;); <br/>
+ override val &cAttributeName; = attrs.get(&qAttributeName;);
</attributeAssign>
- val attribHashCode: int = attrs.toList.hashCode() ;<br/>
- };<dec/><br/>
- def &ccElementName;( ch:Node* ) = new &ccElementName;(ch:_*){<inc/><br/>
- def attributes = scala.collection.immutable.ListMap.Empty[String,String];<br/>
+ val attribHashCode: int = attrs.toList.hashCode() ;
+ };
+ def &ccElementName;( ch:Node* ) = new &ccElementName;(ch:_*){
+ def attributes = scala.collection.immutable.ListMap.Empty[String,String];
val attribHashCode = 0;
};
- abstract case class &ccElementName;( ch:Node* ) extends scala.xml.AttributedNode {<inc/><br/>
- def label = &qElementName;; <br/>
- def children = ch;<br/>
+ abstract case class &ccElementName;( ch:Node* ) extends scala.xml.AttributedNode {
+ def label = &qElementName;;
+ def children = ch;
<attributeBinding>
- val &cAttributeName; : scala.Option[String] = scala.None;
- /* overridden at parse time */
- </attributeBinding><dec/><br/>
+ val &cAttributeName; : scala.Option[String] = scala.None; /* o'ridden at parse time */
+ </attributeBinding>
}
</elementBinding>
- <br/>
-
- def load( filename:String ):Node =
- load( filename, <string ref="compressDefault"/> );<br/>
-<br/>
- def load( filename:String, _compress:boolean ):scala.xml.Node = {<inc/><br/>
+
- val fAdapter = new BindingFactoryAdapter {<inc/><br/>
+ def load( filename:String ):Node = load( filename, <string ref="compressDefault"/> );
- val f = { <inc/><br/>
- val res = new HashMap[String, NodeConstructorType] ;<br/>
- <elementBinding>
- res.update( &qElementName;,
- (x:childrenT,aMap:attribMapT) => constr_&ccElementName;(x,aMap));
- </elementBinding><br/>
- res;<dec/><br/>
- }<br/>
+ def load( filename:String, _compress:boolean ):scala.xml.Node = {
+ val fAdapter = new BindingFactoryAdapter {
+ val f = {
+ val res = new HashMap[String, NodeConstructorType] ;
+ <elementBinding>
+ res.update( &qElementName;, (x:childrenT,aMap:attribMapT) => constr_&ccElementName;(x,aMap));</elementBinding>
+ res;
+ }
- val g = { <inc/><br/>
- val res = new HashMap[scala.String, boolean] ;
- <elementBinding>
- res.update( &qElementName;, <string ref="elementContainsText"/>);<br/>
- </elementBinding><br/>
- res;<dec/><br/>
- }<br/>
- val compress = _compress ; <dec/><br/>
- };<dec/><br/>
- fAdapter.loadXML( filename );<br/>
- };<dec/><br/>
+ val g = {
+ val res = new HashMap[scala.String, boolean] ;
+ <elementBinding>
+ res.update( &qElementName;, <string ref="elementContainsText"/>);</elementBinding>
+ res;
+ }
+ val compress = _compress ;
+ };
+ fAdapter.loadXML( filename );
+ };
}
</template>