이 파서가 작동하도록하고 싶습니다. 나는 현재 오류가 어디에 있는지 잘 모르겠습니다. 주로 "당신에게 계획을 씁니다"의 Parsec 섹션에서 가져옵니다.내 parsec 파서에 문제가 있습니까?
질문이 하나 더 있습니다 : 결국 작동하지만 물음표로 시작하는 문자열이 항상 목록의 마지막임을 보장 할 수있는 방법이 있습니까? ?
input_text :: String
input_text = "Eval (isFib::, 1000, ?BOOL)"
data LTuple
= Command [LTuple]
| Number Integer
| String String
| Query Bool
deriving (Eq, Ord, Show)
data Command = Rd | Read | In | Take | Wr | Out | Eval
deriving (Eq, Ord, Show)
main :: IO()
main = do
case parse lindaCmd "example" input_text of
Left err -> print err
Right res -> putStrLn $ "I parsed: '" ++ res ++ "'"
parseList :: Parser lindaTpl
parseList = liftM Command $ sepBy1 lindaCmd (symbol ",")
lindaCmd = string "rd"
<|> string "take"
<|> string "out"
<|> string "eval"
<|> do char '('
x <- try parseList
char ')'return x
현재 오류 메시지는 다음과 같습니다
test.hs:30:48:
Couldn't match expected type `ParsecT s0 u0 m0 sep0'
with actual type `String -> ParsecT s1 u1 m1 String'
In the return type of a call of `symbol'
Probable cause: `symbol' is applied to too few arguments
In the second argument of `sepBy1', namely `(symbol ",")'
In the second argument of `($)', namely
`sepBy1 lindaCmd (symbol ",")'
test.hs:38:17:
The function `char' is applied to three arguments,
but its type `Char -> ParsecT s0 u0 m0 Char' has only one
In a stmt of a 'do' block: char ')' return x
In the second argument of `(<|>)', namely
`do { char '(';
x <- try parseList;
char ')' return x }'
In the second argument of `(<|>)', namely
`string "eval"
<|>
do { char '(';
x <- try parseList;
char ')' return x }'
입니다. 'return x'는 모두 한 줄에 표시됩니다. 'lindaCmd'의 끝. – huon