@@ -36,7 +36,7 @@ import Effect.Console (log, logShow)
3636import  Effect.Unsafe  (unsafePerformEffect )
3737import  Node.Process  (lookupEnv )
3838import  Parsing  (ParseError (..), ParseState (..), Parser , ParserT , Position (..), consume , fail , getParserT , initialPos , parseErrorPosition , position , region , runParser )
39- import  Parsing.Combinators  (advance , between , chainl , chainl1 , chainr , chainr1 , choice , empty , endBy , endBy1 , lookAhead , many , many1 , many1Till , many1Till_ , manyIndex , manyTill , manyTill_ , notFollowedBy , optionMaybe , replicateA , sepBy , sepBy1 , sepEndBy , sepEndBy1 , skipMany , skipMany1 , try , tryRethrow , (<?>), (<??>), (<~?>))
39+ import  Parsing.Combinators  (advance , between , chainl , chainl1 , chainr , chainr1 , choice , empty , endBy , endBy1 , lookAhead , many , many1 , many1Till , many1Till_ , manyIndex , manyTill , manyTill_ , notFollowedBy , optional ,  optionMaybe , replicateA , sepBy , sepBy1 , sepEndBy , sepEndBy1 , skipMany , skipMany1 , try , tryRethrow , (<?>), (<??>), (<~?>))
4040import  Parsing.Combinators.Array  as  Combinators.Array 
4141import  Parsing.Expr  (Assoc (..), Operator (..), buildExprParser )
4242import  Parsing.Language  (haskellDef , haskellStyle , javaStyle )
@@ -572,6 +572,15 @@ javaStyleTest = do
572572    " hello {- comment\n  -} foo" 
573573    (mkPos 7  )
574574
575+ takeWhilePropagatFail  ::  TestM 
576+ takeWhilePropagatFail = do 
577+   --  `takeWhile` always succeeds, but if input was consumed prior and failure happens
578+   --  later, then failure with consumption should propagate past `optional` #236
579+   parseErrorTestPosition
580+     (optional $ (char ' f'   <* takeWhile CodePoint.Unicode .isSpace <* fail " failure"  ))
581+     " f" 
582+     (Position  { index: 1  , line: 1  , column: 2   })
583+ 
575584main  ::  Effect  Unit 
576585main = do 
577586
@@ -734,6 +743,8 @@ main = do
734743    , expected: Left  $ ParseError  " Expected letter"   (Position  { index: 0  , line: 1  , column: 1   })
735744    }
736745
746+   takeWhilePropagatFail
747+ 
737748  log " \n TESTS number\n " 
738749
739750  --  assert' "Number.fromString" $ Just infinity == Data.Number.fromString "Infinity"
0 commit comments