Scala解析器卡在无限循环中

时间:2012-07-27 12:44:32

标签: scala parser-combinators

我正在尝试在scala中编写一个简单的解析器,但是当我添加一个重复的令牌时,Scala似乎陷入无限循环......

object RewriteRuleParsers extends RegexParsers {
  private def space = regex(new Regex("[ \\n]+"))
  private def number = regex(new Regex("[0-9]+")) 
  private def equals = (space?)~"="~(space?)
  private def word   = regex(new Regex("[a-zA-Z][a-zA-Z0-9-]*")) 
  private def string = regex(new Regex("[0-9]+")) >> { len => ":" ~> regex(new Regex(".{" + len + "}")) }  

  private def matchTokenPartContent: Parser[Any] = (space?)~word~equals~word<~ space?  
  private def matchTokenPart: Parser[Any] = ((space?) ~> "{" ~> matchTokenPartContent <~ "}"<~ space?)  
  private def matchTokenParts = (matchTokenPart *)  
  private def matchToken: Parser[Any] = ("[" ~> matchTokenParts ~ "]")

  def parseMatchToken(str: String): ParseResult[Any] = parse(matchToken, str)
}

以及调用它的代码

val parseResult = RewriteRuleParsers.parseMatchToken("[{tag=hello}]")

感谢任何建议

0 个答案:

没有答案