Use new errorParser
and <:>
functions.
This commit is contained in:
parent
8d3ecb1c14
commit
8f16222114
@ -4,7 +4,6 @@ import Prelude
|
||||
|
||||
import Control.Alt ((<|>))
|
||||
import Data.Either (Either(..))
|
||||
import Data.String.CodeUnits as CU
|
||||
import Data.Maybe (Maybe(..))
|
||||
import Data.Validation.Semigroup (V, invalid, toEither)
|
||||
|
||||
@ -32,12 +31,13 @@ parse (G.Parser p) str c = case p { string: str, position: 0 } of
|
||||
|
||||
login_parser :: G.Parser LoginParsingError String
|
||||
login_parser = do
|
||||
l <- G.many1 (alpha <|> digit) <|> G.Parser \i -> G.failureError i.position (Just CannotParse)
|
||||
_ <- SomeParsers.eof <|> G.Parser \i -> G.failureError i.position (Just CannotEntirelyParse)
|
||||
input <- G.current_input
|
||||
_ <- G.many1 (alpha <|> digit) G.<:> \_ -> CannotParse
|
||||
_ <- SomeParsers.eof G.<:> \_ -> CannotEntirelyParse
|
||||
pos <- G.current_position
|
||||
if pos < min_login_size || pos > max_login_size
|
||||
then G.Parser \i -> G.failureError i.position (Just $ Size min_login_size max_login_size pos)
|
||||
else pure $ CU.fromCharArray l
|
||||
if between min_login_size max_login_size pos
|
||||
then pure input.string
|
||||
else G.errorParser (Just $ Size min_login_size max_login_size pos)
|
||||
|
||||
login :: String -> Either (Array Error) String
|
||||
login s = toEither $ parse login_parser s ParsingError
|
||||
|
Loading…
Reference in New Issue
Block a user