RFC5234: done.

master
Philippe Pittoli 2024-01-27 08:24:43 +01:00
parent 8e68099e52
commit 140c7e128c
1 changed files with 33 additions and 22 deletions

View File

@ -5,11 +5,12 @@ module GenericParser.RFC5234 where
import Prelude (Unit, between, (<<<), (||), (==), bind, void, ($))
import Control.Alt ((<|>))
import Data.Array as A
import Data.Char as C
import GenericParser.BaseFunctions (isAlpha, isDigit, isHexaDecimal)
import GenericParser.Parser (Parser, char, sat)
import GenericParser.Parser (Parser, char, sat, item)
-- | ALPHA: any letter, upper or lower case.
-- |
@ -51,13 +52,17 @@ ctl = sat cond
where cond x = (between 0 31 $ C.toCharCode x)
|| C.toCharCode x == 127
--DIGIT = %x30-39
-- ; 0-9
-- | DIGIT: any digit character (from 0 to 9).
-- |
-- | DIGIT = %x30-39
digit :: forall e. Parser e Char
digit = sat isDigit
--DQUOTE = %x22
-- ; " (Double Quote)
-- | DQUOTE: double quote (").
-- |
-- | DQUOTE = %x22
dquote :: forall e. Parser e Unit
dquote = void $ sat (\x -> C.toCharCode x == 34)
-- | HEXDIG: hexadecimal.
-- |
@ -70,23 +75,29 @@ hexdig = sat isHexaDecimal
htab :: forall e. Parser e Char
htab = char '\t'
--LF = %x0A
-- ; linefeed
--
--LWSP = *(WSP / CRLF WSP)
-- ; Use of this linear-white-space rule
-- ; permits lines containing only white
-- ; space that are no longer legal in
-- ; mail headers and have caused
-- ; interoperability problems in other
-- ; contexts.
-- ; Do not use when defining mail
-- ; headers and use with caution in
-- ; other contexts.
--
--OCTET = %x00-FF
-- ; 8 bits of data
--
-- | LF: linefeed.
-- |
-- | LF = %x0A
lf :: forall e. Parser e Unit
lf = void $ char '\n'
-- | LWSP: Use of this linear-white-space rule permits lines containing only white
-- | space that are no longer legal in mail headers and have caused interoperability
-- | problems in other contexts.
-- | 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))
-- | OCTET: any data on a single byte.
-- |
-- | OCTET = %x00-FF
octet :: forall e. Parser e Char
octet = item
-- | SP: space.
-- |
-- | SP = %x20