instance Show RegExp where showsPrec _ Epsilon = showChar '@' showsPrec _ (Literal c) | isSymbol c = showChar '\'' . showChar c . showChar '\'' | otherwise = showChar c showsPrec n (Star e) = showsPrec 10 e . showChar '*' showsPrec n (OneOrMore e) = showParen (n == 4) $ showsPrec 10 e . showChar '+' showsPrec _ (Optional e) = showsPrec 10 e . showChar '?' showsPrec n (e1 `Or` e2) = showParen (n /= 0 && n /= 4) $ showsPrec 4 e1 . showChar '+' . showsPrec 4 e2 showsPrec n (e1 `Then` e2) = showParen (n /= 0 && n /= 6) $ showsPrec 6 e1 . showChar ' ' . showsPrec 6 e2