-- | -- Module : ZipperAG -- Copyright : 2013 Pedro Martins -- License : BSD3 -- -- Maintainer : Pedro Martins <pedromartins4@gmail.com> -- Stability : Experimental -- Portability : Portable -- -- Zipper-based AG supporting functions module Language.Grammars.ZipperAG where import Data.Generics.Zipper import Data.Maybe -- |Gives the n'th child (.$) :: Zipper a -> Int -> Zipper a z .$ 1 = fromJust (down' z) z .$ n = fromJust (right ( z.$(n-1) )) -- |parent parent = fromJust.up -- |Tests if z is the n'th sibling (.|) :: Zipper a -> Int -> Bool z .| 1 = case (left z) of Nothing -> False _ -> True z .| n = case (left z) of Nothing -> False Just x -> z .| (n-1)