mirror of
https://github.com/github/semantic.git
synced 2024-12-01 09:15:01 +03:00
Use maybeM in Data.Scientific.Exts to fail parsing.
This commit is contained in:
parent
812adece0f
commit
3e3f21c1d7
@ -3,16 +3,15 @@ module Data.Scientific.Exts
|
|||||||
, parseScientific
|
, parseScientific
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Prelude hiding (filter, null, takeWhile)
|
|
||||||
|
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
import Control.Monad
|
import Control.Monad hiding (fail)
|
||||||
import Data.Attoparsec.ByteString.Char8
|
import Data.Attoparsec.ByteString.Char8
|
||||||
import Data.ByteString.Char8 hiding (readInt, takeWhile)
|
import Data.ByteString.Char8 hiding (readInt, takeWhile)
|
||||||
import Data.Char (isOctDigit)
|
import Data.Char (isOctDigit)
|
||||||
import Data.Scientific
|
import Data.Scientific
|
||||||
import Data.Semigroup
|
|
||||||
import Numeric
|
import Numeric
|
||||||
|
import Prelude hiding (fail, filter, null, takeWhile)
|
||||||
|
import Prologue hiding (null)
|
||||||
import Text.Read (readMaybe)
|
import Text.Read (readMaybe)
|
||||||
|
|
||||||
parseScientific :: ByteString -> Either String Scientific
|
parseScientific :: ByteString -> Either String Scientific
|
||||||
@ -38,9 +37,9 @@ parser = signed (choice [hex, oct, bin, dec]) where
|
|||||||
-- The ending stanza. Note the explicit endOfInput call to ensure we haven't left any dangling input.
|
-- The ending stanza. Note the explicit endOfInput call to ensure we haven't left any dangling input.
|
||||||
done = skipWhile (inClass "iIjJlL") *> endOfInput
|
done = skipWhile (inClass "iIjJlL") *> endOfInput
|
||||||
|
|
||||||
-- Wrapper around readMaybe. Analogous to maybeFail in the Prologue, but no need to pull that in.
|
-- Wrapper around readMaybe.
|
||||||
attempt :: Read a => String -> Parser a
|
attempt :: Read a => String -> Parser a
|
||||||
attempt str = maybe (fail ("No parse: " <> str)) pure (readMaybe str)
|
attempt str = maybeM (fail ("No parse: " <> str)) (readMaybe str)
|
||||||
|
|
||||||
-- Parse a hex value, leaning on the parser provided by Attoparsec.
|
-- Parse a hex value, leaning on the parser provided by Attoparsec.
|
||||||
hex = fromIntegral <$> (string "0x" *> hexadecimal @Integer)
|
hex = fromIntegral <$> (string "0x" *> hexadecimal @Integer)
|
||||||
|
Loading…
Reference in New Issue
Block a user