Closed Handora closed 6 years ago
I have no idea why the below question will introduce infinite loop problems.
The code is based on Haskell Attoparsec, and when I use parseOnly pString "v", it gives me the right answer as Right (DontNeedTrim, "v").
Haskell Attoparsec
parseOnly pString "v"
Right (DontNeedTrim, "v")
While when I use the instruction parseOnly (many' pString) "v", it seems drops into the infinite loop and finally failed with the overflowed stack.
parseOnly (many' pString) "v"
infinite loop
data Signal = NeedTrim | DontNeedTrim deriving (Show) pString :: Parser (Signal, [Char]) pString = ((char '\"' *> many' pChar' <* char '\"') >>= \s -> return (NeedTrim, s)) <|> (many' pChar >>= \s -> return (DontNeedTrim, s)) pChar :: Parser Char pChar = char '\\' *> (pEscape <|> spaces *> endOfLine *> pChar) <|> satisfy (`C.notElem` "\"\\\n#;") pChar' :: Parser Char pChar' = char '\\' *> pEscape <|> satisfy (`C.notElem` "\\\"") pEscape :: Parser Char pEscape = choice (zipWith decode "bnt\\\"" "\b\n\t\\\"") where decode c r = r <$ char c
Sorry, I found that (many' pChar >>= \s -> return (DontNeedTrim, s)) can cause it to consume empty string forever
(many' pChar >>= \s -> return (DontNeedTrim, s))
I have no idea why the below question will introduce infinite loop problems.
The code is based on
Haskell Attoparsec
, and when I useparseOnly pString "v"
, it gives me the right answer asRight (DontNeedTrim, "v")
.While when I use the instruction
parseOnly (many' pString) "v"
, it seems drops into theinfinite loop
and finally failed with the overflowed stack.