Browse files

Import EMGM version of Uniplate short projDesc.

  • Loading branch information...
1 parent a967b3c commit de8298b5b092a2efbeedef932dda2fbba068f141 @spl committed Mar 30, 2009
Showing with 54 additions and 0 deletions.
  1. +54 −0 EmacsOrgWithEMGM2.hs
View
54 EmacsOrgWithEMGM2.hs
@@ -0,0 +1,54 @@
+{-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE OverlappingInstances #-}
+{-# LANGUAGE UndecidableInstances #-}
+
+module EmacsOrgWithEMGM2 where
+
+import Generics.EMGM.Derive
+import Generics.EMGM (collect)
+
+import Data.List (isPrefixOf)
+import Data.Maybe (listToMaybe)
+
+type Line = Int
+type Column = Int
+
+data FilePosition = FilePosition Line Column
+
+data WithPos a = WithPos { filePos :: FilePosition, innerValue :: a }
+
+data OrgTableP = OrgTableP [WithPos OrgTableRow]
+
+data OrgFileElementP
+ = TableP OrgTableP
+ | ParagraphP String
+ | HeadingP OrgHeadingP
+
+data OrgHeadingP = OrgHeadingP Int String [WithPos OrgFileElementP]
+
+data OrgFileP = OrgFileP [WithPos OrgFileElementP]
+
+data OrgTableRow
+ = OrgTableRow [String]
+ | OrgTableRowSep
+
+$(deriveMany
+ [ ''FilePosition
+ , ''WithPos
+ , ''OrgTableP
+ , ''OrgHeadingP
+ , ''OrgFileElementP
+ , ''OrgFileP
+ , ''OrgTableRow
+ ])
+
+-- EMGM adaptation of Neil's Uniplate version from:
+-- http://neilmitchell.blogspot.com/2009/03/concise-generic-queries.html
+projDesc :: String -> OrgFileP -> Maybe String
+projDesc name p = listToMaybe [y |
+ OrgHeadingP _ x ys <- collect p, name == x,
+ ParagraphP y <- collect ys, "Description" `isPrefixOf` y]
+

0 comments on commit de8298b

Please sign in to comment.