support globs when built w/o TDFA, just slower
This commit is contained in:
parent
613f8f02e3
commit
410f603383
1 changed files with 30 additions and 17 deletions
|
@ -26,23 +26,23 @@ import Data.Char
|
||||||
#ifdef WITH_TDFA
|
#ifdef WITH_TDFA
|
||||||
import Text.Regex.TDFA
|
import Text.Regex.TDFA
|
||||||
import Text.Regex.TDFA.String
|
import Text.Regex.TDFA.String
|
||||||
|
#else
|
||||||
|
import System.Path.WildMatch
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
type View = [(MetaField, ViewFilter)]
|
type View = [(MetaField, ViewFilter)]
|
||||||
|
|
||||||
data ViewFilter
|
data ViewFilter
|
||||||
= FilterValues (S.Set MetaValue)
|
= FilterValues (S.Set MetaValue)
|
||||||
#ifdef WITH_TDFA
|
| FilterGlob Glob
|
||||||
| FilterGlob String Regex
|
|
||||||
#endif
|
|
||||||
|
|
||||||
instance Show ViewFilter where
|
instance Show ViewFilter where
|
||||||
show (FilterValues s) = show s
|
show (FilterValues s) = show s
|
||||||
show (FilterGlob s _) = s
|
show (FilterGlob g) = getGlob g
|
||||||
|
|
||||||
instance Eq ViewFilter where
|
instance Eq ViewFilter where
|
||||||
FilterValues x == FilterValues y = x == y
|
FilterValues x == FilterValues y = x == y
|
||||||
FilterGlob x _ == FilterGlob y _ = x == y
|
FilterGlob x == FilterGlob y = x == y
|
||||||
_ == _ = False
|
_ == _ = False
|
||||||
|
|
||||||
instance Arbitrary ViewFilter where
|
instance Arbitrary ViewFilter where
|
||||||
|
@ -50,12 +50,26 @@ instance Arbitrary ViewFilter where
|
||||||
size <- arbitrarySizedBoundedIntegral `suchThat` (< 100)
|
size <- arbitrarySizedBoundedIntegral `suchThat` (< 100)
|
||||||
FilterValues . S.fromList <$> vector size
|
FilterValues . S.fromList <$> vector size
|
||||||
|
|
||||||
|
#ifdef WITH_TDFA
|
||||||
|
data Glob = Glob String Regex
|
||||||
|
#else
|
||||||
|
data Glob = Glob String
|
||||||
|
#endif
|
||||||
|
|
||||||
|
instance Eq Glob where
|
||||||
|
a == b = getGlob a == getGlob b
|
||||||
|
|
||||||
|
getGlob :: Glob -> String
|
||||||
|
#ifdef WITH_TDFA
|
||||||
|
getGlob (Glob g _) = g
|
||||||
|
#else
|
||||||
|
getGlob (Glob g) = g
|
||||||
|
#endif
|
||||||
|
|
||||||
{- Can a ViewFilter match multiple different MetaValues? -}
|
{- Can a ViewFilter match multiple different MetaValues? -}
|
||||||
multiValue :: ViewFilter -> Bool
|
multiValue :: ViewFilter -> Bool
|
||||||
multiValue (FilterValues s) = S.size s > 1
|
multiValue (FilterValues s) = S.size s > 1
|
||||||
#ifdef WITH_TDFA
|
multiValue (FilterGlob _) = True
|
||||||
multiValue (FilterGlob _ _) = True
|
|
||||||
#endif
|
|
||||||
|
|
||||||
{- Each multivalued ViewFilter in a view results in another level of
|
{- Each multivalued ViewFilter in a view results in another level of
|
||||||
- subdirectory nesting. When a file matches multiple ways, it will appear
|
- subdirectory nesting. When a file matches multiple ways, it will appear
|
||||||
|
@ -76,11 +90,13 @@ type MkFileView = FilePath -> FileView
|
||||||
matchFilter :: MetaData -> MetaField -> ViewFilter -> Maybe [MetaValue]
|
matchFilter :: MetaData -> MetaField -> ViewFilter -> Maybe [MetaValue]
|
||||||
matchFilter metadata metafield (FilterValues s) = nonEmptyList $
|
matchFilter metadata metafield (FilterValues s) = nonEmptyList $
|
||||||
S.intersection s (currentMetaDataValues metafield metadata)
|
S.intersection s (currentMetaDataValues metafield metadata)
|
||||||
#ifdef WITH_TDFA
|
matchFilter metadata metafield (FilterGlob glob) = nonEmptyList $
|
||||||
matchFilter metadata metafield (FilterGlob _ r) = nonEmptyList $
|
S.filter (matching glob . fromMetaValue) (currentMetaDataValues metafield metadata)
|
||||||
S.filter matching (currentMetaDataValues metafield metadata)
|
|
||||||
where
|
where
|
||||||
matching = either (const False) (const True) . execute r . fromMetaValue
|
#ifdef WITH_TDFA
|
||||||
|
matching (Glob _ r) = either (const False) (const True) . execute r
|
||||||
|
#else
|
||||||
|
matching (Glob g) = wildCheckCase g
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
nonEmptyList :: S.Set a -> Maybe [a]
|
nonEmptyList :: S.Set a -> Maybe [a]
|
||||||
|
@ -91,7 +107,7 @@ nonEmptyList s
|
||||||
{- Converts a filepath used in a reference branch to the
|
{- Converts a filepath used in a reference branch to the
|
||||||
- filename that will be used in the view.
|
- filename that will be used in the view.
|
||||||
-
|
-
|
||||||
- No two filenames from the same branch should yeild the same result,
|
- No two filepaths from the same branch should yeild the same result,
|
||||||
- so all directory structure needs to be included in the output file
|
- so all directory structure needs to be included in the output file
|
||||||
- in some way. However, the branch's directory structure is not relevant
|
- in some way. However, the branch's directory structure is not relevant
|
||||||
- in the view.
|
- in the view.
|
||||||
|
@ -219,10 +235,7 @@ branchView view
|
||||||
]
|
]
|
||||||
branchvals (FilterValues set) = forcelegal $
|
branchvals (FilterValues set) = forcelegal $
|
||||||
intercalate "," $ map fromMetaValue $ S.toList set
|
intercalate "," $ map fromMetaValue $ S.toList set
|
||||||
#ifdef WITH_TDFA
|
branchvals (FilterGlob glob) = forcelegal $ getGlob glob
|
||||||
branchvals (FilterGlob glob _) = forcelegal $
|
|
||||||
replace "*" "ANY" $ replace "?" "_" glob
|
|
||||||
#endif
|
|
||||||
forcelegal s
|
forcelegal s
|
||||||
| Git.Ref.legal True s = s
|
| Git.Ref.legal True s = s
|
||||||
| otherwise = map (\c -> if isAlphaNum c then c else '_') s
|
| otherwise = map (\c -> if isAlphaNum c then c else '_') s
|
||||||
|
|
Loading…
Add table
Reference in a new issue