summaryrefslogtreecommitdiffstats
path: root/app/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'app/Main.hs')
-rw-r--r--app/Main.hs40
1 files changed, 24 insertions, 16 deletions
diff --git a/app/Main.hs b/app/Main.hs
index f9452aa..41a546f 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -526,26 +526,34 @@ suggestTags :: S.Settings -> C.ProbabilityCache -> D.Document -> [(G.Tag, [G.Tag
suggestTags settings probabilityCache doc = do
flip map settings.suggestedTags $ \suggestedTag ->
case suggestedTag of
- S.SuggestTagByRE tagName pattern ->
+ S.SuggestTagByRE tagName searchReplaces ->
let tagValues =
- nub
- . mapMaybe
- ( -- XXX Whys is this so complicated?
- \match -> do
- captures <- snd <$> R.matchCaptures match
- pure
- ( foldl
- ( \template (captureName, captureOrdinal) ->
- T.replace
- ("${" <> R.getCaptureName captureName <> "}")
- (R.capturedText (captures !! (fromEnum captureOrdinal - 1)))
- template
+ nub . concat $
+ map
+ ( \searchReplace ->
+ mapMaybe
+ ( -- XXX Whys is this so complicated?
+ \match -> do
+ captures <- snd <$> R.matchCaptures match
+ pure
+ ( foldl
+ ( \template (captureName, captureOrdinal) ->
+ T.replace
+ ("${" <> R.getCaptureName captureName <> "}")
+ (R.capturedText (captures !! (fromEnum captureOrdinal - 1)))
+ template
+ )
+ (R.getTemplate searchReplace)
+ (HM.toList $ R.captureNames match)
+ )
+ )
+ ( R.allMatches
+ ( doc.index.content
+ R.*=~ R.getSearch searchReplace
)
- (R.getTemplate pattern)
- (HM.toList $ R.captureNames match)
)
)
- $ R.allMatches (doc.index.content R.*=~ (R.getSearch pattern))
+ searchReplaces
in (G.tag tagName (Just ""), map (G.tag tagName . Just) tagValues)
S.SuggestTagByTags tagName ->
let tagValues =