summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2004-02-13 15:26:21 +0000
committerburaq <buraq@epfl.ch>2004-02-13 15:26:21 +0000
commit14ea14e71b63cc590f312246146c42da4fe94e94 (patch)
tree61c3a053e0079e6887292daad3fdcee374eea82f /sources
parent1da04b88fc7ab66535be9542398c0d0b4a077cc1 (diff)
downloadscala-14ea14e71b63cc590f312246146c42da4fe94e94.tar.gz
scala-14ea14e71b63cc590f312246146c42da4fe94e94.tar.bz2
scala-14ea14e71b63cc590f312246146c42da4fe94e94.zip
xml literals with embedded scala blocks
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/tools/scalac/ast/parser/Parser.scala39
-rw-r--r--sources/scala/tools/scalac/ast/parser/Scanner.scala8
2 files changed, 30 insertions, 17 deletions
diff --git a/sources/scala/tools/scalac/ast/parser/Parser.scala b/sources/scala/tools/scalac/ast/parser/Parser.scala
index 97c19417a2..68d2f09724 100644
--- a/sources/scala/tools/scalac/ast/parser/Parser.scala
+++ b/sources/scala/tools/scalac/ast/parser/Parser.scala
@@ -25,7 +25,7 @@ package scala.tools.scalac.ast.parser {
/** A recursive descent parser for the programming language Scala.
*
* @author Martin Odersky, Matthias Zenger, Burak Emir
- * @version 1.2
+ * @version 1.3
*/
class Parser(unit: Unit) {
@@ -1041,21 +1041,20 @@ class Parser(unit: Unit) {
null;//dummy
}
- /** xmlExpr ::= '<' ident '>' { xmlExpr | '{' simpleExpr '}' } '<''/'ident'>'
+ /** '<' xmlExpr ::= STag { xmlExpr | '{' simpleExpr '}' } ETag
+ ** '<' xmlExpr ::= EmptyElemTag
*/
def xmlExpr():Tree = {
val pos = s.pos;
-
var empty = false;
- /* [40] STag ::= '<' Name (S Attribute)* S? '>'
+ /* [40] STag ::= '<' Name (S Attribute)* S? '>'
+ * [41] Attribute ::= Name Eq AttValue
+ * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
*/
val elemName = s.xmlName();
s.xmlSpaceOpt();
var attrMap = ListMap.Empty[Name,String];
- /* [41] Attribute ::= Name Eq AttValue
- * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
- */
while(( s.ch != '>' )&&( !empty )) {
if( s.ch == '/' ) {
s.nextch();
@@ -1085,18 +1084,18 @@ class Parser(unit: Unit) {
}
}
s.xmlToken('>');
- /* Console.println("startTag of:"+elemName); */
+ /* Console.println("startTag of:"+elemName);*/
s.xmlSpaceOpt();
if( empty ) {
makeXML( pos, elemName, Tree.EMPTY_ARRAY );
- } else {
+ } else { /* possible XML content: */
val ts = new myTreeList();
-
var exit = false;
while( !exit ) {
+ /* Console.println("read '"+s.ch.asInstanceOf[char]+"'"); */
s.ch match {
- case '<' => {
+ case '<' => { /* tag */
s.nextch();
if( s.ch != '/' ) { /* search end tag */
ts.append( xmlExpr() );
@@ -1104,7 +1103,21 @@ class Parser(unit: Unit) {
exit = true
}
}
- case _ => {
+ case '{' => { /* Scala block */
+ while( s.ch == '{' ) {
+ s.nextToken();
+ /* Console.println("{"); */
+ s.nextToken();
+ val bs = new myTreeList();
+ val b = block( s.pos );
+ if( s.token != RBRACE ) {
+ s.xml_syntaxError(" expected end of Scala block");
+ }
+ /* Console.println("}"); */
+ ts.append( b );
+ }
+ }
+ case _ => { /* text */
val pos = s.pos;
val str = s.xmlText();/* text node */
ts.append( gen.mkStringLit( pos, str ));
@@ -1113,7 +1126,7 @@ class Parser(unit: Unit) {
}
}
- /* [42] ETag ::= '</' Name S? '>' */
+ /* [42] ETag ::= '</' Name S? '>' */
s.xmlToken('/');
if( elemName != s.xmlName() )
s.xml_syntaxError("expected closing tag of "+elemName);
diff --git a/sources/scala/tools/scalac/ast/parser/Scanner.scala b/sources/scala/tools/scalac/ast/parser/Scanner.scala
index 6ef2524554..454ad6683b 100644
--- a/sources/scala/tools/scalac/ast/parser/Scanner.scala
+++ b/sources/scala/tools/scalac/ast/parser/Scanner.scala
@@ -18,8 +18,8 @@ import ch.epfl.lamp.util.SourceFile;
/** A scanner for the programming language Scala.
*
- * @author Matthias Zenger, Martin Odersky
- * @version 1.0
+ * @author Matthias Zenger, Martin Odersky, Burak Emir
+ * @version 1.1
*/
class Scanner(_unit: Unit) extends TokenData {
@@ -661,7 +661,7 @@ class Scanner(_unit: Unit) extends TokenData {
def xml_syntaxError(s:String) = {
syntaxError("in XML literal: "+s);
- xml_nextch();
+ nextch();
}
/* this helper functions updates ccol and cline, only necessary in whitespace
@@ -757,7 +757,7 @@ class Scanner(_unit: Unit) extends TokenData {
val index = bp;
while ( ch != endch ) {
if(( ch == '<' )||( ch == '&' ))
- syntaxError(ch.asInstanceOf[char]+" not allowed here");
+ xml_syntaxError(ch.asInstanceOf[char]+" not allowed here");
xml_nextch();
};
pos = Position.encode(cline, ccol);