このパーサーを機能させたいと思います。現在、エラーがどこにあるのかよくわかりません。それは主に「あなたに計画を書く」のパーセクのセクションから取られています
もう1つの質問:それが最終的に機能する場合、疑問符で始まる文字列が常にリストの最後になるようにする方法はありますか?
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 }'