随着代码的爆炸,我可以使用< *绑定两个解析器,但它只返回第一个结果。
如何绑定解析器并获取结果列表?
我现在得到的结果是
*Main> parserAll "111|"
Right (Str "111")
*Main> parserAll "111"
Left "123" (line 1, column 4):
unexpected end of input
expecting letter, digit, white space or "|"
我希望得到的结果是
*Main> parserAll "111|"
Right [(Str "111"),(Str "|")]
或
*Main> parserAll "111|"
Left "123" (line 1, column 4):
[Right (Str "111"),Right (Str "|")]
代码======
data SimpleExpr = Num Integer
| Var String
| Add SimpleExpr SimpleExpr
| Parens SimpleExpr
| Str [Char]
deriving (Eq,Show)
arser4search:: Parser SimpleExpr
parser4search = do
spaces
searchStr <- many1 (choice [letter,digit])
spaces
return (Str searchStr)
--if searchStr ==[]
-- then return (Num 0)
-- else return (Num (read searchStr))
parserSeparator:: Parser SimpleExpr
parserSeparator = do
spaces
tStr <- (char '|')
spaces
return (Str [tStr])
parseBuilder = parser4search <* parserSeparator
parserAll s = parse parseBuilder "123" s