【发布时间】:2016-11-03 02:43:31
【问题描述】:
鉴于以下
let maxCount = System.Int32.MaxValue
let pmlcomment = pstring "/*" >>. skipCharsTillString "*/" true (maxCount)
let ws = pspaces >>. many (pspaces >>. pmlcomment .>> pspaces) |>> (function | [] -> () | _ -> ())
let str_ws s = pstring s .>> ws
let exprBraceSeqOpt p =
let trailingComma = (str_ws "," |>> fun _ -> None )
between (str_ws "{") (str_ws "}") ((opt (attempt (sepBy p (str_ws ",")))) <|> (attempt trailingComma))
let sampleP = exprBraceSeqOpt (str_ws "x")
它正确匹配除了最后一个之外的所有以下内容:
["{}";"{x}";"{x,x}";"{x,x,}"]
我猜有些东西正在改变状态或其他东西。
如何处理 fparsec 中的可选尾随逗号?
【问题讨论】:
-
应该是
opt (attempt trailingComma)? -
不,不会编译