]> gitweb @ CieloNegro.org - hs-rrdtool.git/blobdiff - Database/RRDtool/Expression.hs
IsShortEnoughForVarName
[hs-rrdtool.git] / Database / RRDtool / Expression.hs
index 669acbca32adffa985f93c652b4e60cc5823f39e..499a580753c6a17e4d049a36e9ebbc3828ab93f0 100644 (file)
@@ -10,8 +10,11 @@ module Database.RRDtool.Expression
     , IsExprSet
     , IsCommonExprSet
 
+    , IsVarName
+    , IsShortEnoughForVarName
+    , IsGoodLetterForVarName
+
     , Constant(..)
-    , IsVarName(..)
     , Variable(..)
     , IsVariableSet
     , CommonUnaryOp(..)
@@ -29,6 +32,10 @@ module Database.RRDtool.Expression
     where
 
 import Data.HList
+import Data.HList.String
+import Types.Data.Bool
+import Types.Data.Num hiding ((:*:))
+import Types.Data.Ord
 
 
 -- MentionedVars
@@ -66,9 +73,38 @@ instance IsCommonExpr Constant
 instance MentionedVars Constant where
     type MentionedVarsOf Constant = HNil
 
-class (Show a, Eq a, Ord a) => IsVarName a where
-    varName :: a -> String
-
+{- This is what we want to do but GHC can't handle this for now. 
+class ( (HLengthOf str :<=: D255) ~ True
+      , HString str
+      )
+    => IsVarName str
+-}
+class ( IsShortEnoughForVarName str
+      , HString str
+      )
+    => IsVarName str
+
+class HString str => IsShortEnoughForVarName str
+instance ( HString str
+         , (HLength str :<=: D255) ~ True
+         )
+    => IsShortEnoughForVarName str
+
+class IntegerT c => GoodLetterForVarName c where
+    type IsGoodLetterForVarName c
+
+instance IntegerT c => GoodLetterForVarName c where
+    type IsGoodLetterForVarName c = ( (c :>=: D65) :&&: (c :<=:  D90) ) -- A-Z
+                                    :||:
+                                    ( (c :>=: D99) :&&: (c :<=: D122) ) -- a-z
+                                    :||:
+                                    ( c :==: D45 ) -- '-'
+                                    :||:
+                                    ( c :==: D95 ) -- '_'
+
+--instance (a :>=: D65) ~ True => IsGoodLetterForVarName a
+
+-- Variable
 data Variable vn
     = Variable !vn
     deriving (Show, Eq, Ord)