diff options
author | buraq <buraq@epfl.ch> | 2004-09-30 10:02:13 +0000 |
---|---|---|
committer | buraq <buraq@epfl.ch> | 2004-09-30 10:02:13 +0000 |
commit | 3dd173c8ed966f80ab988b46174753ad8fe7e577 (patch) | |
tree | 052c58d030af507154a4b525585e8f15d824aeae | |
parent | 88ad9751203d0945244fd65e5eb56b1286272a8d (diff) | |
download | scala-3dd173c8ed966f80ab988b46174753ad8fe7e577.tar.gz scala-3dd173c8ed966f80ab988b46174753ad8fe7e577.tar.bz2 scala-3dd173c8ed966f80ab988b46174753ad8fe7e577.zip |
better error message for xml parsing
-rw-r--r-- | sources/scala/tools/scalac/ast/parser/MarkupParser.scala | 25 | ||||
-rw-r--r-- | sources/scala/tools/scalac/ast/parser/Scanner.scala | 2 |
2 files changed, 23 insertions, 4 deletions
diff --git a/sources/scala/tools/scalac/ast/parser/MarkupParser.scala b/sources/scala/tools/scalac/ast/parser/MarkupParser.scala index 9dc8b6d8c9..65f5f21b89 100644 --- a/sources/scala/tools/scalac/ast/parser/MarkupParser.scala +++ b/sources/scala/tools/scalac/ast/parser/MarkupParser.scala @@ -55,6 +55,8 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, presWS: boolean reportSyntaxError("'" + that + "' expected instead of '" + ch + "'"); } + var debugLastStartElement = new mutable.Stack[Pair[Int,String]]; + /** checks whether next character starts a Scala block, if yes, skip it. * @return true if next character starts a scala block */ @@ -288,7 +290,7 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, presWS: boolean * | xmlTag1 '/' '>' */ /*[Duplicate]*/ def element: Tree = { - var pos1 = pos; + val pos1 = pos; val Tuple2(qname, attrMap) = xTag; if(ch == '/') { // empty element xToken('/'); @@ -296,8 +298,10 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, presWS: boolean handle.element( pos1, qname, attrMap, new mutable.ListBuffer[Tree] ); } else { // handle content xToken('>'); + debugLastStartElement.push(Pair(pos1,qname)); val ts = content; xEndTag( qname ); + debugLastStartElement.pop; handle.element( pos1, qname, attrMap, ts ); } } @@ -401,7 +405,7 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, presWS: boolean * @return Scala representation of this xml literal * precondition: s.xStartsXML == true */ - def xLiteral: Tree = { + def xLiteral: Tree = try { init; handle.isPattern = false; val pos = s.pos; @@ -418,13 +422,19 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, presWS: boolean //Console.println("out of xLiteral, parsed:"+tree.toString()); s.xSync2; tree + } catch { + case _:ArrayIndexOutOfBoundsException => + s.syntaxError(debugLastStartElement.top._1, + "missing end tag in XML literal for <" + +debugLastStartElement.top._2+">"); + Tree.Empty; } /** @see xmlPattern. resynchronizes after succesful parse * @return this xml pattern * precondition: s.xStartsXML == true */ - def xLiteralPattern:Tree = { + def xLiteralPattern:Tree = try { init; val oldMode = handle.isPattern; handle.isPattern = true; @@ -443,6 +453,12 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, presWS: boolean //Console.println("out of xLiteralPattern, parsed:"+tree.toString()); s.xSync2; tree + }catch { + case _:ArrayIndexOutOfBoundsException => + s.syntaxError(debugLastStartElement.top._1, + "missing end tag in XML literal for <" + +debugLastStartElement.top._2+">"); + Tree.Empty; } def xEmbeddedExpr:Tree = { @@ -475,6 +491,7 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, presWS: boolean def init: Unit = { ch = s.ch; + pos = s.pos; //Console.println("\ninit! ch = "+ch); } @@ -532,6 +549,7 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, presWS: boolean //Console.println("xPattern"); val pos1 = pos; val qname = xName; + debugLastStartElement.push(Pair(pos1,qname)); xSpaceOpt; if( ch == '/' ) { // empty tag nextch; @@ -571,6 +589,7 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, presWS: boolean } } xEndTag( qname ); + debugLastStartElement.pop; handle.makeXMLpat( pos1, qname, ts ); } diff --git a/sources/scala/tools/scalac/ast/parser/Scanner.scala b/sources/scala/tools/scalac/ast/parser/Scanner.scala index 370866d947..5318bdbc12 100644 --- a/sources/scala/tools/scalac/ast/parser/Scanner.scala +++ b/sources/scala/tools/scalac/ast/parser/Scanner.scala @@ -916,7 +916,7 @@ class Scanner(_unit: CompilationUnit) extends TokenData { ch = srcIterator.raw; ccol = ccol + 1; // = nextch() without unicode ch match { case SU => - syntaxError( lastpos, "unclosed XML literal" ); + //syntaxError( lastpos, "missing end tag in XML literal" ); token = EOF; case LF => ccol = 0; cline = cline + 1; |