module Language.Egison.CmdOptions
( EgisonOpts (..)
, defaultOption
, cmdParser
) where
import Data.Functor (($>))
import Data.List (intercalate)
import Data.Maybe (maybeToList)
import Options.Applicative
import qualified Text.Parsec as P
data EgisonOpts = EgisonOpts {
EgisonOpts -> Maybe (String, [String])
optExecFile :: Maybe (String, [String]),
EgisonOpts -> Bool
optShowVersion :: Bool,
EgisonOpts -> Maybe String
optEvalString :: Maybe String,
EgisonOpts -> Maybe String
optExecuteString :: Maybe String,
EgisonOpts -> [(String, String)]
optFieldInfo :: [(String, String)],
EgisonOpts -> [String]
optLoadLibs :: [String],
EgisonOpts -> [String]
optLoadFiles :: [String],
EgisonOpts -> Maybe String
optSubstituteString :: Maybe String,
EgisonOpts -> Maybe String
optMapTsvInput :: Maybe String,
EgisonOpts -> Maybe String
optFilterTsvInput :: Maybe String,
EgisonOpts -> Bool
optTsvOutput :: Bool,
EgisonOpts -> Bool
optNoIO :: Bool,
EgisonOpts -> Bool
optShowBanner :: Bool,
EgisonOpts -> Bool
optTestOnly :: Bool,
EgisonOpts -> String
optPrompt :: String,
EgisonOpts -> Maybe String
optMathExpr :: Maybe String,
EgisonOpts -> Bool
optSExpr :: Bool,
EgisonOpts -> Bool
optMathNormalize :: Bool
}
defaultOption :: EgisonOpts
defaultOption :: EgisonOpts
defaultOption = Maybe (String, [String])
-> Bool
-> Maybe String
-> Maybe String
-> [(String, String)]
-> [String]
-> [String]
-> Maybe String
-> Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts
EgisonOpts Maybe (String, [String])
forall a. Maybe a
Nothing Bool
False Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing [] [] [] Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Bool
False Bool
False Bool
True Bool
False String
"> " Maybe String
forall a. Maybe a
Nothing Bool
False Bool
True
cmdParser :: ParserInfo EgisonOpts
cmdParser :: ParserInfo EgisonOpts
cmdParser = Parser EgisonOpts -> InfoMod EgisonOpts -> ParserInfo EgisonOpts
forall a. Parser a -> InfoMod a -> ParserInfo a
info (Parser (EgisonOpts -> EgisonOpts)
forall a. Parser (a -> a)
helper Parser (EgisonOpts -> EgisonOpts)
-> Parser EgisonOpts -> Parser EgisonOpts
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser EgisonOpts
cmdArgParser)
(InfoMod EgisonOpts -> ParserInfo EgisonOpts)
-> InfoMod EgisonOpts -> ParserInfo EgisonOpts
forall a b. (a -> b) -> a -> b
$ InfoMod EgisonOpts
forall a. InfoMod a
fullDesc
InfoMod EgisonOpts -> InfoMod EgisonOpts -> InfoMod EgisonOpts
forall a. Semigroup a => a -> a -> a
<> String -> InfoMod EgisonOpts
forall a. String -> InfoMod a
header String
"The Egison Programming Language"
cmdArgParser :: Parser EgisonOpts
cmdArgParser :: Parser EgisonOpts
cmdArgParser = Maybe (String, [String])
-> Bool
-> Maybe String
-> Maybe String
-> [(String, String)]
-> [String]
-> [String]
-> Maybe String
-> Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts
EgisonOpts
(Maybe (String, [String])
-> Bool
-> Maybe String
-> Maybe String
-> [(String, String)]
-> [String]
-> [String]
-> Maybe String
-> Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
-> Parser (Maybe (String, [String]))
-> Parser
(Bool
-> Maybe String
-> Maybe String
-> [(String, String)]
-> [String]
-> [String]
-> Maybe String
-> Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser (String, [String]) -> Parser (Maybe (String, [String]))
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional ((,) (String -> [String] -> (String, [String]))
-> Parser String -> Parser ([String] -> (String, [String]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mod ArgumentFields String -> Parser String
forall s. IsString s => Mod ArgumentFields s -> Parser s
strArgument (String -> Mod ArgumentFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"FILE") Parser ([String] -> (String, [String]))
-> Parser [String] -> Parser (String, [String])
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser String -> Parser [String]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (Mod ArgumentFields String -> Parser String
forall s. IsString s => Mod ArgumentFields s -> Parser s
strArgument (String -> Mod ArgumentFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"ARGS")))
Parser
(Bool
-> Maybe String
-> Maybe String
-> [(String, String)]
-> [String]
-> [String]
-> Maybe String
-> Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
-> Parser Bool
-> Parser
(Maybe String
-> Maybe String
-> [(String, String)]
-> [String]
-> [String]
-> Maybe String
-> Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mod FlagFields Bool -> Parser Bool
switch
(Char -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'v'
Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"version"
Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields Bool
forall (f :: * -> *) a. String -> Mod f a
help String
"Show version number")
Parser
(Maybe String
-> Maybe String
-> [(String, String)]
-> [String]
-> [String]
-> Maybe String
-> Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
-> Parser (Maybe String)
-> Parser
(Maybe String
-> [(String, String)]
-> [String]
-> [String]
-> Maybe String
-> Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser String -> Parser (Maybe String)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
(Char -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'e'
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"eval"
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"EXPR"
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Evaluate the argument string"))
Parser
(Maybe String
-> [(String, String)]
-> [String]
-> [String]
-> Maybe String
-> Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
-> Parser (Maybe String)
-> Parser
([(String, String)]
-> [String]
-> [String]
-> Maybe String
-> Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser String -> Parser (Maybe String)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
(Char -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'c'
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"command"
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"EXPR"
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Execute the argument string"))
Parser
([(String, String)]
-> [String]
-> [String]
-> Maybe String
-> Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
-> Parser [(String, String)]
-> Parser
([String]
-> [String]
-> Maybe String
-> Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (String, String) -> Parser [(String, String)]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (ReadM (String, String)
-> Mod OptionFields (String, String) -> Parser (String, String)
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM (String, String)
readFieldOption
(Char -> Mod OptionFields (String, String)
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'F'
Mod OptionFields (String, String)
-> Mod OptionFields (String, String)
-> Mod OptionFields (String, String)
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields (String, String)
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"field"
Mod OptionFields (String, String)
-> Mod OptionFields (String, String)
-> Mod OptionFields (String, String)
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields (String, String)
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"FIELD"
Mod OptionFields (String, String)
-> Mod OptionFields (String, String)
-> Mod OptionFields (String, String)
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields (String, String)
forall (f :: * -> *) a. String -> Mod f a
help String
"Field information"))
Parser
([String]
-> [String]
-> Maybe String
-> Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
-> Parser [String]
-> Parser
([String]
-> Maybe String
-> Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser String -> Parser [String]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
(Char -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'L'
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"load-library"
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"FILE"
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Load library"))
Parser
([String]
-> Maybe String
-> Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
-> Parser [String]
-> Parser
(Maybe String
-> Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser String -> Parser [String]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
(Char -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'l'
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"load-file"
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"FILE"
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Load file"))
Parser
(Maybe String
-> Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
-> Parser (Maybe String)
-> Parser
(Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser String -> Parser (Maybe String)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
(Char -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
's'
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"substitute"
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"EXPR"
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Operate input in tsv format as infinite stream"))
Parser
(Maybe String
-> Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
-> Parser (Maybe String)
-> Parser
(Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser String -> Parser (Maybe String)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
(Char -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'm'
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"map"
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"EXPR"
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Operate input in tsv format line by line"))
Parser
(Maybe String
-> Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
-> Parser (Maybe String)
-> Parser
(Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser String -> Parser (Maybe String)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
(Char -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'f'
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"filter"
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"EXPR"
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Filter input in tsv format line by line"))
Parser
(Bool
-> Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
-> Parser Bool
-> Parser
(Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mod FlagFields Bool -> Parser Bool
switch
(Char -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'T'
Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"tsv"
Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields Bool
forall (f :: * -> *) a. String -> Mod f a
help String
"Output in tsv format")
Parser
(Bool
-> Bool
-> Bool
-> String
-> Maybe String
-> Bool
-> Bool
-> EgisonOpts)
-> Parser Bool
-> Parser
(Bool
-> Bool -> String -> Maybe String -> Bool -> Bool -> EgisonOpts)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mod FlagFields Bool -> Parser Bool
switch
(String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"no-io"
Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields Bool
forall (f :: * -> *) a. String -> Mod f a
help String
"Prohibit all io primitives")
Parser
(Bool
-> Bool -> String -> Maybe String -> Bool -> Bool -> EgisonOpts)
-> Parser Bool
-> Parser
(Bool -> String -> Maybe String -> Bool -> Bool -> EgisonOpts)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> Bool -> Mod FlagFields Bool -> Parser Bool
forall a. a -> a -> Mod FlagFields a -> Parser a
flag Bool
True Bool
False
(String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"no-banner"
Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields Bool
forall (f :: * -> *) a. String -> Mod f a
help String
"Do not display banner")
Parser
(Bool -> String -> Maybe String -> Bool -> Bool -> EgisonOpts)
-> Parser Bool
-> Parser (String -> Maybe String -> Bool -> Bool -> EgisonOpts)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mod FlagFields Bool -> Parser Bool
switch
(Char -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
't'
Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"test"
Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields Bool
forall (f :: * -> *) a. String -> Mod f a
help String
"Execute only test expressions")
Parser (String -> Maybe String -> Bool -> Bool -> EgisonOpts)
-> Parser String
-> Parser (Maybe String -> Bool -> Bool -> EgisonOpts)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
(Char -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'p'
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"prompt"
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"STRING"
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value String
"> "
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Set prompt string")
Parser (Maybe String -> Bool -> Bool -> EgisonOpts)
-> Parser (Maybe String) -> Parser (Bool -> Bool -> EgisonOpts)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser String -> Parser (Maybe String)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
(Char -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'M'
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"math"
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"(asciimath|latex|mathematica|maxima)"
Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Output in AsciiMath, Latex, Mathematica, or Maxima format"))
Parser (Bool -> Bool -> EgisonOpts)
-> Parser Bool -> Parser (Bool -> EgisonOpts)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> Bool -> Mod FlagFields Bool -> Parser Bool
forall a. a -> a -> Mod FlagFields a -> Parser a
flag Bool
False Bool
True
(Char -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'S'
Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"sexpr-syntax"
Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields Bool
forall (f :: * -> *) a. String -> Mod f a
help String
"Use s-expression syntax")
Parser (Bool -> EgisonOpts) -> Parser Bool -> Parser EgisonOpts
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> Bool -> Mod FlagFields Bool -> Parser Bool
forall a. a -> a -> Mod FlagFields a -> Parser a
flag Bool
True Bool
False
(String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"no-normalize"
Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields Bool
forall (f :: * -> *) a. String -> Mod f a
help String
"Turn off normalization of math expressions")
readFieldOption :: ReadM (String, String)
readFieldOption :: ReadM (String, String)
readFieldOption = (String -> Either String (String, String))
-> ReadM (String, String)
forall a. (String -> Either String a) -> ReadM a
eitherReader ((String -> Either String (String, String))
-> ReadM (String, String))
-> (String -> Either String (String, String))
-> ReadM (String, String)
forall a b. (a -> b) -> a -> b
$ \String
str ->
case Parsec String () (String, String)
-> String -> String -> Either ParseError (String, String)
forall s t a.
Stream s Identity t =>
Parsec s () a -> String -> s -> Either ParseError a
P.parse Parsec String () (String, String)
parseFieldOption String
"(argument)" String
str of
Left ParseError
err -> String -> Either String (String, String)
forall a b. a -> Either a b
Left (String -> Either String (String, String))
-> String -> Either String (String, String)
forall a b. (a -> b) -> a -> b
$ ParseError -> String
forall a. Show a => a -> String
show ParseError
err
Right (String, String)
ok -> (String, String) -> Either String (String, String)
forall a b. b -> Either a b
Right (String, String)
ok
parseFieldOption :: P.Parsec String () (String, String)
parseFieldOption :: Parsec String () (String, String)
parseFieldOption = do
String
s <- ParsecT String () Identity Char
-> ParsecT String () Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
P.many1 ParsecT String () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
P.digit
Maybe String
e <- ParsecT String () Identity String
-> ParsecT String () Identity (Maybe String)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
P.optionMaybe (Char -> ParsecT String () Identity Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
P.char Char
',' ParsecT String () Identity Char
-> ParsecT String () Identity String
-> ParsecT String () Identity String
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT String () Identity Char
-> ParsecT String () Identity String
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
P.many1 ParsecT String () Identity Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
P.digit)
let se :: [String]
se = String
s String -> [String] -> [String]
forall a. a -> [a] -> [a]
: Maybe String -> [String]
forall a. Maybe a -> [a]
maybeToList Maybe String
e
([String]
rs, [String]
rc)
<- ParsecT String () Identity String
-> ParsecT String () Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
P.try (String -> ParsecT String () Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
P.string String
"sc") ParsecT String () Identity String
-> ([String], [String])
-> ParsecT String () Identity ([String], [String])
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> ([String]
se, [String]
se)
ParsecT String () Identity ([String], [String])
-> ParsecT String () Identity ([String], [String])
-> ParsecT String () Identity ([String], [String])
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT String () Identity String
-> ParsecT String () Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
P.try (String -> ParsecT String () Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
P.string String
"cs") ParsecT String () Identity String
-> ([String], [String])
-> ParsecT String () Identity ([String], [String])
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> ([String]
se, [String]
se)
ParsecT String () Identity ([String], [String])
-> ParsecT String () Identity ([String], [String])
-> ParsecT String () Identity ([String], [String])
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT String () Identity String
-> ParsecT String () Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
P.try (String -> ParsecT String () Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
P.string String
"s" ) ParsecT String () Identity String
-> ([String], [String])
-> ParsecT String () Identity ([String], [String])
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> ([String]
se, [])
ParsecT String () Identity ([String], [String])
-> ParsecT String () Identity ([String], [String])
-> ParsecT String () Identity ([String], [String])
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT String () Identity String
-> ParsecT String () Identity String
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
P.try (String -> ParsecT String () Identity String
forall s (m :: * -> *) u.
Stream s m Char =>
String -> ParsecT s u m String
P.string String
"c" ) ParsecT String () Identity String
-> ([String], [String])
-> ParsecT String () Identity ([String], [String])
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> ([], [String]
se)
ParsecT String () Identity ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
P.eof
let f :: [String] -> String
f [String]
x = String
"[" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
", " [String]
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"]"
(String, String) -> Parsec String () (String, String)
forall (m :: * -> *) a. Monad m => a -> m a
return ([String] -> String
f [String]
rs, [String] -> String
f [String]
rc)