Add recursive glob matcher.

This commit is contained in:
Dillon Kearns 2021-03-31 12:41:49 -07:00
parent f7c647fb80
commit ea75b4acc2
2 changed files with 39 additions and 0 deletions

View File

@ -1,6 +1,9 @@
module Glob exposing (..)
import List.Extra
import OptimizedDecoder
import Pages.StaticHttp as StaticHttp
import Secrets
type Glob a
@ -35,6 +38,19 @@ star =
)
recursiveStar : Glob String
recursiveStar =
Glob "**"
(\captures ->
case captures of
first :: rest ->
( first, rest )
[] ->
( "ERROR", [] )
)
zeroOrMore : List String -> Glob (Maybe String)
zeroOrMore matchers =
Glob
@ -136,3 +152,14 @@ oneOf ( defaultMatch, otherMatchers ) =
[] ->
( Tuple.second defaultMatch, [] )
)
toStaticHttp : Glob a -> StaticHttp.Request (List a)
toStaticHttp glob =
StaticHttp.get (Secrets.succeed <| "glob://" ++ toPattern glob)
(OptimizedDecoder.string
|> OptimizedDecoder.list
|> OptimizedDecoder.list
|> OptimizedDecoder.map
(\appliedList -> appliedList |> List.map (\inner -> run inner glob |> .match))
)

View File

@ -93,6 +93,18 @@ all =
, expectedMatch = ( "before-slash", "AFTER-SLASH" )
, expectedPattern = "*/*.txt"
}
, test "recursive match" <|
\() ->
Glob.succeed Tuple.pair
|> Glob.keep Glob.recursiveStar
|> Glob.drop (Glob.literal "/")
|> Glob.keep Glob.star
|> Glob.drop (Glob.literal ".txt")
|> expect
{ captures = [ "a/b/c", "d" ]
, expectedMatch = ( "a/b/c", "d" )
, expectedPattern = "**/*.txt"
}
]