gpt4 book ai didi

Haskell 秒差距空间解析错误

转载 作者:行者123 更新时间:2023-12-02 14:21:41 25 4
gpt4 key购买 nike

我有

stringparse = mstring
<$> char '"'
<*> (many alphaNum <|> many space)
<*> char '"'
where mstring a b c = [a] ++ b ++ [c]

当我这样做的时候,

解析 stringparse """\"hello\" 我得到 正确的 "\"hello\""

当我这样做的时候,

解析 stringparse """\"\"" 我得到正确的 "\"\""

但是当我这样做时,

解析 stringparse """\"\""解析 stringparse """\"he llo\""

它不起作用。

我收到错误,

Left (line 1, column 2):
unexpected " "
expecting letter or digit or "\""

Left (line 1, column 4):
unexpected " "
expecting letter or digit or "\""

分别。

我不明白为什么代码不能正确解析空格。

最佳答案

因为你这样做many alphaNum <|> many spacemany接受 0 作为可接受的字符数,它总是成功。这与 * 的行为相同。在正则表达式中。

所以在 <|>它永远不会失败并调用正确的一方。所以你是说“尝试尽可能多的 alphaNum ,然后采取 "

你想要的是

many (alphaNum <|> space) 

换句话说,“尽可能多的 alphaNumspace ”。

关于Haskell 秒差距空间解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18777191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com