Skip to content

Commit

Permalink
Ensure EOF after compilationUnit, otherwise give correct exception
Browse files Browse the repository at this point in the history
  • Loading branch information
mdr committed Feb 6, 2011
1 parent a26c151 commit 176558b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Expand Up @@ -1693,7 +1693,9 @@ class ScalaParser(tokens: Array[Token]) {
StatSeq(selfReferenceOpt = None, firstStatOpt = None, otherStats = otherStats)
}
}
CompilationUnit(topstats())
val topStats_ = topstats()
accept(EOF)
CompilationUnit(topStats_)
}

private def xmlStartTag(isPattern: Boolean): XmlStartTag = {
Expand Down
11 changes: 7 additions & 4 deletions scalariform/src/test/scala/scalariform/parser/ParserTest.scala
Expand Up @@ -17,13 +17,16 @@ class ParserTest extends FlatSpec with ShouldMatchers {
evaluating { parseExpression("a match { }") } should produce[ScalaParserException]
}

"Parser" should "produce a parse exception on a trailing close brace" in {
evaluating { parseCompilationUnit("class A{}}") } should produce[ScalaParserException]
}

"Parser" should "not throw an exception" in {
parseExpression("{ case List[String]() => 12 }")
}

private def parseExpression(s: String) = {
val (_, tokens) = ScalaLexer.tokeniseFull(s)
new ScalaParser(tokens.toArray).expr
}
private def parser(s: String) = new ScalaParser(ScalaLexer.tokeniseFull(s)._2.toArray)
private def parseExpression(s: String) = parser(s).expr
private def parseCompilationUnit(s: String) = parser(s).compilationUnit

}

0 comments on commit 176558b

Please sign in to comment.