Verified Commit 989664bc authored by Camil Staps's avatar Camil Staps 🚀

Fix matching issue with $

parent 8dc03725
......@@ -28,12 +28,12 @@ where stat = {zero & unseen=s}
match` :: Regex MatchStatus -> [MatchStatus]
match` r=:(Literal cs) st
= matchAndContinue r st $
= matchOrSkip r st $
if (isPrefixOf cs st.unseen) [eat (length cs) st] []
match` (CharacterClass _ _) {unseen=[]}
= []
match` r=:(CharacterClass n cs) st=:{matched,unseen=[u:us]}
= matchAndContinue r st $
= matchOrSkip r st $
if (if n not id $ any (\(f,t) -> f <= u && u <= t) cs) [eat 1 st] []
match` (Concat []) st
= [st]
......@@ -58,12 +58,12 @@ match` (Group id r) st
= [{st` & groups=put id (drop (length st.matched) st`.matched) st`.groups}
\\ st` <- match` r st]
where put id m gs = [(id,m):filter ((<>) id o fst) gs]
match` StartOfString st
= if (isEmpty st.matched) [{st & can_skip=False}] []
match` EndOfString st
= if (isEmpty st.unseen) [st] []
match` r=:StartOfString st
= matchOrSkip r st $ if (isEmpty st.matched) [{st & can_skip=False}] []
match` r=:EndOfString st
= matchOrSkip r st $ if (isEmpty st.unseen) [st] []
match` r=:(WordBreak n) st
= matchAndContinue r st $ if (if n not id atWordBreak) [st`] []
= matchOrSkip r st $ if (if n not id atWordBreak) [st`] []
where
st` = {st & can_skip=False}
atWordBreak
......@@ -84,8 +84,8 @@ eat :: Int MatchStatus -> MatchStatus
eat n st
= {st & matched=st.matched ++ take n st.unseen, unseen=drop n st.unseen}
matchAndContinue :: Regex MatchStatus [MatchStatus] -> [MatchStatus]
matchAndContinue r st sts = sts ++
matchOrSkip :: Regex MatchStatus [MatchStatus] -> [MatchStatus]
matchOrSkip r st sts = sts ++
if can_skip (match` r $ skip 1 st) []
where
can_skip = st.can_skip && not (isEmpty st.unseen) && isEmpty st.matched
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment