WIP RFC5234.

master
Philippe Pittoli 2024-01-27 07:06:17 +01:00
parent 125bbd1118
commit 1951d893a9
1 changed files with 25 additions and 27 deletions

View File

@ -2,37 +2,41 @@
-- | This module implements core rules found in appendix B.1.
module GenericParser.RFC5234 where
import Prelude (Unit, unit, bind, pure, ($), (<>), (==), (||), between, void)
import Prelude (Unit, between, bind, void, ($))
import Control.Alt ((<|>))
import Data.Array as A
import Data.Char as C
import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
import Data.String.CodeUnits as CU
import GenericParser.BaseFunctions (repeat, isHexaDecimal)
import GenericParser.BaseFunctions (isHexaDecimal)
import GenericParser.Parser (Parser(..)
, sat, char , digit , letter, item, many1, tryMaybe
, current_input, failureError, parse, rollback, until)
import GenericParser.Parser (Parser, char, sat)
-- | RFC 5234:
--ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
--
--BIT = "0" / "1"
--
--CHAR = %x01-7F
-- ; any 7-bit US-ASCII character,
-- ; excluding NUL
--
--CR = %x0D
-- ; carriage return
--
--CRLF = CR LF
-- ; Internet standard newline
--
-- | CHAR (renamed `asciichar` to fix naming conflict with `GenericParser.char`):
-- | any 7-bit US-ASCII character, excluding NUL.
-- |
-- | CHAR = %x01-7F
asciichar :: forall e. Parser e Char
asciichar = sat (\x -> between 1 127 $ C.toCharCode x)
-- | CR: carriage return.
-- |
-- | CR = %x0D
cr :: forall e. Parser e Unit
cr = void $ char '\r'
-- | CRLF: Internet standard newline.
-- |
-- | CRLF = CR LF
crlf :: forall e. Parser e Unit
crlf = do _ <- char '\r'
void $ char '\n'
--CTL = %x00-1F / %x7F
-- ; controls
--
@ -87,9 +91,3 @@ vchar = sat (\x -> between 33 126 $ C.toCharCode x)
-- | WSP = SP / HTAB
wsp :: forall e. Parser e Char
wsp = sp <|> htab
crlf :: forall e. Parser e Unit
crlf = do _ <- char '\r'
_ <- char '\n'
pure unit