File: Options.hs

package info (click to toggle)
hugs98 98.200609.21-6
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 43,136 kB
  • sloc: haskell: 118,978; xml: 61,802; ansic: 46,695; sh: 8,750; cpp: 6,033; makefile: 2,663; yacc: 1,111; cs: 883; sed: 10
file content (54 lines) | stat: -rw-r--r-- 1,438 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-----------------------------------------------------------------------------
-- |
-- 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) where

import Maybe

data CpphsOption
    = CpphsNoMacro
    | CpphsNoLine
    | CpphsText
    | CpphsStrip
    | CpphsAnsi
    | CpphsLayout
    | CpphsUnlit
    | CpphsMacro (String,String)
    | CpphsPath String
      deriving (Eq, Show)
    
    
flags = [ ("--nomacro", CpphsNoMacro)
        , ("--noline",  CpphsNoLine)
        , ("--text",    CpphsText)
        , ("--strip",   CpphsStrip)
        , ("--hashes",  CpphsAnsi)
        , ("--layout",  CpphsLayout)
        , ("--unlit",   CpphsUnlit)
        ]


parseOption :: String -> Maybe CpphsOption
parseOption x | isJust a = Just $ fromJust a
    where a = lookup x flags

parseOption ('-':'D':xs) = Just $ CpphsMacro (s, if null d then "1" else tail d)
    where (s,d) = break (=='=') xs
    
parseOption ('-':'I':xs) = Just $ CpphsPath $ trail "/\\" xs

parseOption _ = Nothing

trail :: (Eq a) => [a] -> [a] -> [a]
trail xs = reverse . dropWhile (`elem`xs) . reverse