我试图运行以下FParsec
代码,直到某种原因它停止工作:
我得到的错误是
"The value is not a function and cannot be applied."
如果我注释掉最后一行代码(test ns ".."
),它不会产生错误。有关如何解决这个问题的想法吗?
文本形式的源代码如下:
open System
open FParsec
let test p str =
match run p str with
| Success(result, _, _) -> printfn "Success: %A" result
| Failure(errorMsg, _, _) -> printfn "Failure: %s" errorMsg
type Namespace = { Name : string; Classes : string list; }
let classes : Parser<string list, unit> =
many (spaces >>. many1Satisfy isLetter .>> spaces)
let ns =
pipe2
(spaces >>. skipString "namespace" >>. spaces >>. many1Satisfy isLetter)
(spaces >>. skipString "{" >>. classes .>> skipString "}")
(fun name classes -> { Name = name; Classes = classes } )
test ns "namespace abc { def ghi }"
答案 0 :(得分:4)
没有人可以在这里猜到答案。问题与我决定从帖子中排除的其他内容有关:我文件的标题:
#if INTERACTIVE
#r @"C:\Users\xyz\Desktop\fparsec-main-default\Build\VS10\bin\Debug\FParsecCS.dll";
#r @"C:\Users\xyz\Desktop\fparsec-main-default\Build\VS10\bin\Debug\FParsec.dll";
#endif
;
替换;;
会使所有错误消失:
#if INTERACTIVE
#r @"C:\Users\xyz\Desktop\fparsec-main-default\Build\VS10\bin\Debug\FParsecCS.dll";;
#r @"C:\Users\xyz\Desktop\fparsec-main-default\Build\VS10\bin\Debug\FParsec.dll";;
#endif
答案 1 :(得分:-1)
红色下划线清楚地表明编译器认为pipe2
正在采用四个参数 - 您应该能够通过围绕整个测试表达式添加括号来确认这一点:(test ns "namespace abs { def ghi })
我不确定为什么;尝试在pipe2调用周围添加括号:
let ns =
(pipe2
(spaces >>. skipString "namespace" >>. spaces >>. many1Satisfy isLetter)
(spaces >>. skipString "{" >>. classes .>> skipString "}")
(fun name classes -> { Name = name; Classes = classes } ))