summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2004-07-19 09:46:30 +0000
committerburaq <buraq@epfl.ch>2004-07-19 09:46:30 +0000
commitcf71c30d3cb9bcb7521a5f271101119ff2c8bb79 (patch)
tree71f97c4ee4e6e11d69a761b59fe37c2d11cd370f
parent036c29404e26e681378f6150c36b9f27d2bacde9 (diff)
downloadscala-cf71c30d3cb9bcb7521a5f271101119ff2c8bb79.tar.gz
scala-cf71c30d3cb9bcb7521a5f271101119ff2c8bb79.tar.bz2
scala-cf71c30d3cb9bcb7521a5f271101119ff2c8bb79.zip
moved parsing methods to lib
-rw-r--r--config/list/library.lst4
-rw-r--r--sources/scala/tools/scalac/ast/parser/MarkupParser.scala366
-rw-r--r--sources/scala/tools/scalac/ast/parser/SymbolicXMLBuilder.scala130
3 files changed, 108 insertions, 392 deletions
diff --git a/config/list/library.lst b/config/list/library.lst
index 9a3855d91f..f7acac0af4 100644
--- a/config/list/library.lst
+++ b/config/list/library.lst
@@ -213,6 +213,10 @@ xml/dtd/ValidationException.scala
xml/nobinding/NoBindingFactoryAdapter.scala
xml/nobinding/XML.scala
+xml/parsing/AttribValue.scala
+xml/parsing/FatalError.scala
+xml/parsing/MarkupParser.scala
+xml/parsing/MarkupHandler.scala
xml/path/Expression.scala
#xml/path/Tokens.scala
#xml/path/Scanner.scala
diff --git a/sources/scala/tools/scalac/ast/parser/MarkupParser.scala b/sources/scala/tools/scalac/ast/parser/MarkupParser.scala
index 20d6d8dbbf..f8d8ca938d 100644
--- a/sources/scala/tools/scalac/ast/parser/MarkupParser.scala
+++ b/sources/scala/tools/scalac/ast/parser/MarkupParser.scala
@@ -15,18 +15,24 @@ import java.lang.{Integer, Long, Float, Double};
import scala.Iterator;
import scala.tools.scalac.util.NewArray;
import scala.collection.immutable.ListMap ;
-import scala.collection.mutable.Buffer;
+import scala.collection.mutable;
import scala.xml.{Text,TextBuffer};
+import scala.xml.parsing.AttribValue ;
package scala.tools.scalac.ast.parser {
-class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, trimWS: boolean ) {
+class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, presWS: boolean ) with scala.xml.parsing.MarkupParser[Tree,Tree] {
import Tokens.{EMPTY, LBRACE, RBRACE} ;
import scala.tools.scalac.ast.{TreeList => myTreeList}
+ final val preserveWS = presWS;
+
/** the XML tree factory */
- val mk = new SymbolicXMLBuilder( unit.global.make, unit.global.treeGen, p, trimWS );
+ val handle: SymbolicXMLBuilder = new SymbolicXMLBuilder( unit.global.make, unit.global.treeGen, p, presWS );
+
+ //override type MarkupType = handle.MarkupType;
+ //override type AVType = handle.AVType;
/** the XML tree builder */
val gen = unit.global.treeGen ;
@@ -35,10 +41,10 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, trimWS: boolean
final val PATTERN = true;
final val EXPR = false;
- val cbuf = new StringBuffer();
+ //val cbuf = new StringBuffer();
/** append Unicode character to name buffer*/
- private def putChar(c: char) = cbuf.append( c );
+ //private def putChar(c: char) = cbuf.append( c );
/** xLiteral = xExpr { xExpr }
* @return Scala representation of this xml literal
@@ -50,13 +56,13 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, trimWS: boolean
val pos = s.pos;
var tree = xExpr; xSpaceOpt;
if( ch=='<' ) {
- val ts = new myTreeList(); ts.append( tree );
+ val ts = new mutable.ArrayBuffer[Tree](); ts.append( tree );
while( ch == '<' ) {
nextch;
ts.append( xExpr );
xSpaceOpt;
}
- tree = mk.makeXMLseq( pos, ts.toArray() );
+ tree = handle.makeXMLseq( pos, ts );
}
//Console.println("out of xLiteral, parsed:"+tree.toString());
s.xSync2;
@@ -80,7 +86,7 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, trimWS: boolean
ts.append( xPattern );
xSpaceOpt;
}
- tree = mk.makeXMLseqPat( pos, ts.toArray() );
+ tree = handle.makeXMLseqPat( pos, ts.toArray() );
}
mode = oldMode;
//Console.println("out of xLiteralPattern, parsed:"+tree.toString());
@@ -88,7 +94,7 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, trimWS: boolean
tree
}
- def xScalaExpr:Tree = {
+ def xEmbeddedExpr:Tree = {
sync;
val b = p.expr(true,false);
if(s.token != RBRACE)
@@ -109,10 +115,10 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, trimWS: boolean
return b
}
- var ch: Char = _;
+ //var ch: Char = _;
/** this method assign the next character to ch and advances in input */
- def nextch: Unit = { s.xNext; ch = s.ch; }
+ def nextch: Unit = { s.xNext; ch = s.ch; pos = s.pos; }
def lookahead = { s.xLookahead }
@@ -128,29 +134,29 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, trimWS: boolean
* | `{` scalablock `}`
*/
def xAttributes = {
- var aMap = new ListMap[String, Tree];
+ var aMap = new mutable.HashMap[String, AttribValue[Tree]];
while( xml.Parsing.isNameStart( ch )) {
val key = xName;
xEQ;
val delim = ch;
val value:Tree = ch match {
case '"' | '\'' =>
- val pos = s.pos;
+ val pos1 = pos;
nextch;
val tmp = xAttributeValue( delim );
nextch;
- gen.mkStringLit( pos, tmp )
+ gen.mkStringLit( pos1, tmp )
case '{' =>
nextch;
- xScalaExpr;
+ xEmbeddedExpr;
case _ =>
xSyntaxError( "' or \" delimited attribute value or '{' scala-expr '}' expected" );
- gen.mkStringLit( s.pos, "<syntax-error>" )
+ gen.mkStringLit( pos, "<syntax-error>" )
};
// well-formedness constraint: unique attribute names
if( aMap.contains( key ))
xSyntaxError( "attribute "+key+" may only be defined once" );
- aMap = aMap.update( key, value );
+ aMap.update( key, AttribValue( value ));
if(( ch != '/' )&&( ch != '>' ))
xSpace;
};
@@ -158,179 +164,38 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, trimWS: boolean
}
- /** attribute value, terminated by either ' or ". value may not contain <.
- * @param endch either ' or "
- */
- def xAttributeValue( endch:char ):String = {
- while ( ch != endch ) {
- putChar( ch );
- nextch;
- };
- val str = cbuf.toString();
- cbuf.setLength( 0 );
- // @todo: normalize attribute value
- // well-formedness constraint
- if( str.indexOf('<') != -1 ) {
- xSyntaxError( "'<' not allowed in attrib value" ); ""
- } else {
- str
- }
- }
-
- /** parse a start or empty tag.
- * [40] STag ::= '<' Name { S Attribute } [S]
- * [44] EmptyElemTag ::= '<' Name { S Attribute } [S]
- */
- def xTag = {
- val elemName = xName;
- xSpaceOpt;
- val aMap = if(xml.Parsing.isNameStart( ch )) {
- xAttributes;
- } else {
- ListMap.Empty[String,Tree];
- }
- Tuple2( elemName, aMap );
- }
-
- /** munch expected XML token, report syntax error for unexpected
- */
- def xToken(that: Char): Unit = {
- if( ch == that )
- nextch;
- else
- xSyntaxError("'" + that + "' expected instead of '" + ch + "'");
- }
-
- /* [42] '<' xmlEndTag ::= '<' '/' Name S? '>' */
- def xEndTag(n: String) = {
- xToken('/');
- val m = xName;
- if(n != m) xSyntaxError( "expected closing tag of " + n/* +", not "+m*/);
- xSpaceOpt;
- xToken('>')
- }
-
def xSyntaxError(str:String) = {
s.syntaxError("in XML literal: "+str);
nextch;
}
def sync: Unit = {
- xScalaBlock = false;
+ xEmbeddedBlock = false;
s.xSync;
}
- /* move forward one char
- *
- * @return true if next character starts a scala block
- */
- def xxNext:boolean = {
- nextch;
- xCheckScalaBlock
- }
-
- var xScalaBlock = false;
-
- /** checks whether next character starts a Scala block, if yes, skip it.
- * @return true if next character starts a scala block
- */
- def xCheckScalaBlock:Boolean = {
- xScalaBlock = ( ch == '{' ) && { nextch;( ch != '{' ) };
- return xScalaBlock;
- }
-
- /** '<' xExpr ::= xmlTag1 '>' { xmlExpr | '{' simpleExpr '}' } ETag
- * | xmlTag1 '/' '>'
- */
- def xExpr:Tree = {
- var pos = s.pos;
- val Tuple2(qname: String, attrMap: ListMap[String,Tree]) = xTag;
- if(ch == '/') { // empty element
- xToken('/');
- xToken('>');
- mk.makeXML( pos, qname, attrMap, Tree.EMPTY_ARRAY );
- } else { // handle content
- xToken('>');
- val ts = new myTreeList();
- var exit = false;
- while( !exit ) {
- if( xScalaBlock ) {
- ts.append( xScalaExpr );
- } else {
- pos = s.pos;
- ch match {
- case '<' => // another tag
- nextch;
- ch match {
- case '/' => exit = true; // end tag
- case '!' =>
- nextch;
- if( '[' == ch ) // CDATA
- ts.append( mk.CharData( pos, xCharData ));
- else // comment
- ts.append( mk.Comment( pos, xComment ));
- case '?' => // PI
- nextch;
- ts.append( mk.ProcInstr( pos, xProcInstr ));
- case _ => ts.append( xExpr ); // child
- }
-
- case '{' =>
- if( xCheckScalaBlock ) {
- ts.append( xScalaExpr );
- } else {
- val str = new StringBuffer("{");
- str.append( xText );
- mk.appendTrimmed( pos, mode, ts, str.toString() )
- }
- // postcond: xScalaBlock == false!
- case '&' => // EntityRef or CharRef
- nextch;
- ch match {
- case '#' => // CharacterRef
- nextch;
- val theChar = mk.makeText( s.pos, false, xCharRef );
- xToken(';');
- ts.append( theChar );
- case _ => // EntityRef
- val n = xName ;
- xToken(';');
- ts.append( mk.EntityRef( pos, n ));
- }
- case _ => // text content
- mk.appendTrimmed( pos, mode, ts, xText );
- // here xScalaBlock might be true
-
- }
- }
- }
- xEndTag( qname );
- mk.makeXML( pos, qname, attrMap, ts.toArray() );
- }
- }
-
-
/** '<' xPattern ::= Name [S] { xmlPattern | '{' pattern3 '}' } ETag
* | Name [S] '/' '>'
*/
def xPattern:Tree = {
//Console.println("xPattern");
- val pos = s.pos;
+ val pos1 = pos;
val qname = xName;
xSpaceOpt;
if( ch == '/' ) { // empty tag
nextch;
xToken('>');
- return mk.makeXMLpat( pos, qname, Tree.EMPTY_ARRAY );
+ return handle.makeXMLpat( pos1, qname, new mutable.ArrayBuffer[Tree]() );
};
// else: tag with content
xToken('>');
- val ts = new myTreeList();
+ var ts = new mutable.ArrayBuffer[Tree];
var exit = false;
while( !exit ) {
- if( xScalaBlock ) {
- ts.append( xScalaPatterns );
+ val pos2 = pos;
+ if( xEmbeddedBlock ) {
+ ts ++ xScalaPatterns;
} else
ch match {
case '<' => { // tag
@@ -344,174 +209,19 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, trimWS: boolean
case '{' => // embedded Scala patterns
while( ch == '{' ) {
s.nextch();
- ts.append( xScalaPatterns );
+ ts ++ xScalaPatterns;
}
- // postcond: xScalaBlock = false;
- if( xScalaBlock ) throw new ApplicationError(); // assert
- case _ => // text
- mk.appendTrimmed( pos, mode, ts, xText );
- // here xScalaBlock might be true;
- //if( xScalaBlock ) throw new ApplicationError("after:"+text); // assert
+ // postcond: xEmbeddedBlock = false;
+ if( xEmbeddedBlock ) throw new ApplicationError(); // assert
+ case _ => // teMaxt
+ appendTrimmed( pos2, mode, ts, xText );
+ // here xEmbeddedBlock might be true;
+ //if( xEmbeddedBlock ) throw new ApplicationError("after:"+text); // assert
}
}
xEndTag( qname );
- mk.makeXMLpat( pos, qname, ts.toArray() );
+ handle.makeXMLpat( pos1, qname, ts );
}
- /** '<! CharData ::= [CDATA[ ( {char} - {char}"]]>"{char} ) ']]>'
- *
- * see [15]
- */
- def xCharData:scala.xml.CharData = {
- xToken('[');
- xToken('C');
- xToken('D');
- xToken('A');
- xToken('T');
- xToken('A');
- xToken('[');
- val sb:StringBuffer = new StringBuffer();
- while (true) {
- if( ch==']' &&
- { sb.append( ch ); nextch; ch == ']' } &&
- { sb.append( ch ); nextch; ch == '>' } ) {
- sb.setLength( sb.length() - 2 );
- nextch;
- return scala.xml.CharData( sb.toString() );
- } else sb.append( ch );
- nextch;
- }
- return null; // this cannot happen;
- };
-
- /** CharRef ::= "&#" '0'..'9' {'0'..'9'} ";"
- * | "&#x" '0'..'9'|'A'..'F'|'a'..'f' { hexdigit } ";"
- *
- * see [66]
- */
- def xCharRef:String = {
- val hex = ( ch == 'x' ) && { nextch; true };
- val base = if (hex) 16 else 10;
- var i = 0;
- while( ch != ';' ) {
- ch match {
- case '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' =>
- i = i * base + Character.digit( ch, base );
- case 'a' | 'b' | 'c' | 'd' | 'e' | 'f'
- | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' =>
- if( !hex )
- xSyntaxError("hex char not allowed in decimal char ref\n"
- +"Did you mean to write &#x ?");
- else
- i = i * base + Character.digit( ch, base );
- case _ =>
- xSyntaxError("character '"+ch+" not allowed in char ref\n");
- }
- nextch;
- }
- new String( Predef.Array[char]( i.asInstanceOf[char] ))
- }
-
- /** Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
- *
- * see [15]
- */
- def xComment:scala.xml.Comment = {
- val sb:StringBuffer = new StringBuffer();
- xToken('-');
- xToken('-');
- while (true) {
- if( ch=='-' && { sb.append( ch ); nextch; ch == '-' } ) {
- sb.setLength( sb.length() - 1 );
- nextch;
- xToken('>');
- return scala.xml.Comment( sb.toString() );
- } else sb.append( ch );
- nextch;
- }
- return null; // this cannot happen;
- };
-
-
- /** Name ::= (Letter | '_' | ':') (NameChar)*
- *
- * see [5] of XML 1.0 specification
- */
- def xName: String = {
- if( xml.Parsing.isNameStart( ch ) ) {
- do {
- putChar( ch );
- nextch;
- } while( xml.Parsing.isNameChar( ch ) );
- val n = cbuf.toString().intern();
- cbuf.setLength( 0 );
- n
- } else {
- xSyntaxError( "name expected" );
- new String();
- }
- }
-
-
- /** scan [S] '=' [S]*/
- def xEQ = { xSpaceOpt; xToken('='); xSpaceOpt }
-
- /** skip optional space S? */
- def xSpaceOpt = { while( xml.Parsing.isSpace( ch ) ) { nextch; }}
-
- /** scan [3] S ::= (#x20 | #x9 | #xD | #xA)+ */
- def xSpace = {
- if( xml.Parsing.isSpace( ch ) ) {
- nextch; xSpaceOpt
- } else {
- xSyntaxError("whitespace expected");
- }
- }
-
- /** '<?' ProcInstr ::= Name [S ({Char} - ({Char}'>?' {Char})]'?>'
- *
- * see [15]
- */
- def xProcInstr:scala.xml.ProcInstr = {
- val sb:StringBuffer = new StringBuffer();
- val n = xName;
- if( xml.Parsing.isSpace( ch ) ) {
- xSpace;
- while( true ) {
- if( ch=='?' && { sb.append( ch ); nextch; ch == '>' } ) {
- sb.setLength( sb.length() - 1 );
- nextch;
- return scala.xml.ProcInstr( n.toString(), Some(sb.toString()) );
- } else
- sb.append( ch );
- nextch;
- }
- };
- xToken('?');
- xToken('>');
- scala.xml.ProcInstr( n.toString(), None );
- }
-
- /** parse character data.
- * precondition: xScalaBlock == false (we are not in a scala block)
- */
- def xText:String = {
- if( xScalaBlock ) throw new ApplicationError(); // assert
-
- if( xCheckScalaBlock )
- return ""
- else {
- var exit = false;
- while( !exit ) {
- putChar( ch );
- exit = xxNext || ( ch == '<' ) || ( ch == '&' );
- }
- val str = cbuf.toString();
- cbuf.setLength( 0 );
- str
- }
- }
-
-
} /* class MarkupParser */
}
diff --git a/sources/scala/tools/scalac/ast/parser/SymbolicXMLBuilder.scala b/sources/scala/tools/scalac/ast/parser/SymbolicXMLBuilder.scala
index 9634f2559d..64e7a9827a 100644
--- a/sources/scala/tools/scalac/ast/parser/SymbolicXMLBuilder.scala
+++ b/sources/scala/tools/scalac/ast/parser/SymbolicXMLBuilder.scala
@@ -14,14 +14,16 @@ import scala.tools.util.Position;
import java.lang.{Integer, Long, Float, Double};
import scala.Iterator;
import scala.tools.scalac.util.NewArray;
-import scala.collection.immutable.ListMap ;
-import scala.collection.mutable.Buffer;
+import scala.collection.immutable.{ Map, ListMap };
+import scala.collection.mutable;
import scala.xml.{Text,TextBuffer};
+import scala.xml.parsing.{ AttribValue, MarkupHandler };
import scalac.util.{ Name, Names, TypeNames } ;
+
package scala.tools.scalac.ast.parser {
/** this class builds instance of Tree that represent XML */
-class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS: Boolean ) {
+class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS: Boolean ) extends MarkupHandler[Tree,Tree] {
import scala.tools.scalac.ast.{TreeList => myTreeList}
@@ -140,6 +142,12 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS:
_scala_xml( pos, _Attribute );
+ private def bufferToArray(buf: mutable.Buffer[Tree]): Array[Tree] = {
+ val arr = new Array[Tree]( buf.length );
+ var i = 0;
+ for (val x <- buf.elements) { arr(i) = x; i = i + 1; }
+ arr;
+ }
/** convenience method */
def convertToTypeId(t: Tree): Tree = t match {
@@ -159,16 +167,17 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS:
* @todo map: a map of attributes !!!
*/
- protected def mkXML(pos: int, isPattern: boolean, namespace: Tree, label: Tree, attrs: Array[Tree], children: Array[Tree]): Tree = {
+ protected def mkXML(pos: int, isPattern: boolean, namespace: Tree, label: Tree, attrs: Array[Tree], children: mutable.Buffer[Tree]): Tree = {
if( isPattern ) {
- val ts = new myTreeList();
+ val ts = new mutable.ArrayBuffer[Tree]();
ts.append( namespace );
ts.append( label );
ts.append( new Tree$Ident( Names.PATTERN_WILDCARD ) ); // attributes?
- ts.append( convertToTextPat( children ) );
+ convertToTextPat( children );
+ ts ++ children;
make.Apply(pos,
convertToTypeId( _scala_xml_Elem( pos ) ),
- ts.toArray())
+ bufferToArray( ts ))
} else {
val ab = new scala.collection.mutable.ArrayBuffer[Tree]();
ab + namespace;
@@ -183,7 +192,7 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS:
attrs);
if(( children.length ) > 0 )
ab + make.Typed(pos,
- makeXMLseq(pos, children ),
+ makeXMLseq( pos, children ),
make.Ident(pos, TypeNames.WILDCARD_STAR));
val arr:Array[Tree] = new Array[Tree]( ab.length );
ab.elements.copyToArray( arr, 0 );
@@ -199,7 +208,7 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS:
make.New( pos, constr );
};
// create scala.xml.Text here <: scala.xml.Node
- def makeText( pos: int, isPattern:Boolean, txt:String ):Tree = {
+ final def Text( pos: int, isPattern:Boolean, txt:String ):Tree = {
//makeText( pos, isPattern, gen.mkStringLit( pos, txt ));
val txt1 = gen.mkStringLit( pos, txt );
if( isPattern )
@@ -208,17 +217,6 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS:
makeText1( pos, txt1 );
}
- def appendTrimmed(pos: int, mode:Boolean, ts:myTreeList, txt:String) = {
- var textNodes =
- if( !preserveWS )
- new TextBuffer().append( txt ).toText;
- else
- List( Text( txt ));
-
- for( val t <- textNodes )
- ts.append( makeText( pos, mode, t.text ));
- }
-
// create scala.xml.Text here <: scala.xml.Node
/*
protected def makeText( pos: int, isPattern:Boolean, txt:Tree ):Tree = {
@@ -312,45 +310,40 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS:
}
/** @todo: attributes */
- def makeXMLpat(pos: int, n: String, args: Array[Tree]): Tree =
+ def makeXMLpat(pos: int, n: String, args: mutable.Buffer[Tree]): Tree =
mkXML(pos,
true,
new Tree$Ident( Names.PATTERN_WILDCARD ):Tree,
gen.mkStringLit( pos, n ):Tree,
- Tree.EMPTY_ARRAY:Array[Tree],
- args:Array[Tree]);
+ Predef.Array[Tree](),
+ args);
protected def convertToTextPat(t: Tree): Tree = t match {
case _:Tree$Literal => makeTextPat(t.pos, t);
case _ => t
}
- protected def convertToTextPat(ts: Array[Tree]): Array[Tree] = {
- var res:Array[Tree] = null;
- var i = 0; while( i < ts.length ) {
- val t1 = ts( i );
- val t2 = convertToTextPat( t1 );
- if (!t1.eq(t2)) {
- if( null == res ) { // lazy copy
- res = new Array[Tree]( ts.length );
- System.arraycopy( ts, 0, res, 0, i );
- }
- res( i ) = t2;
- }
- i = i + 1;
+ protected def convertToTextPat(buf: mutable.Buffer[Tree]): Unit = {
+ var i = 0; while( i < buf.length ) {
+ val t1 = buf( i );
+ val t2 = convertToTextPat( t1 );
+ if (!t1.eq(t2)) {
+ buf.remove(i);
+ buf.insert(i,t2);
+ }
+ i = i + 1;
}
- if( null == res ) ts else res;
}
def isEmptyText(t:Tree) = t match {
case Tree$Literal(atree.AConstant.STRING("")) => true;
case _ => false;
}
- def makeXMLseq( pos:int, args:Array[Tree] ) = {
+ def makeXMLseq( pos:int, args:mutable.Buffer[Tree] ) = {
val ts = new TreeList();
//val blocArr = new Array[Tree] ( 1 + args.length );
//val constr = _scala_collection_mutable_ArrayBuffer( pos );
- val _buffer = makeNodeBuffer( pos );
+ var _buffer = makeNodeBuffer( pos );
val n = p.fresh();
val nIdent = make.Ident(pos, n);
//blocArr( 0 )
@@ -358,18 +351,17 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS:
0, n, Tree.Empty,
_buffer));
- var i = 0; while( i < args.length ) {
- val ipos = args(i).pos;
- if( !isEmptyText( args( i ))) {
- ts.append(
- make.Apply( ipos,
- make.Select( ipos, nIdent, _plus /*_append*/ ),
- Predef.Array[Tree]( args( i ) ))
- )
+ val it = args.elements;
+ while( it.hasNext ) {
+ val t = it.next;
+ val tpos = t.pos;
+ if( !isEmptyText( t )) {
+ _buffer = make.Apply( tpos,
+ make.Select( tpos, _buffer, _plus ),
+ Predef.Array[Tree]( t ));
}
- i = i + 1;
}
- make.Block( pos, ts.toArray(), nIdent );
+ _buffer;//make.Block( pos, ts.toArray(), nIdent );
}
def makeXMLseqPat( pos:int, args:Array[Tree] ) = {
@@ -404,20 +396,24 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS:
}
/** makes an element */
- def makeXML(pos: int, label: String, attrMap1: ListMap[String,Tree], args: Array[Tree]): Tree={
- var setNS = ListMap.Empty[String, Tree];
- var attrMap = attrMap1;
-
- for( val z <- attrMap.keys; z.startsWith("xmlns") ) {
- val i = z.indexOf(':');
- if( i == -1 )
- setNS = setNS.update("default", attrMap( z ));
- else {
- val zz = z.substring( i+1, z.length() );
- setNS = setNS.update( zz, attrMap( z ));
+ def element(pos: int, label: String, attrMap: mutable.Map[String,AttribValue[Tree]], args: mutable.Buffer[Tree]): Tree = {
+ var setNS = new mutable.HashMap[String, Tree];
+ /* DEBUG */
+ val attrIt = attrMap.keys;
+ while( attrIt.hasNext ) {
+ val z = attrIt.next;
+ if( z.startsWith("xmlns") ) {
+ val i = z.indexOf(':');
+ if( i == -1 )
+ setNS.update("default", attrMap( z ).value );
+ else {
+ val zz = z.substring( i+1, z.length() );
+ setNS.update( zz, attrMap( z ).value );
+ }
+ attrMap -= z;
}
- attrMap = attrMap - z;
}
+ /* */
val i = label.indexOf(':');
val Pair( namespace, newlabel ) = qualified( pos, label );
@@ -426,15 +422,18 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS:
Tree.EMPTY_ARRAY
else {
val attrs:Array[Tree] = new Array[Tree](attrMap.size);
+ /* DEBUG */
var k = 0;
var it = attrMap.elements;
while( it.hasNext ) {
val ansk = it.next;
val Pair( ns, aname ) = qualifiedAttr( pos, namespace, ansk._1 );
- attrs( k ) = makeAttribute( pos, ns, aname, ansk._2 );
+ attrs( k ) = makeAttribute( pos, ns, aname, ansk._2.value );
k = k + 1;
}
+ /* */
attrs
+
}
var t = mkXML(pos,
@@ -442,7 +441,8 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS:
make.Ident(pos, Name.fromString(namespace)):Tree,
gen.mkStringLit(pos, newlabel):Tree,
attr:Array[Tree],
- args:Array[Tree]);
+ args);
+ /* DEBUG */
if( !setNS.isEmpty ) {
val nsStms = new Array[Tree]( setNS.size );
var i = 0;
@@ -451,8 +451,10 @@ class SymbolicXMLBuilder(make: TreeFactory, gen: TreeGen, p: Parser, preserveWS:
i = i + 1;
}
make.Block( pos, nsStms, t )
- } else
+ } else {
+ /* */
t
+ }
}
def setNamespacePrefix(pos:Int, pref:String, uri:Tree) =