Add another elm-review rule.

This commit is contained in:
Dillon Kearns 2022-01-28 08:31:18 -08:00
parent 7ac4ceecde
commit 1b19d8e22e
2 changed files with 42 additions and 42 deletions

View File

@ -38,8 +38,8 @@ config : List Rule
config =
([ NoExposingEverything.rule
, NoPrematureLetComputation.rule
--NoImportingEverything.rule []
, NoImportingEverything.rule []
|> ignoreInTest
, NoInconsistentAliases.config
[ ( "Html.Attributes", "Attr" )

View File

@ -1,81 +1,81 @@
module CookieParser exposing (parse)
import Dict exposing (Dict)
import Parser exposing (..)
import Parser exposing ((|.), (|=), Parser, Step(..))
import Url
parse : String -> Dict String String
parse input =
run parser input
Parser.run parser input
|> Result.withDefault Dict.empty
parser : Parser (Dict String String)
parser =
loop [] keyValuePair
|> map Dict.fromList
Parser.loop [] keyValuePair
|> Parser.map Dict.fromList
keyValuePair : List ( String, String ) -> Parser (Step (List ( String, String )) (List ( String, String )))
keyValuePair revChunks =
oneOf
[ end
|> map (\_ -> Done (List.reverse revChunks))
, succeed (Loop revChunks)
|. chompIf isSpace
|. chompWhile isSpace
, succeed Tuple.pair
Parser.oneOf
[ Parser.end
|> Parser.map (\_ -> Done (List.reverse revChunks))
, Parser.succeed (Loop revChunks)
|. Parser.chompIf isSpace
|. Parser.chompWhile isSpace
, Parser.succeed Tuple.pair
|= parseKey
|= oneOf
[ succeed Nothing
|. token ";"
, succeed Just
|. token "="
|= Parser.oneOf
[ Parser.succeed Nothing
|. Parser.token ";"
, Parser.succeed Just
|. Parser.token "="
|= valueParser
|. oneOf
[ token ";"
, succeed ()
|. Parser.oneOf
[ Parser.token ";"
, Parser.succeed ()
]
]
|> andThen
|> Parser.andThen
(\( key, maybeValue ) ->
case maybeValue of
Just value ->
succeed (Loop (( key, value ) :: revChunks))
Parser.succeed (Loop (( key, value ) :: revChunks))
Nothing ->
succeed (Loop revChunks)
Parser.succeed (Loop revChunks)
)
]
valueParser : Parser String
valueParser =
succeed identity
|. chompWhile isSpace
|= oneOf
[ succeed ""
|. token ";"
, succeed identity
|. token "\""
|= (chompUntil "\""
|> getChompedString
Parser.succeed identity
|. Parser.chompWhile isSpace
|= Parser.oneOf
[ Parser.succeed ""
|. Parser.token ";"
, Parser.succeed identity
|. Parser.token "\""
|= (Parser.chompUntil "\""
|> Parser.getChompedString
)
|. token "\""
, chompWhile (\c -> c /= ';')
|> getChompedString
|. Parser.token "\""
, Parser.chompWhile (\c -> c /= ';')
|> Parser.getChompedString
]
|> map String.trim
|> map (\value -> value |> Url.percentDecode |> Maybe.withDefault "")
|> Parser.map String.trim
|> Parser.map (\value -> value |> Url.percentDecode |> Maybe.withDefault "")
parseKey : Parser String
parseKey =
succeed identity
|= (chompWhile (\c -> c /= '=' && c /= ';')
|> getChompedString
|> map String.trim
Parser.succeed identity
|= (Parser.chompWhile (\c -> c /= '=' && c /= ';')
|> Parser.getChompedString
|> Parser.map String.trim
)