Permalink
Browse files

* Okay, now constants are identified, and given a formatting rule.

  • Loading branch information...
spockz committed Oct 2, 2011
1 parent 24a42cb commit 0057d6b84d606f2aa5675d6ed13311ebae9a1726
Showing with 28 additions and 10 deletions.
  1. +3 −1 src/Data/Data.hs
  2. +22 −7 src/Literate/Haskell.hs
  3. +3 −2 src/Literate/SimpleInfo.hs
View
@@ -5,11 +5,13 @@ data Item = Constructor String
| Function String
| Operator String
| Class String
+ | Constant String
deriving (Eq, Ord)
instance Show Item where
show (Constructor s) = s
show (Type s) = s
show (Function s) = s
show (Operator s) = s
- show (Class s) = s
+ show (Class s) = s
+ show (Constant s) = s
View
@@ -62,7 +62,6 @@ searchConDecl (RecDecl i _) = [Constructor $ prettyPrint i]
searchPat :: ItemQuery Pat
searchPat (PApp i _) = [Constructor $ prettyPrint i]
-searchPat (PVar i) = [Function $ prettyPrint i]
searchPat _ = []
searchExp :: ItemQuery Exp
@@ -76,12 +75,23 @@ searchMat (Match _ (i) _ _ _ _) = [Function $ prettyPrint i]
searchDecl :: ItemQuery Decl
searchDecl (TypeSig _ names t) = case t of
- TyParen (TyFun _ _) -> map nameToString names
- TyFun _ _ -> map nameToString names
- _ -> []
- where nameToString :: Name -> Item
- nameToString (Ident s) = Function s
- nameToString (Symbol s) = Function s
+ TyParen (TyFun _ _) -> namesToFunction names
+ TyFun _ _ -> namesToFunction names
+ TyForall _ _ t -> case t of
+ TyParen (TyFun _ _) -> namesToFunction names
+ TyFun _ _ -> namesToFunction names
+ _ -> namesToConstant names
+ _ -> namesToConstant names
+ where nameToString :: (String -> Item) -> Name -> Item
+ nameToString f (Ident s) = f s
+ nameToString f (Symbol s) = f s
+ namesToFunction = map (nameToString Function)
+ namesToConstant = map (nameToString Constant)
+
+
+
+
+
searchDecl (ClassDecl _ _ name _ _ _) = [Class $ prettyPrint name]
searchDecl _ = []
@@ -101,6 +111,7 @@ getSimpleInfo m = simpleinfo{ types = f isT
, functions = f isF
, operators = f isO
, classes = f isCl
+ , constants = f isConst
}
where f p = map show (filter p collection)
isT (Type _) = True
@@ -113,6 +124,8 @@ getSimpleInfo m = simpleinfo{ types = f isT
isO _ = False
isCl (Class _) = True
isCl _ = False
+ isConst (Constant _) = True
+ isConst _ = False
collection = collect m
@@ -124,6 +137,7 @@ mapping = [
, ("function", mfunctions)
, ("infixoperator", moperators)
, ("class", mclasses)
+ , ("constant", mconstants)
]
mtypes :: SimpleInfo -> [(String, String)]
@@ -133,6 +147,7 @@ moperators SimpleInfo{operators} = map (\ a -> (a, "\\ "++ makeLatexSafe a++"\\
mconstructors SimpleInfo{constructors} = map (dp) constructors
mfunctions SimpleInfo{functions } = map (dp) functions
mclasses SimpleInfo{classes} = map (dp) classes
+mconstants SimpleInfo{constants} = map (dp) constants
@@ -7,8 +7,8 @@ data SimpleInfo = SimpleInfo {
constructors :: [String],
functions :: [String],
operators :: [String],
- classes :: [String]
-
+ classes :: [String],
+ constants :: [String]
} deriving Show
@@ -19,5 +19,6 @@ simpleinfo = SimpleInfo{ fileName = ""
, functions = []
, operators = []
, classes = []
+ , constants = []
}

0 comments on commit 0057d6b

Please sign in to comment.