From 2a3213562ed3e3393731670a764a51fb51fdee7c Mon Sep 17 00:00:00 2001 From: Kazutaka Matsuda Date: Wed, 21 Feb 2024 15:59:27 +0900 Subject: [PATCH] A field needs not end with a new line Added a function `skipToNextLineOrEOI` and changed `field` to call the function instead. This function may consume no inputs, and hence `many skipToNextLineOrEOI` can go to infinite loop. --- src/Hie/Cabal/Parser.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Hie/Cabal/Parser.hs b/src/Hie/Cabal/Parser.hs index fbedb31..9b51033 100644 --- a/src/Hie/Cabal/Parser.hs +++ b/src/Hie/Cabal/Parser.hs @@ -110,6 +110,10 @@ parseList i = many (nl <|> sl) skipToNextLine :: Parser () skipToNextLine = skipWhile (not . isEndOfLine) >> endOfLine +-- This function may consume no inputs; so 'many skipToNextLineOrEOI' may go into infinite loop. +skipToNextLineOrEOI :: Parser () +skipToNextLineOrEOI = skipWhile (not . isEndOfLine) >> (endOfInput <|> endOfLine) + comment :: Parser () comment = skipMany tabOrSpace >> "--" >> skipToNextLine @@ -133,7 +137,7 @@ field i f p = _ <- char ':' skipMany tabOrSpace p' <- p $ i' + 1 - skipToNextLine + skipToNextLineOrEOI pure p' -- | Skip at least n spaces