我寫了與fail
意圖-ing上的空白以下解析器:理解`not`在解析器組合
import scala.util.parsing.combinator._
object Foo extends JavaTokenParsers {
val wsTest = not(whiteSpace) // uses whitespace inherited from `RegexParsers`
}
爲什麼解析一堆空白的全成?
scala> Foo.parseAll(Foo.wsTest, " ")
res5: Foo.ParseResult[Unit] = [1.11] parsed:()
scala> res5.successful
res6: Boolean = true
從project望着Parsers#not
,我會一直期待我的上述測試Failure
。
/** Wrap a parser so that its failures and errors become success and
* vice versa -- it never consumes any input.
*/
def not[T](p: => Parser[T]): Parser[Unit] = Parser { in =>
p(in) match {
case Success(_, _) => Failure("Expected failure", in)
case _ => Success((), in)
}
}
'不'正常工作。我的猜測是解析器默認跳過空格,你必須禁用它。也許這有助於:http://stackoverflow.com/questions/3564094/parsing-a-blank-whitespace-with-regexparsers – Kigyo 2014-09-01 16:27:46
'我的猜測是,解析器跳過默認空白' - 我已經觀察到這種行爲與類擴展'JavaTokenParsers'。但是,我不希望'Foo.parseAll(Foo.wsTest,「」)'成功。 – 2014-09-01 17:32:46