Use new `errorParser` and `<:>` functions.

beta
Philippe Pittoli 2024-02-15 20:41:46 +01:00
parent 8d3ecb1c14
commit 8f16222114
1 changed files with 6 additions and 6 deletions

View File

@ -4,7 +4,6 @@ import Prelude
import Control.Alt ((<|>)) import Control.Alt ((<|>))
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.String.CodeUnits as CU
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Validation.Semigroup (V, invalid, toEither) 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 :: G.Parser LoginParsingError String
login_parser = do login_parser = do
l <- G.many1 (alpha <|> digit) <|> G.Parser \i -> G.failureError i.position (Just CannotParse) input <- G.current_input
_ <- SomeParsers.eof <|> G.Parser \i -> G.failureError i.position (Just CannotEntirelyParse) _ <- G.many1 (alpha <|> digit) G.<:> \_ -> CannotParse
_ <- SomeParsers.eof G.<:> \_ -> CannotEntirelyParse
pos <- G.current_position pos <- G.current_position
if pos < min_login_size || pos > max_login_size if between min_login_size max_login_size pos
then G.Parser \i -> G.failureError i.position (Just $ Size min_login_size max_login_size pos) then pure input.string
else pure $ CU.fromCharArray l else G.errorParser (Just $ Size min_login_size max_login_size pos)
login :: String -> Either (Array Error) String login :: String -> Either (Array Error) String
login s = toEither $ parse login_parser s ParsingError login s = toEither $ parse login_parser s ParsingError