【发布时间】:2019-08-13 20:33:10
【问题描述】:
我正在解析一个文件,并想丢弃我不感兴趣的文件中的某些行。我已经能够让它适用于所有情况,除了最后一行是一次性的并且确实不以换行符结尾。
我尝试构建一个endOfInput 规则并通过<|> 将它与skipLine 规则连接起来。这一切都包含在many 中。当我不尝试某种回溯时,调整所有我似乎要么得到“许多成功而不消耗输入......”错误或 skipLine 规则失败。
let skipLine = many (noneOf "\n") .>> newline |>> fun x -> [string x]
let endOfInput = many (noneOf "\n") .>> eof |>> fun x -> [string x]
test (many (skipLine <|> endOfInput)) "And here is the next.\nThen the last."
** 在最后一行的 skipLine 解析器上出现此错误
我试过了
let skipLine = many (noneOf "\n") .>>? newline |>> fun x -> [string x]
...和...
let skipLine = many (noneOf "\n") .>> newline |>> fun x -> [string x]
test (many (attempt skipLine <|> endOfInput)) "And here is the next.\nThen the last."
** 这些会产生很多错误
注意:输出函数只是让它们与我的其他规则一起使用的占位符。我还没有弄清楚如何格式化输出。 这是我第一次使用 FParsec,我是 F# 新手。
【问题讨论】: