Fixed matching of groups.
Matching of the tail of all groups would continue if any matched, leading to (aa|bb) matching the string ab. Also, any empty group would mean continuing to match the rest of the terms, ignoring a non-empty matching group. This lead to (aa|a) not matching the string a.
This commit is contained in:
parent
213cefa832
commit
0fb804cc21
1 changed files with 3 additions and 5 deletions
|
@ -15,6 +15,7 @@ module System.FilePath.GlobPattern (
|
|||
) where
|
||||
|
||||
import Control.Arrow (second)
|
||||
import Control.Monad (msum)
|
||||
import Data.Ix (Ix, inRange)
|
||||
import Data.List (nub)
|
||||
import Data.Maybe (isJust)
|
||||
|
@ -144,11 +145,8 @@ matchTerms (MatchClass k c:ts) cs = matchClass cs >>= matchTerms ts
|
|||
where matchClass (b:bs) | (inClass && k) || not (inClass || k) = return bs
|
||||
where inClass = b `inSRange` c
|
||||
matchClass _ = fail "no match"
|
||||
matchTerms (MatchGroup g:ts) cs = matchGroup g cs >>= matchTerms ts
|
||||
where matchGroup g' as | any null g' = return as
|
||||
matchGroup g' (a:as) | a `elem` map head g' =
|
||||
matchGroup (map tail g') as
|
||||
matchGroup _ _ = fail "not in group"
|
||||
matchTerms (MatchGroup g:ts) cs = msum (map matchGroup g)
|
||||
where matchGroup g = matchTerms (MatchLiteral g : ts) cs
|
||||
matchTerms [MatchAny] _ = return ()
|
||||
matchTerms (MatchAny:ts) cs = matchAny cs >>= matchTerms ts
|
||||
where matchAny [] = fail "no match"
|
||||
|
|
Loading…
Add table
Reference in a new issue