Your parser works. You just need to catch the result instead of sending it to println. 'A' is matched, but 'B' is not (since '\z'='end of input' was expected) which makes the whole match unsuccessful.
import scala.util.parsing.combinator.JavaTokenParsers
object MainTest extends JavaTokenParsers {
def line: Parser[String] = "A"
def main: Unit = {
val result = parseAll(line, """AB""".stripMargin)
if(result.successful) println("OK")
else println("NOT ok")
}
}
Note:
def line = "A*B"
matches only "A*B"
def line = "A*B".r
is a regexp for n>=0 repetitions of 'A' followed with 'B'