【发布时间】:2018-12-06 16:23:07
【问题描述】:
我正在尝试使用 FParsec 解析箭头类型。 也就是这个:
Int -> Int -> Int -> Float -> Char
例如。
我尝试使用此代码,但它仅适用于一种类型的箭头 (Int -> Int),不再适用。我也想避免使用括号,因为我已经有一个使用它们的元组类型,而且我也不希望它在语法方面太重。
let ws = pspaces >>. many pspaces |>> (fun _ -> ())
let str_ws s = pstring s .>> ws
type Type = ArrowType of Type * Type
let arrowtype' =
pipe2
(ws >>. ty')
(ws >>. str_ws "->" >>. ws >>. ty')
(fun t1 t2 -> ArrowType(t1, t2))
let arrowtype =
pipe2
(ws >>. ty' <|> arrowtype')
(ws >>. str_ws "->" >>. ws >>. ty' <|> arrowtype')
(fun t1 t2 -> ArrowType(t1, t2)) <?> "arrow type"
ty' 只是另一种类型,例如元组或标识符。
你有解决办法吗?
【问题讨论】: