Created
February 21, 2012 16:48
-
-
Save MgaMPKAy/1877328 to your computer and use it in GitHub Desktop.
try to implement VBF.Compilers.Scanners.RegularExpression;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
module Regex where | |
import GHC.Exts(IsString(..)) | |
data Regex | |
= Empty | |
| Concatention Regex Regex | |
| Alternation Regex Regex | |
| KleeneStar Regex | |
| Symbol String | |
instance IsString Regex where | |
fromString = Symbol | |
instance Show Regex where | |
show Empty = "" | |
show (Concatention r1 r2) = show r1 ++ show r2 | |
show (Alternation r1 r2) = show r1 ++ "|" ++ show r2 | |
show (KleeneStar r) = "[" ++ show r ++ "]*" | |
show (Symbol s) = s | |
infix 5 <+> | |
(<+>) :: Regex -> Regex -> Regex | |
a <+> b = Concatention a b | |
infix 4 <|> | |
(<|>) :: Regex -> Regex -> Regex | |
a <|> b = Alternation a b | |
many :: Regex -> Regex | |
many = KleeneStar | |
re :: Regex | |
re = many $ "a" <|> (many $ "b" <+> "a") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment