We planned to upgrade GitLab and Mattermost to the latest version this Friday morning. Expect some downtime!

Commit 8d806357 authored by Camil Staps's avatar Camil Staps 🐾

Only match last occurence of group

parent c681e3b2
definition module Regex
from StdOverloaded import class ==
from Data.Maybe import :: Maybe (Just, Nothing)
import Regex.Match
......@@ -25,3 +27,5 @@ Optional g :== Repeated g 0 (Just 1)
:: Position :== Int
:: GroupId = Named String | NotNamed Int
instance == GroupId
implementation module Regex
import StdEnv
instance == GroupId
where
(==) (NotNamed a) (NotNamed b) = a == b
(==) (Named a) (Named b) = a == b
(==) _ _ = False
implementation module Regex.Match
import StdBool
from StdFunc import flip, id
from StdFunc import flip, id, o
import StdTuple
from Data.Func import $
import Data.Functor
......@@ -54,8 +55,9 @@ match` (Repeated g f t r) st
= match` (Concat $ repeatn f r ++ [Any $ if g id reverse opts]) st
where opts = [Concat [r, Repeated g 0 (flip (-) (f+1) <$> t) r], Concat []]
match` (Group id r) st
= [{st` & groups=st`.groups ++ [(id,drop (length st.matched) st`.matched)]}
= [{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
......
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