From 140c7e128c2bbc9bff44ebf5cc47fa79ee7ffaec Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sat, 27 Jan 2024 08:24:43 +0100 Subject: [PATCH] RFC5234: done. --- src/GenericParser/RFC5234.purs | 55 ++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/src/GenericParser/RFC5234.purs b/src/GenericParser/RFC5234.purs index 752ef53..2769570 100644 --- a/src/GenericParser/RFC5234.purs +++ b/src/GenericParser/RFC5234.purs @@ -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