Verified Commit 29cd0d76 authored by Camil Staps's avatar Camil Staps 🙂

Fix escape sequences; parse pipe; cleanup dcl

parent 24d29590
...@@ -5,4 +5,3 @@ from Data.Maybe import :: Maybe ...@@ -5,4 +5,3 @@ from Data.Maybe import :: Maybe
from Regex import :: Regex from Regex import :: Regex
compile :: [Char] -> Maybe Regex compile :: [Char] -> Maybe Regex
parse :: [Regex] [Char] -> Maybe ([Regex], [Char])
...@@ -40,6 +40,10 @@ parse [r:rs] ['*':cs] = Just ([Many True r:rs], cs) ...@@ -40,6 +40,10 @@ parse [r:rs] ['*':cs] = Just ([Many True r:rs], cs)
parse [r:rs] ['?':'?':cs] = Just ([Optional False r:rs], cs) parse [r:rs] ['?':'?':cs] = Just ([Optional False r:rs], cs)
parse [r:rs] ['?':cs] = Just ([Optional True r:rs], cs) parse [r:rs] ['?':cs] = Just ([Optional True r:rs], cs)
parse [Any rs:rs`] ['|':cs] = (\(r,cs)->([Any $ rs++r:rs`],cs)) <$> parse [] cs
parse [r:rs] ['|':cs] = (\(r`,cs)->([Any [r:r`]:rs],cs)) <$> parse [] cs
parse _ ['|':_] = Nothing
parse [r:rs] ['{':cs] parse [r:rs] ['{':cs]
| isNothing fr = Nothing | isNothing fr = Nothing
| hd cs` == '}' | hd cs` == '}'
...@@ -99,7 +103,7 @@ singleChar ['\\':c:cs] ...@@ -99,7 +103,7 @@ singleChar ['\\':c:cs]
| otherwise | otherwise
= Nothing = Nothing
where where
escapable = ['\\+*?()[]{}^$.'] escapable = ['\\+*?()[]{}^$.|']
(octs,nonocts) = spanMax 3 isOctDigit [c:cs] (octs,nonocts) = spanMax 3 isOctDigit [c:cs]
......
definition module Regex.Util definition module Regex.Util
escape_sequences :== escape_sequences :==
[ ('a', '\a') [ ('a', '\x07')
, ('b', '\b') , ('b', '\x08')
, ('f', '\f') , ('f', '\x0c')
, ('n', '\n') , ('n', '\x0a')
, ('r', '\r') , ('r', '\x0d')
, ('t', '\t') , ('t', '\x09')
, ('v', '\v') , ('v', '\x0b')
, ('\\', '\\') , ('\\', '\\')
] ]
shorthand_classes :== shorthand_classes :==
[ ('d', [('0','9')]) [ ('w', [('A','Z'),('a','z'),('0','9'),('_','_')])
, ('D', [('\0','/'),(':','\255')])
, ('w', [('A','Z'),('a','z'),('0','9'),('_','_')])
, ('W', [('\0','/'),(':','@'),('[','^'),('`','`'),('{','\255')]) , ('W', [('\0','/'),(':','@'),('[','^'),('`','`'),('{','\255')])
, ('d', [('0','9')])
, ('D', [('\0','/'),(':','\255')])
, ('s', [(' ',' '),('\t','\n'),('\f','\r')]) , ('s', [(' ',' '),('\t','\n'),('\f','\r')])
, ('S', [('\0','\8'),('\11','\11'),('\14','\31'),('!','\255')]) , ('S', [('\0','\8'),('\11','\11'),('\14','\31'),('!','\255')])
] ]
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