Expose Elm types

As a general rule of thumb, internal values need no opaque types to hide their implementation
parser
Bram 2024-04-10 08:28:52 +02:00
parent c858ef151e
commit 203205f53c
2 changed files with 8 additions and 8 deletions

View File

@ -47,8 +47,8 @@ type alias IPv6Address =
{-| The server name is a combination of a hostname and an optional port. {-| The server name is a combination of a hostname and an optional port.
-} -}
type ServerName type alias ServerName =
= ServerName { host : HostName, port_ : Maybe Int } { host : HostName, port_ : Maybe Int }
{-| Parser for the DNS name record. The Matrix spec bases its grammar on the {-| Parser for the DNS name record. The Matrix spec bases its grammar on the
@ -214,7 +214,7 @@ portParser =
servernameParser : Parser ServerName servernameParser : Parser ServerName
servernameParser = servernameParser =
P.succeed (\h p -> ServerName { host = h, port_ = p }) P.succeed ServerName
|= hostnameParser |= hostnameParser
|= P.oneOf |= P.oneOf
[ P.succeed Just [ P.succeed Just
@ -225,7 +225,7 @@ servernameParser =
toString : ServerName -> String toString : ServerName -> String
toString (ServerName { host, port_ }) = toString { host, port_ } =
let let
hostString : String hostString : String
hostString = hostString =

View File

@ -43,8 +43,8 @@ import Internal.Tools.ParserExtra as PE
import Parser as P exposing ((|.), (|=), Parser) import Parser as P exposing ((|.), (|=), Parser)
type UserID type alias UserID =
= UserID { localpart : String, domain : ServerName } { localpart : String, domain : ServerName }
fromString : String -> Maybe UserID fromString : String -> Maybe UserID
@ -61,13 +61,13 @@ localpartParser =
toString : UserID -> String toString : UserID -> String
toString (UserID { localpart, domain }) = toString { localpart, domain } =
String.concat [ "@", localpart, ":", ServerName.toString domain ] String.concat [ "@", localpart, ":", ServerName.toString domain ]
userIdParser : Parser UserID userIdParser : Parser UserID
userIdParser = userIdParser =
P.succeed (\l d -> UserID { localpart = l, domain = d }) P.succeed UserID
|. P.symbol "@" |. P.symbol "@"
|= localpartParser |= localpartParser
|. P.symbol ":" |. P.symbol ":"