------------------------------------------------------------------------------- |-- Module      :  Options-- Copyright   :  2006 Malcolm Wallace-- Licence     :  LGPL---- Maintainer  :  Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk>-- Stability   :  experimental-- Portability :  All---- This module deals with Cpphs options and parsing them-----------------------------------------------------------------------------module Language.Preprocessor.Cpphs.Options(CpphsOption(..), parseOption) whereimport Maybedata CpphsOption= CpphsNoMacro| CpphsNoLine| CpphsText| CpphsStrip| CpphsAnsi| CpphsLayout| CpphsMacro (String,String)| CpphsPath Stringderiving (Eq, Show)flags = [("--nomacro", CpphsNoMacro),("--noline", CpphsNoLine),("--text", CpphsText),("--strip", CpphsStrip),("--hashes", CpphsAnsi),("--layout", CpphsLayout)]parseOption :: String -> Maybe CpphsOptionparseOption x | isJust a = Just $ fromJust awhere a = lookup x flagsparseOption ('-':'D':xs) = Just $ CpphsMacro (s, if null d then "1" else tail d)where (s,d) = break (=='=') xsparseOption ('-':'I':xs) = Just $ CpphsPath $ trail "/\\" xsparseOption _ = Nothingtrail :: (Eq a) => [a] -> [a] -> [a]trail xs = reverse . dropWhile (`elem`xs) . reverse