------------------------------------------------------------------ -- | -- Module : IdlUtil -- Copyright : (c) Dmitry Golubovsky, 2009 -- License : BSD-style -- -- Maintainer : golubovsky@gmail.com -- Stability : experimental -- Portability : portable -- -- -- -- Useful IDL utilities. ------------------------------------------------------------------ module IdlUtil where import Data.List import Data.Maybe import Data.Either import qualified Data.Map as M import Control.Monad.RWS import Text.ParserCombinators.Parsec.Pos import Language.WebIDL defOf :: IDLDefinition -> IDLDef defOf (IDLDefinition _ _ d) = d defName :: IDLDef -> String defName (IDLDefModule s _ _) = s defName (IDLDefInterface s _ _ _) = s defName (IDLDefValue s _) = s defName (IDLDefExcept (IDLExceptDcl s _)) = s defName (IDLDefConst (IDLConstDcl _ s _)) = s defName _ = "" isModule :: IDLDef -> Bool isModule (IDLDefModule _ _ _) = True isModule _ = False isInterface :: IDLDef -> Bool isInterface (IDLDefInterface _ _ _ _) = True isInterface _ = False isFwdInterface :: IDLDef -> Bool isFwdInterface (IDLDefInterface _ _ _ Nothing) = True isFwdInterface _ = False isTypeDef :: IDLDef -> Bool isTypeDef (IDLDefType _) = True isTypeDef _ = False isConst :: IDLDef -> Bool isConst (IDLDefConst _) = True isConst _ = False root2ns :: [IDLDef] -> String root2ns ds = r (reverse ds) where r [] = "" r (d:ds) = "::" ++ defName d ++ r ds