Verified Commit 8dc03725 authored by Camil Staps's avatar Camil Staps 🚀

Fix parsing of |

parent 91f72535
......@@ -50,12 +50,18 @@ parse g [r:rs] ['*':cs] = Ok (g, [Many True r:rs], cs)
parse g [r:rs] ['?':'?':cs] = Ok (g, [Optional False r:rs], cs)
parse g [r:rs] ['?':cs] = Ok (g, [Optional True r:rs], cs)
parse g [Any rs:rs`] ['|':cs]
= (\(g,r,cs) -> (g,[Any $ rs++r:rs`],cs)) <$> parse g [] cs
parse g [r:rs] ['|':cs]
= (\(g,r`,cs) -> (g,[Any [r:r`]:rs],cs)) <$> parse g [] cs
parse g [] ['|':_]
= Error "no regex before |"
parse g rs ['|':cs]
= (\(g,rs`,cs) -> (g,[Any [revConcat rs:rs`]],cs)) <$> alternatives g [] cs
where
alternatives :: Int [Regex] [Char] -> MaybeErrorString (Int, [Regex], [Char])
alternatives g rs []
= Ok (g, [revConcat rs], [])
alternatives g rs cs=:[')':_]
= Ok (g, [revConcat rs], cs)
alternatives g rs ['|':cs]
= (\(g,rs`,cs) -> (g, [revConcat rs:rs`], cs)) <$> alternatives g [] cs
alternatives g rs cs
= parse g rs cs >>= uncurry3 alternatives
parse g [r:rs] ['{':cs]
| isNothing fr = Error "couldn't parse from part of quantifier"
......@@ -158,5 +164,9 @@ shorthandClass ['\\':c:cs] = case lookup c shorthand_classes of
shorthandClass ['.':cs] = Ok ([('\x00','\x09'),('\x0b','\xff')], cs)
shorthandClass _ = Error "expected character class"
revConcat :: [Regex] -> Regex
revConcat [r] = r
revConcat rs = Concat $ reverse rs
uncurry3 :: (a b c -> d) (a,b,c) -> d
uncurry3 f (x,y,z) = f x y z
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