嘗試解析像GroupParser.parse(「{{a} {{c} {d}}}」的嵌套表達式「) 很多小時後,我現在有下面的snipplet解析{a} ,但失敗scala使用嵌套parens解析
[1.5] failure: ``}'' expected but `{' found
{{a}{{b}{c}}}
^
sealed abstract class Expr
case class ValueNode(value:String) extends Expr
object GroupParser extends StandardTokenParsers {
lexical.delimiters ++= List("{","}")
def vstring = ident ^^ { case s => ValueNode(s) }
def expr = (vstring | parens)
def parens:Parser[Expr] = "{" ~> expr <~ "}"
def parse(s:String) = {
val tokens = new lexical.Scanner(s)
phrase(expr)(tokens)
}
}
任何提示?
貴的問題得到解答? – 2011-02-18 17:08:09