Scala 存在词法解析问题;或假

问题描述 投票:0回答:1

你好,我有一个公式

child(1);false 我正在尝试解析它。我尝试了几种变体,但不知怎的,它们都不起作用

"child" ~ "(" ~> numericLit <~ ");false" ^^
"child" ~ "(" ~> numericLit <~ ")" ~ ";false" ^^
"child" ~ "(" ~> numericLit <~ ")" ~ ";" ~ "false" ^^

如果我尝试匹配 child(1) 它可以工作,但是一旦我尝试使用 child(1);false 我就会从解析器中得到错误

end of input expected

这是从内置解析器函数返回的,如下所示

  def phrase[T](p: Parser[T]) = new Parser[T] {
    def apply(in: Input) = p(in) match {
      case s @ Success(out, in1) =>
        if (in1.atEnd) s
        else Failure("end of input expected", in1)
      case ns => ns
    }
  }

我很不知道该怎么做,希望得到帮助

scala parsing lexical
1个回答
0
投票
        val childArgument = Argument(Right("child"), Some(Argument(Left(a._1._1.toInt), None)))
        val optionalArgument = if (a._2.nonEmpty) {
          Some(Argument(Left(if (a._2.get._2) 1 else 0), None))
        } else
          None
        if (optionalArgument.nonEmpty) {
          List(childArgument, optionalArgument.get)
        } else {
          List(childArgument)
        }
      }
    ```

def booleanLit: 解析器[布尔] = “真” ^^ { _ => 真 } | “假”^^ { _ => 假}


this is how it was solved. there were three cases child(1), child(1);false and child(1);true
© www.soinside.com 2019 - 2024. All rights reserved.