首页 > 解决方案 > 使用 scala fastparse 删除封闭的转义引号但保留其他引号

问题描述

我想使用fastparse将以下字符串\"Escaped quote\"\"\"转换为Escaped quote\". 我有以下几乎可以工作的代码。

def escapedQuote[_: P]: P[Unit] = P("\"")
def unquotedColumn[_: P] = P(escapedQuote ~ ((!escapedQuote ~ AnyChar.!) | escapedQuote ~ escapedQuote.!).rep ~ escapedQuote ~ End)
val result = parse(input, unquotedColumn(_))

我得到的结果ArrayBuffer(E, s, c, a, p, e, d, , q, u, o, t, e, ")非常接近我想要的结果,但是我想要一个字符串中的结果。

但是,当我尝试以下操作时(在代表之后添加 .!),

def unquotedColumn[_: P] = P(escapedQuote ~ ((!escapedQuote ~ AnyChar.!) | escapedQuote ~ escapedQuote.!).rep.! ~ escapedQuote ~ End)

我得到了结果Escaped quote\"\"。出现了一个额外的转义引用。

我想unquotedColumn在其他解析器中使用我的。

任何想法如何修复我的代码?

标签: scalafastparse

解决方案


推荐阅读