RFC5234: return what was parsed (except for \r\n in lwsp).

master
Philippe Pittoli 2024-01-30 03:58:25 +01:00
parent b77f219c40
commit 45f867f3c5
1 changed files with 8 additions and 7 deletions

View File

@ -2,11 +2,12 @@
-- | This module implements core rules found in appendix B.1.
module GenericParser.RFC5234 where
import Prelude (Unit, between, (<<<), (||), (==), bind, void, ($))
import Prelude (between, pure, (<$>), (<<<), (||), (==), bind, ($))
import Control.Alt ((<|>))
import Data.Array as A
import Data.Char as C
import Data.String.CodeUnits as CU
import GenericParser.BaseFunctions (isAlpha, isDigit, isHexaDecimal)
@ -40,9 +41,10 @@ cr = char '\r'
-- | CRLF: Internet standard newline.
-- |
-- | CRLF = CR LF
crlf :: forall e. Parser e Unit
crlf :: forall e. Parser e String
crlf = do _ <- char '\r'
void $ char '\n'
_ <- char '\n'
pure "\r\n"
-- | CTL: control characters.
-- |
@ -87,10 +89,9 @@ lf = char '\n'
-- | Do not use when defining mail headers and use with caution in other contexts.
-- |
-- | LWSP = *(WSP / CRLF WSP)
lwsp :: forall e. Parser e Unit
lwsp = void $ A.many (wsp <|> (do _ <- crlf
wsp))
lwsp :: forall e. Parser e String
lwsp = CU.fromCharArray <$> A.many (wsp <|> (do _ <- crlf
wsp))
-- | OCTET: any data on a single byte.
-- |