module Futhark.CodeGen.Backends.GenericCSharp.Options
( Option (..)
, OptionArgument (..)
, generateOptionParser
)
where
import Futhark.CodeGen.Backends.GenericCSharp.AST
data Option = Option { optionLongName :: String
, optionShortName :: Maybe Char
, optionArgument :: OptionArgument
, optionAction :: [CSStmt]
}
data OptionArgument = NoArgument
| RequiredArgument
| OptionalArgument
generateOptionParser :: [Option] -> [CSStmt]
generateOptionParser options =
[ Assign (Var "options") (Collection "OptionSet" $ map parseOption options)
, Assign (Var "extra") (Call (Var "options.Parse") [Arg Nothing (Var "args")])
]
where parseOption option = Array [ String $ option_string option
, Lambda (Var "optarg") $ optionAction option ]
option_string option = case optionArgument option of
RequiredArgument ->
concat [maybe "" prefix $ optionShortName option,optionLongName option,"="]
_ ->
maybe "" prefix (optionShortName option) ++ optionLongName option
prefix = flip (:) "|"