3

我试图运行以下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 }"
4

2 回答 2

4

Noone could have guessed the answer here. The problem lied with other thing that I had decided to exclude from the post: the very header of my file:

#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

Replacing the ; by ;; will make all errors disappear:

#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
于 2011-08-24T19:55:28.230 回答
-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 } ))
于 2011-08-24T18:57:45.623 回答