summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sources/scala/tools/dtd2scala/DeclToSQL.scala2
-rw-r--r--sources/scala/tools/dtd2scala/DeclToScala.scala11
-rw-r--r--sources/scala/tools/dtd2scala/MainHandler.scala37
-rw-r--r--sources/scala/tools/dtd2scala/MyElemDecl.scala10
-rw-r--r--sources/scala/tools/scalac/ast/parser/MarkupParser.scala32
-rw-r--r--test/files/run/xmlLiterals.check16
-rw-r--r--test/files/run/xmlLiterals.scala156
-rw-r--r--test/files/run/xmlParsing.check0
-rw-r--r--test/files/run/xmlParsing.scala51
-rw-r--r--test/files/run/xmlParsing_attr.check2
-rw-r--r--test/files/run/xmlParsing_attr.scala17
-rw-r--r--test/files/run/xmlParsing_servlet.check23
-rw-r--r--test/files/run/xmlParsing_servlet.scala83
-rw-r--r--test/files/run/xmlRef.check2
-rw-r--r--test/files/run/xmlRef.scala23
15 files changed, 69 insertions, 396 deletions
diff --git a/sources/scala/tools/dtd2scala/DeclToSQL.scala b/sources/scala/tools/dtd2scala/DeclToSQL.scala
index 064bea8c79..1aac891782 100644
--- a/sources/scala/tools/dtd2scala/DeclToSQL.scala
+++ b/sources/scala/tools/dtd2scala/DeclToSQL.scala
@@ -5,7 +5,7 @@ import scala.tools.dtd2scala.regexp._ ;
import java.io.PrintWriter ;
import scala.collection.mutable.{Set,Map,HashMap,HashSet} ;
-class DeclToSQL(fOut:PrintWriter,mName:String,elemMap:Map[String,ElemDecl ] ) {
+class DeclToSQL(fOut:PrintWriter,mName:String,elemMap:Map[String,MyElemDecl ] ) {
abstract class Vertex {
var marked = false;
diff --git a/sources/scala/tools/dtd2scala/DeclToScala.scala b/sources/scala/tools/dtd2scala/DeclToScala.scala
index 152b255822..cd2bf74c28 100644
--- a/sources/scala/tools/dtd2scala/DeclToScala.scala
+++ b/sources/scala/tools/dtd2scala/DeclToScala.scala
@@ -10,6 +10,7 @@ import scala.collection.Map ;
import scala.collection.mutable.HashMap ;
import scala.xml._ ;
+import scala.xml.dtd._;
import scala.xml.nobinding.XML ;
/** transforms a set of DTD declaraion to a scala source file.
@@ -17,7 +18,7 @@ import scala.xml.nobinding.XML ;
*/
class DeclToScala(fOut:PrintWriter,
moduleName:String,
- elemMap:Map[ String, ElemDecl ] ) {
+ elemMap:Map[ String, MyElemDecl ] ) {
abstract class objectTemplate {
val objectName : String = "myXML"; /* DEFAULT MODULE NAME */
@@ -71,17 +72,17 @@ class DeclToScala(fOut:PrintWriter,
lookup -= "attributeName";
}
case "ccstring" => {
- fOut.print( cookedCap( lookup( n("ref").get ) ));
+ fOut.print( cookedCap( lookup( n.attribute("ref") ) ));
}
case "cstring" => {
- fOut.print( cooked( lookup( n("ref").get ) ));
+ fOut.print( cooked( lookup( n.attribute("ref") ) ));
}
case "string" => {
- fOut.print( lookup( n("ref").get ) );
+ fOut.print( lookup( n.attribute("ref") ) );
}
case "qstring" => {
fOut.print("\"");
- fOut.print( lookup( n("ref").get ) );
+ fOut.print( lookup( n.attribute("ref") ) );
fOut.print("\"");
}
case _ => error("what shall I do with a \""+n.label+"\" node ?")
diff --git a/sources/scala/tools/dtd2scala/MainHandler.scala b/sources/scala/tools/dtd2scala/MainHandler.scala
index 595b98a34d..588ce99fa8 100644
--- a/sources/scala/tools/dtd2scala/MainHandler.scala
+++ b/sources/scala/tools/dtd2scala/MainHandler.scala
@@ -3,13 +3,14 @@ package scala.tools.dtd2scala ;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.ext.DeclHandler;
+import scala.xml.dtd._ ;
import scala.collection.mutable.HashMap ;
// 2 do : - handle modes of attributes ( #REQUIRED, defaults for #IMPLIED )
/** SAX handler, reacts to events during declaration parsing */
class MainHandler extends DefaultHandler with DeclHandler {
- var elemMap:HashMap[String,ElemDecl] = new HashMap[String,ElemDecl];
+ var elemMap:HashMap[String,MyElemDecl] = new HashMap[String,MyElemDecl];
// zzz DTDHandler methods zzz
@@ -17,13 +18,13 @@ class MainHandler extends DefaultHandler with DeclHandler {
def elementDecl( name:String, contentModel:String ) = {
elemMap.get( name ).match {
case Some(decl) => // was added because of ATTLIST decl before
- elemMap.update( name, ElemDecl( decl.name,
- contentModel,
- decl.attribs ) )
+ elemMap.update( name, new MyElemDecl( decl.name,
+ contentModel,
+ decl.myAttribs ) )
case None =>
- elemMap.update( name, ElemDecl( name,
- contentModel,
- new HashMap[String,AttrDecl]() ));
+ elemMap.update( name, new MyElemDecl( name,
+ contentModel,
+ new HashMap[String,AttrDecl]() ));
}
} // elementDecl(String,String)
@@ -37,13 +38,21 @@ class MainHandler extends DefaultHandler with DeclHandler {
val attribs = elemMap.get( elementName ).match {
case None => { val amap = new HashMap[String,AttrDecl];
elemMap.update( elementName,
- ElemDecl( elementName,
- null:String,
- amap ));
- amap; }
- case Some(decl) => decl.attribs;
- };
- attribs.update( attributeName, AttrDecl(attributeName, tpe ));
+ new MyElemDecl( elementName,
+ null:String,
+ amap ));
+ amap
+ }
+ case Some(decl) => decl.myAttribs;
+ }
+ val defDecl = if( valueDefault == null ) {
+ DEFAULT( false, value );
+ } else valueDefault match {
+ case "#IMPLIED" => IMPLIED;
+ case "#REQUIRED" => REQUIRED;
+ case "#FIXED" => DEFAULT( true, value );
+ }
+ attribs.update( attributeName, AttrDecl(attributeName, tpe, defDecl ));
} // attributeDecl(String,String,String,String,String)
diff --git a/sources/scala/tools/dtd2scala/MyElemDecl.scala b/sources/scala/tools/dtd2scala/MyElemDecl.scala
new file mode 100644
index 0000000000..fc22af6b5a
--- /dev/null
+++ b/sources/scala/tools/dtd2scala/MyElemDecl.scala
@@ -0,0 +1,10 @@
+package scala.tools.dtd2scala ;
+
+import scala.xml.dtd._ ;
+import scala.collection.mutable.HashMap ;
+
+class MyElemDecl( name:String ,
+ contentModel:String ,
+ theAttribs:HashMap[String,AttrDecl] ) extends ElemDecl( name, contentModel, theAttribs ) {
+ def myAttribs = theAttribs;
+};
diff --git a/sources/scala/tools/scalac/ast/parser/MarkupParser.scala b/sources/scala/tools/scalac/ast/parser/MarkupParser.scala
index 24c2b055b7..66f9c96a62 100644
--- a/sources/scala/tools/scalac/ast/parser/MarkupParser.scala
+++ b/sources/scala/tools/scalac/ast/parser/MarkupParser.scala
@@ -25,11 +25,14 @@ class MarkupParser( unit:Unit, s:Scanner, p:Parser ) {
import scala.tools.scalac.ast.{TreeList => myTreeList}
val _ArrayBuffer = Name.fromString("ArrayBuffer");
- val _collection = Name.fromString("collection");
+ val _TreeMap = Name.fromString("TreeMap");
val _Elem = Name.fromString("Elem");
val _Seq = Name.fromString("Seq");
+ val _String = Name.fromString("String");
+ val _immutable = Name.fromString("immutable");
val _mutable = Name.fromString("mutable");
val _append = Name.fromString("append");
+ val _collection = Name.fromString("collection");
val _xml = Name.fromString("xml");
val _Node = Name.fromString("Node");
val _Text = Name.fromString("Text");
@@ -50,6 +53,9 @@ class MarkupParser( unit:Unit, s:Scanner, p:Parser ) {
private def _scala_Seq( pos: int ) =
p.convertToTypeId( _scala( pos, _Seq ));
+ private def _string( pos: int ) =
+ p.convertToTypeId( make.Ident( pos, _String ) );
+
private def _scala_xml( pos: int, name: Name ) =
make.Select( pos, _scala( pos, _xml ), name );
@@ -68,6 +74,9 @@ class MarkupParser( unit:Unit, s:Scanner, p:Parser ) {
private def _scala_collection_mutable( pos: int, name: Name ) =
make.Select(pos, _scala_collection(pos, _mutable ), name);
+ private def _scala_collection_immutable( pos: int, name: Name ) =
+ make.Select(pos, _scala_collection(pos, _immutable ), name);
+
private def _scala_collection_mutable_ArrayBuffer( pos: int ) =
make.Apply( pos,
make.AppliedType(pos,
@@ -79,6 +88,22 @@ class MarkupParser( unit:Unit, s:Scanner, p:Parser ) {
),
Tree.EMPTY_ARRAY );
+ private def _scala_collection_immutable_TreeMap( pos: int ) =
+ make.Apply( pos,
+ make.AppliedType(pos,
+ p.convertToConstr(
+ _scala_collection_immutable(pos, _TreeMap )),
+ Predef.Array[Tree](
+ _string( pos ),
+ _string( pos )
+ )
+ ),
+ Tree.EMPTY_ARRAY );
+
+ private def _emptyMap( pos:int ) = {
+ make.New( pos,_scala_collection_immutable_TreeMap( pos: int ));
+ }
+
private def _scala_Tuple2( pos:int ) =
_scala( pos, Names.Tuple2 );
@@ -101,15 +126,16 @@ class MarkupParser( unit:Unit, s:Scanner, p:Parser ) {
if( isPattern ) {
val ts = new myTreeList();
ts.append( t );
+ ts.append( new Tree$Ident( Names.PATTERN_WILDCARD ) );
ts.append( convertToText( args ) );
make.Apply(pos,
convertToTypeId( _scala_xml_Elem( pos ) ),
ts.toArray())
} else {
val constrArgs = if( 0 == args.length ) {
- Predef.Array[Tree]( t )
+ Predef.Array[Tree]( t, _emptyMap( pos ) )
} else {
- Predef.Array[Tree]( t, make.Typed(
+ Predef.Array[Tree]( t, _emptyMap( pos ), make.Typed(
pos, makeXMLseq(pos, args), make.Ident(pos, TypeNames.WILDCARD_STAR)))
};
make.Apply( pos, _scala_xml_Elem( pos ), constrArgs )
diff --git a/test/files/run/xmlLiterals.check b/test/files/run/xmlLiterals.check
deleted file mode 100644
index 04f0426af9..0000000000
--- a/test/files/run/xmlLiterals.check
+++ /dev/null
@@ -1,16 +0,0 @@
-passed ok
-passed ok
-passed ok
-passed ok
-passed ok
-passed ok
-passed ok
-passed ok
-passed ok
-passed ok
-passed ok
-ArrayBuffer(<foo></foo>, <bar>Text</bar>, <foo></foo>)
-<foo></foo>
-passed ok
-passed ok
-passed ok
diff --git a/test/files/run/xmlLiterals.scala b/test/files/run/xmlLiterals.scala
deleted file mode 100644
index 63600f7962..0000000000
--- a/test/files/run/xmlLiterals.scala
+++ /dev/null
@@ -1,156 +0,0 @@
-//############################################################################
-// XML Literals
-//############################################################################
-// $Id$
-
-import scala.testing.UnitTest._ ;
-
-import scala.xml._ ;
-
-object Test with Application {
-
- def noWS(x:String):String = {
- val res = new StringBuffer();
- var i = 0; while( i < x.length() ) {
- val c = x.charAt( i );
- c match {
- case ' ' | '\n' | '\t' =>
- case _ => res.append( c )
- }
- i = i + 1;
- }
- res.toString();
- }
-
-
-
- /* */
- /* === tags, elements === */
- /* */
-
- val x = <hello></hello>.toString(); /* see neg(1) */
-
- /* whitespace (ws) handling */
-
- val x2 = <hello > </hello>.toString(); /* ws in tags allowed */
-
- assertEquals( x, noWS( x2 ) );
-
- val x3 = <hello>
- <world></world>
- <test/>
- <mars></mars></hello>.toString(); /* ws in element content */
-
-
- assertEquals( noWS( x3 ),
- Elem("hello",
- Elem("world"),
- Elem("test"),
- Elem("mars")).toString() );
-
-
- /* */
- /* === attributes === */
- /* */
-
- val z = <html>
- <body background="#FFFFFF">
- <h1>Hello World</h1>
- <p>Check the <a href="scala.epfl.ch">scala</a> page!</p>
- </body>
- </html>.toString();
-
- assertEquals( noWS( z ), noWS(
- Elem("html",
- Elem("body",
- Elem("h1",Text("Hello World")),
- Elem("p",Text("Check the "),
- Elem("a", Text("scala"))
- % Pair("href","scala.epfl.ch"),
- Text("page!"))
- ) % Pair("background","#FFFFFF")
- ).toString()
- ));
-
- /* todo: better way to deal with whitespace in content */
- /* (Canonical XML or even more aggressive normlization) */
-
- /* */
- /* === embedded Scala blocks === */
- /* */
-
- def computeDate() = {
- Elem("date", Text("now!"));
- }
-
-
- /* embedding Scala strings as text and elements */
- val sc = <hello>{ "World" }{ Text("42") }{ computeDate() }</hello>;
-
- assertEquals( sc.child.elements.toList,
- List( Text("World"), Text("42"), Elem( "date", Text("now!") ) ) );
-
- assertEquals( sc.toString(),
- Elem("hello",Text("World42"),Elem("date",Text("now!"))).toString() );
-
- def foo( m:Node ):String = m match {
- case <hello/> => "hello node"
- case <hallo ></hallo > => "hallo node"
- case <test>{ z }</test> => "test node:"+z
- case <list>{ e1:Node }{ e2:Node }{ _* }</list> => e1.toString() + e2.toString();
- }
-
- assertEquals( foo(<hello/>), "hello node" );
- assertEquals( foo(<hallo/>), "hallo node" );
- assertEquals( foo(<test>42</test>), "test node:42" );
- assertEquals( foo(<list><a/><b><c/></b><d/><d/></list>),
- <a/>.toString() + <b><c/></b>.toString() );
-
- val rows = <tr>
- <td>1.1</td><td>1.2</td>
- </tr>
- <tr>
- <td>2.1</td><td>2.2</td>
- </tr>;
-
- assertEquals( noWS( rows.toList.toString() ),
- noWS( List(Elem("tr",
- Elem("td",Text("1.1")),Elem("td",Text("1.2"))
- ),
- Elem("tr",
- Elem("td",Text("2.1")),Elem("td",Text("2.2"))
- )
- ).toString() )
- );
- val rows2 = <tr><!-- an XML comment --><td>1.1</td><td>1.2</td>
- </tr>
- <tr>
- <td>2.1</td><td>2.2</td>
- </tr>;
-
- assertEquals( noWS( rows.toList.toString() ), noWS( rows2.toList.toString() ) );
-
- val sequence = <foo/>
- <bar>Text</bar>
- <foo/>;
-
- Console.println( sequence );
-
- val onlyOne = <foo/>;
-
- Console.println( onlyOne );
-
- val tryBrace = <try>Now we try escaped {{ braces } </try>;
-
- assertEquals( tryBrace, Elem("try",Text("Now we try escaped { braces }")));
-
- val tryBrace2 = <try myAttrib={ (3+4).toString() }> cool ?</try>;
-
- assertEquals( tryBrace2("myAttrib").get, "7" );
-
- /* Scala comments are not allowed in XML literals. see neg(2) */
- val zzz = <hello>/* no comment */</hello>;
- assertEquals( zzz, Elem("hello", Text("/* no comment */")));
-
-}
-
diff --git a/test/files/run/xmlParsing.check b/test/files/run/xmlParsing.check
deleted file mode 100644
index e69de29bb2..0000000000
--- a/test/files/run/xmlParsing.check
+++ /dev/null
diff --git a/test/files/run/xmlParsing.scala b/test/files/run/xmlParsing.scala
deleted file mode 100644
index beedf44b62..0000000000
--- a/test/files/run/xmlParsing.scala
+++ /dev/null
@@ -1,51 +0,0 @@
-//############################################################################
-// XML Parsing
-//############################################################################
-// $Id$
-
-import scala.testing.UnitTest._ ;
-
-import scala.xml._ ;
-
-/** this file test just succesful run of the parser. There are no checks whether
- * the encoding to Scala expressions is done correctly
- */
-object Test with Application {
-
- val x0 = <hello/>;
- val x1s = <foo></foo>.toString();
- val x2 = <foo><bar><baz/></bar><bar/></foo>.toString();
-
- /* whitespace (ws) handling */
-
- val x3 = <hello > </hello>.toString(); /* ws in tags allowed */
-
- val x4 = <hello>
- <world></world>
- <test/>
- <mars></mars></hello>.toString(); /* ws in element content */
-
- /* attributes */
-
- val z = <html>
- <body background="#FFFFFF">
- <h1>Hello World</h1>
- <p>Check the <a href="scala.epfl.ch">scala</a> page!</p>
- </body>
- </html>.toString();
-
- val ent = <foo>
- hello &nbsp; character entities!
- welcome &#0160; unicode characters!
- </foo>;
-
-
- val foo = <a/><b/><c/>;
-
- val foo2 = foo match {
- case <a/><b/> => 1
- case <a></a><b></b><c></c> => 2
- case Seq(Elem("a"),Elem("b"),Elem("c")) => 3
- };
-
-}
diff --git a/test/files/run/xmlParsing_attr.check b/test/files/run/xmlParsing_attr.check
deleted file mode 100644
index 9c042b5de2..0000000000
--- a/test/files/run/xmlParsing_attr.check
+++ /dev/null
@@ -1,2 +0,0 @@
-<testTag value="This is a test." ab="bkla"></testTag>
-<testTag value="42" bla="foo"></testTag>
diff --git a/test/files/run/xmlParsing_attr.scala b/test/files/run/xmlParsing_attr.scala
deleted file mode 100644
index ea2eb60bf6..0000000000
--- a/test/files/run/xmlParsing_attr.scala
+++ /dev/null
@@ -1,17 +0,0 @@
-import scala.xml._ ;
-
-object Test with Application {
-
- val testValue = "This is a test.";
-
- val testValue2 = 42;
-
- val page = <testTag value={ testValue } ab="bkla" />;
-
- val page2 = <testTag value={testValue2.toString()} bla="foo"></testTag>;
-
- Console.println( page.toString() );
-
- Console.println( page2.toString() );
-
-}
diff --git a/test/files/run/xmlParsing_servlet.check b/test/files/run/xmlParsing_servlet.check
deleted file mode 100644
index ef35a97716..0000000000
--- a/test/files/run/xmlParsing_servlet.check
+++ /dev/null
@@ -1,23 +0,0 @@
-<html>
- <head>
- <title>ModularFormatting</title>
- </head>
- <body>
- <h2>Welcome</h2>
- <p>
- What follows is an example of modular formatting.
- </p>
- <p>
- <table align="center">
- <tr>
- <td color="#222255" bgcolor="#AAAAFF"><h1> message </h1></td>
- </tr>
- </table>
- </p>
- <hr></hr>
- <p>
- Complicated layout tasks can be encapsulated and outsourced.
- </p>
- <h2>Bye!</h2>
- </body>
- </html>
diff --git a/test/files/run/xmlParsing_servlet.scala b/test/files/run/xmlParsing_servlet.scala
deleted file mode 100644
index 7bd622b0a6..0000000000
--- a/test/files/run/xmlParsing_servlet.scala
+++ /dev/null
@@ -1,83 +0,0 @@
-import scala.xml._ ;
-
-object Test {
-
- val headerMsg = Text("What follows is an example of modular formatting.");
- val footerMsg = Text("Complicated layout tasks can be encapsulated and outsourced.");
-
- /** helper function for the main page, provides header and a footer
- */
- def page( ns:Seq[Node] ) = {
- <html>
- <head>
- <title>ModularFormatting</title>
- </head>
- <body>
- <h2>Welcome</h2>
- <p>
- { headerMsg }
- </p>
- <p>
- { ns:_* }
- </p>
- <hr/>
- <p>
- { footerMsg }
- </p>
- <h2>Bye!</h2>
- </body>
- </html>
- }
-
- /** applies beautify to every element in a sequence
- */
- def beautify( xs:Seq[Node] ):Seq[Node] = xs.toList.map { beautify }
-
- /** this is a recursive procedure that adds some attributes to the tree
- */
- def beautify( n:Node ):Node = n match {
- case <td>{ xs @ _* }</td> =>
- <td bgcolor="#AAAAFF" color="#222255">{ xs:_* }</td>
-
- case <table>{ xs @ _* }</table> =>
- <table align="center">{ beautify( xs ):_* }</table>
-
- case Elem( label, xs @ _* ) =>
- Elem( label, beautify( xs ):_*)
-
- case _ => n
- }
-
- /** this function will take a node and put it in a table
- */
- def format( msg:Node ):Node = {
- <table>
- <tr>
- <td>{ msg }</td>
- </tr>
- </table>
- }
-
- /** returns a highlighted text node with the string given as arguemnt. if it
- * is null, supplies a default string.
- */
- def getMessage( x:String ) = {
- if( x == null )
- <h1> This could be YOUR message ! </h1>
- else
- <h1> { Text( x ) } </h1>
- }
-
- /** the entry method
- */
- def doGetXML() = {
- beautify( page( List( format( getMessage( "message" ) )) ));
- /* page( List( format( theMessage ))); */
-
- }
-
- def main( args:Array[String] ) = {
- Console.println( doGetXML() );
- }
-
-}
diff --git a/test/files/run/xmlRef.check b/test/files/run/xmlRef.check
deleted file mode 100644
index 049f160175..0000000000
--- a/test/files/run/xmlRef.check
+++ /dev/null
@@ -1,2 +0,0 @@
-<foo>{</foo>
-<foo>&nbsp;{<bar><baz></baz></bar><bar></bar></foo>
diff --git a/test/files/run/xmlRef.scala b/test/files/run/xmlRef.scala
deleted file mode 100644
index 47bc5dd6dd..0000000000
--- a/test/files/run/xmlRef.scala
+++ /dev/null
@@ -1,23 +0,0 @@
-//############################################################################
-// XML Parsing
-//############################################################################
-// $Id$
-
-import scala.testing.UnitTest._ ;
-
-import scala.xml._ ;
-
-/** this file test just succesful run of the parser. There are no checks whether
- * the encoding to Scala expressions is done correctly
- */
-object Test with Application {
-
- val x1s = <foo>&#0123;</foo>.toString();
-
- Console.println( x1s );
-
- val x2 = <foo>&nbsp;&#x7b;<bar><baz/></bar><bar/></foo>.toString();
-
- Console.println( x2 );
-
-}