Remove parsing inside constructors

This commit is contained in:
Jeroen Engels 2024-04-07 22:29:36 +02:00
parent 4129685142
commit 04b3b9fa2a

View File

@ -19,9 +19,9 @@ import Glob exposing (Glob)
type FilePattern type FilePattern
= Include ( String, Glob ) = Include String
| Exclude ( String, Glob ) | Exclude String
| ExcludeFolder ( String, Glob ) | ExcludeFolder String
| InvalidGlob String | InvalidGlob String
@ -69,25 +69,25 @@ compactBase filePatterns accSummary =
[] -> [] ->
Ok accSummary Ok accSummary
(Include ( raw, pattern )) :: rest -> (Include raw) :: rest ->
case Glob.fromString raw of case Glob.fromString raw of
Ok glob -> Ok pattern ->
compactHelp rest [ pattern ] True (addRawIncludeExclude raw True accSummary) compactHelp rest [ pattern ] True (addRawIncludeExclude raw True accSummary)
Err _ -> Err _ ->
Err (compactErrors rest [ raw ]) Err (compactErrors rest [ raw ])
(Exclude ( raw, pattern )) :: rest -> (Exclude raw) :: rest ->
case Glob.fromString raw of case Glob.fromString raw of
Ok glob -> Ok pattern ->
compactHelp rest [ pattern ] False (addRawIncludeExclude raw False accSummary) compactHelp rest [ pattern ] False (addRawIncludeExclude raw False accSummary)
Err _ -> Err _ ->
Err (compactErrors rest [ raw ]) Err (compactErrors rest [ raw ])
(ExcludeFolder ( raw, pattern )) :: rest -> (ExcludeFolder raw) :: rest ->
case Glob.fromString (toFolder raw) of case Glob.fromString (toFolder raw) of
Ok glob -> Ok pattern ->
compactBase rest compactBase rest
{ includeExclude = accSummary.includeExclude { includeExclude = accSummary.includeExclude
, excludedFolders = pattern :: accSummary.excludedFolders , excludedFolders = pattern :: accSummary.excludedFolders
@ -120,9 +120,9 @@ compactHelp filePatterns accGlobs included accSummary =
, excludedFoldersStrings = accSummary.excludedFoldersStrings , excludedFoldersStrings = accSummary.excludedFoldersStrings
} }
(Include ( raw, pattern )) :: rest -> (Include raw) :: rest ->
case Glob.fromString raw of case Glob.fromString raw of
Ok glob -> Ok pattern ->
if included then if included then
compactHelp rest (pattern :: accGlobs) included (addRawIncludeExclude raw included accSummary) compactHelp rest (pattern :: accGlobs) included (addRawIncludeExclude raw included accSummary)
@ -139,9 +139,9 @@ compactHelp filePatterns accGlobs included accSummary =
Err _ -> Err _ ->
Err (compactErrors rest [ raw ]) Err (compactErrors rest [ raw ])
(Exclude ( raw, pattern )) :: rest -> (Exclude raw) :: rest ->
case Glob.fromString raw of case Glob.fromString raw of
Ok glob -> Ok pattern ->
if included then if included then
compactHelp rest compactHelp rest
[ pattern ] [ pattern ]
@ -158,9 +158,9 @@ compactHelp filePatterns accGlobs included accSummary =
Err _ -> Err _ ->
Err (compactErrors rest [ raw ]) Err (compactErrors rest [ raw ])
(ExcludeFolder ( raw, pattern )) :: rest -> (ExcludeFolder raw) :: rest ->
case Glob.fromString (toFolder raw) of case Glob.fromString (toFolder raw) of
Ok glob -> Ok pattern ->
compactHelp rest compactHelp rest
accGlobs accGlobs
included included
@ -200,33 +200,18 @@ addRawIncludeExclude string included summary =
include : String -> FilePattern include : String -> FilePattern
include globStr = include =
case Glob.fromString globStr of Include
Ok glob ->
Include ( globStr, glob )
Err _ ->
InvalidGlob globStr
exclude : String -> FilePattern exclude : String -> FilePattern
exclude globStr = exclude =
case Glob.fromString globStr of Exclude
Ok glob ->
Exclude ( globStr, glob )
Err _ ->
InvalidGlob globStr
excludeFolder : String -> FilePattern excludeFolder : String -> FilePattern
excludeFolder globStr = excludeFolder =
case Glob.fromString (toFolder globStr) of ExcludeFolder
Ok glob ->
ExcludeFolder ( globStr, glob )
Err _ ->
InvalidGlob globStr
toFolder : String -> String toFolder : String -> String