We have a multi-threaded RPC server that parses input strings. We encountered a problem when the Scala library is not multithreaded security: var lastNoSuccess in Parsers.scala is used for any parsing, We get a NullPointerException on this line
if (!(lastNoSuccess != null && next.pos < lastNoSuccess.next.pos))
By default, to implement the parser, an object is created that extends one of the Parsers, but I want to build a parser on demand, so each of them has its own internal state, so I use a class instead of an object. However, I can not compile it, since I need to match the correspondence according to the result:
import scala.util.parsing.combinator.RegexParsers
class SqlParserImpl
extends RegexParsers
{
val term: Parser[String] = """(?i)term\b""".r
}
object Test
{
def main(args: Array[String]): Unit =
{
val parser = new SqlParserImpl
parser.parseAll(parser.term, "term") match {
case SqlParserImpl
case SqlParserImpl
}
}
}
Crash with
t.scala:16: error: '=>' expected but '#' found.
case SqlParserImpl
^
t.scala:17: error: '=>' expected but '#' found.
case SqlParserImpl
^
two errors found