{-# LANGUAGE NoMonomorphismRestriction #-}
module Data.Regex.Antimirov.Regex where

data (Eq a, Ord a) => Regex a
	= Then (Regex a) (Regex a) 
	| Or (Regex a) (Regex a) 
	| Star (Regex a) 
	| Empty 
	| Literal a
	deriving (Eq, Ord, Show)

nullable :: (Ord t) => Regex t -> Bool
nullable Empty = True
nullable (Then r1 r2) = nullable r1 && nullable r2
nullable (Or r1 r2) = nullable r1 || nullable r2
nullable (Star _) = True
nullable (Literal _) = False


( - ) = Then 
( ? ) x = x # Empty
( * ) = Star
( # ) = Or
l = Literal

infixr 7 ?
infixr 7 *
infixr 6 -
infixr 5 #

toG :: Ord a => [a] -> Regex a
toG [] = Empty
toG l_ = foldl1 Then ((map Literal) l_)