From 7def23284d740060ab6b61719af5cfa33623a720 Mon Sep 17 00:00:00 2001 From: Joscha Date: Wed, 20 Nov 2019 20:46:12 +0000 Subject: [PATCH] Fix labels not being applied when they should --- src/Mima/Parse/Common.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Mima/Parse/Common.hs b/src/Mima/Parse/Common.hs index 3943306..10b0be0 100644 --- a/src/Mima/Parse/Common.hs +++ b/src/Mima/Parse/Common.hs @@ -157,9 +157,12 @@ fixedWidthDec = fixedWidthWithExponent 10 decDigit fixedWidthHex :: (Num a) => Int -> Parser a fixedWidthHex = fixedWidthWithExponent 16 hexDigit +-- The 'try' below is necessary for the label to take effect if the parser +-- succeeds but the value is out of bounds. In that case, the do-block has +-- usually already consumed input, so the label wouldn't take effect. asBoundedValue :: (Show a, Ord a) => a -> a -> Parser a -> Parser a asBoundedValue lower upper parser = - label ("value within bounds " ++ show (lower, upper)) $ do + label ("value within bounds " ++ show (lower, upper)) $ try $ do value <- parser if lower <= value && value <= upper then pure value