@@ -36,7 +36,7 @@ import Effect.Console (log, logShow)
36
36
import Effect.Unsafe (unsafePerformEffect )
37
37
import Node.Process (lookupEnv )
38
38
import 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 , (<?>), (<??>), (<~?>))
40
40
import Parsing.Combinators.Array as Combinators.Array
41
41
import Parsing.Expr (Assoc (..), Operator (..), buildExprParser )
42
42
import Parsing.Language (haskellDef , haskellStyle , javaStyle )
@@ -572,6 +572,15 @@ javaStyleTest = do
572
572
" hello {- comment\n -} foo"
573
573
(mkPos 7 )
574
574
575
+ takeWhilePropagateFail :: TestM
576
+ takeWhilePropagateFail = do
577
+ -- `takeWhile` always succeeds, but if input was consumed prior and failure happens
578
+ -- later, then the failure with consumption should propagate past `optional` #236
579
+ parseErrorTestPosition
580
+ (optional $ (char ' f' <* takeWhile (const false ) <* fail " failure" ))
581
+ " f"
582
+ (Position { index: 1 , line: 1 , column: 2 })
583
+
575
584
main :: Effect Unit
576
585
main = do
577
586
@@ -734,6 +743,8 @@ main = do
734
743
, expected: Left $ ParseError " Expected letter" (Position { index: 0 , line: 1 , column: 1 })
735
744
}
736
745
746
+ takeWhilePropagateFail
747
+
737
748
log " \n TESTS number\n "
738
749
739
750
-- assert' "Number.fromString" $ Just infinity == Data.Number.fromString "Infinity"
0 commit comments