Skip to content

Commit 13bcc2a

Browse files
committed
merge
2 parents 8962de4 + 36ed84e commit 13bcc2a

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

hs-src/Interpreter/egison.hs

+26-20
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,12 @@ defaultOptions = Options {
112112

113113
options :: [OptDescr (Options -> Options)]
114114
options = [
115-
Option ['v', 'V'] ["version"]
116-
(NoArg (\opts -> opts {optShowVersion = True}))
117-
"show version number",
118115
Option ['h', '?'] ["help"]
119116
(NoArg (\opts -> opts {optShowHelp = True}))
120117
"show usage information",
121-
Option ['T'] ["tsv"]
122-
(NoArg (\opts -> opts {optTsvOutput = True}))
123-
"output in tsv format",
124-
Option ['e'] ["eval"]
125-
(ReqArg (\expr opts -> opts {optEvalString = Just expr})
126-
"String")
127-
"eval the argument string",
128-
Option ['c'] ["command"]
129-
(ReqArg (\expr opts -> opts {optExecuteString = Just expr})
130-
"String")
131-
"execute the argument string",
118+
Option ['v', 'V'] ["version"]
119+
(NoArg (\opts -> opts {optShowVersion = True}))
120+
"show version number",
132121
Option ['L'] ["load-library"]
133122
(ReqArg (\d opts -> opts {optLoadLibs = optLoadLibs opts ++ [d]})
134123
"[String]")
@@ -140,16 +129,24 @@ options = [
140129
Option [] ["no-io"]
141130
(NoArg (\opts -> opts {optNoIO = True}))
142131
"prohibit all io primitives",
132+
Option ['p'] ["prompt"]
133+
(ReqArg (\prompt opts -> opts {optPrompt = prompt})
134+
"String")
135+
"set prompt string",
143136
Option [] ["no-banner"]
144137
(NoArg (\opts -> opts {optShowBanner = False}))
145138
"do not display banner",
146139
Option ['t'] ["test"]
147140
(NoArg (\opts -> opts {optTestOnly = True}))
148141
"execute only test expressions",
149-
Option ['p'] ["prompt"]
150-
(ReqArg (\prompt opts -> opts {optPrompt = prompt})
142+
Option ['e'] ["eval"]
143+
(ReqArg (\expr opts -> opts {optEvalString = Just expr})
151144
"String")
152-
"set prompt string",
145+
"eval the argument string",
146+
Option ['c'] ["command"]
147+
(ReqArg (\expr opts -> opts {optExecuteString = Just expr})
148+
"String")
149+
"execute the argument string",
153150
Option ['s'] ["substitute"]
154151
(ReqArg (\expr opts -> opts {optSubstituteString = Just expr})
155152
"String")
@@ -162,6 +159,9 @@ options = [
162159
(ReqArg (\expr opts -> opts {optSubstituteString = Just ("(filter " ++ expr ++ " $)")})
163160
"String")
164161
"filter strings",
162+
Option ['T'] ["tsv"]
163+
(NoArg (\opts -> opts {optTsvOutput = True}))
164+
"output in tsv format",
165165
Option ['F'] ["--field"]
166166
(ReqArg (\d opts -> opts {optFieldInfo = optFieldInfo opts ++ [(readFieldOption d)]})
167167
"String")
@@ -218,11 +218,17 @@ printHelp = do
218218
putStrLn " --substitute, -s expr Substitute input using the argument expression"
219219
putStrLn " --map, -m expr Substitute each line of input using the argument expression"
220220
putStrLn " --filter, -f expr Filter each line of input using the argument predicate"
221+
putStrLn ""
222+
putStrLn "Options to change input or output format:"
223+
putStrLn " --tsv, -T Input and output in tsv format"
224+
putStrLn " --field, -F field Specify a field type of input tsv"
225+
putStrLn " --math, -M (asciimath|latex|mathematica)"
226+
putStrLn " Output in AsciiMath, LaTeX, or Mathematica format (only for interpreter)"
221227
exitWith ExitSuccess
222228

223229
printVersionNumber :: IO ()
224230
printVersionNumber = do
225-
putStrLn $ showVersion version
231+
putStrLn $ showVersion version
226232
exitWith ExitSuccess
227233

228234
showBanner :: IO ()
@@ -244,9 +250,9 @@ repl noIOFlag isSExpr mathExprLang env prompt = do
244250
where
245251
settings :: MonadIO m => FilePath -> Settings m
246252
settings home = setComplete completeEgison $ defaultSettings { historyFile = Just (home </> ".egison_history") }
247-
253+
248254
loop :: Env -> IO ()
249-
loop env = (do
255+
loop env = (do
250256
home <- getHomeDirectory
251257
input <- liftIO $ runInputT (settings home) $ getEgisonExpr isSExpr prompt
252258
case (noIOFlag, input) of

hs-src/Language/Egison/MathOutput.hs

+10-7
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import Text.ParserCombinators.Parsec hiding (spaces)
1515
mathExprToHaskell :: String -> String
1616
mathExprToHaskell input = case parse parseExpr "math-expr" input of
1717
Left err -> input
18-
Right val -> "#haskell\"" ++ show val ++ "\""
18+
Right val -> "#haskell|" ++ show val ++ "|#"
1919

2020
mathExprToAsciiMath :: String -> String
2121
mathExprToAsciiMath input = case parse parseExpr "math-expr" input of
2222
Left err -> input
23-
Right val -> "#asciimath\"" ++ showMathExprAsciiMath val ++ "\""
23+
Right val -> "#asciimath|" ++ showMathExprAsciiMath val ++ "|#"
2424

2525
mathExprToLatex :: String -> String
2626
mathExprToLatex input = case parse parseExpr "math-expr" input of
@@ -63,8 +63,9 @@ showMathExprAsciiMath (Plus (x:xs)) = showMathExprAsciiMath x ++ showMathExprAsc
6363
showMathExprAsciiMathForPlus :: [MathExpr] -> String
6464
showMathExprAsciiMathForPlus [] = ""
6565
showMathExprAsciiMathForPlus ((NegativeAtom a):xs) = " - " ++ a ++ showMathExprAsciiMathForPlus xs
66+
showMathExprAsciiMathForPlus ((Multiply (NegativeAtom "1":ys)):xs) = " - " ++ showMathExprAsciiMath (Multiply ys) ++ showMathExprAsciiMathForPlus xs
6667
showMathExprAsciiMathForPlus ((Multiply (NegativeAtom a:ys)):xs) = " - " ++ showMathExprAsciiMath (Multiply ((Atom a []):ys)) ++ " " ++ showMathExprAsciiMathForPlus xs
67-
showMathExprAsciiMathForPlus (x:xs) = showMathExprAsciiMath x ++ " + " ++ showMathExprAsciiMathForPlus xs
68+
showMathExprAsciiMathForPlus (x:xs) = " + " ++ showMathExprAsciiMath x ++ showMathExprAsciiMathForPlus xs
6869
showMathExprAsciiMath (Multiply []) = ""
6970
showMathExprAsciiMath (Multiply [a]) = showMathExprAsciiMath a
7071
showMathExprAsciiMath (Multiply (NegativeAtom "1":lvs)) = "-" ++ showMathExprAsciiMath (Multiply lvs)
@@ -130,6 +131,7 @@ showMathExprLatex (Plus (x:xs)) = showMathExprLatex x ++ showMathExprLatexForPlu
130131
showMathExprLatexForPlus :: [MathExpr] -> String
131132
showMathExprLatexForPlus [] = ""
132133
showMathExprLatexForPlus ((NegativeAtom a):xs) = " - " ++ a ++ showMathExprLatexForPlus xs
134+
showMathExprLatexForPlus ((Multiply (NegativeAtom "1":ys)):xs) = " - " ++ showMathExprLatex (Multiply ys) ++ showMathExprLatexForPlus xs
133135
showMathExprLatexForPlus ((Multiply (NegativeAtom a:ys)):xs) = " - " ++ showMathExprLatex (Multiply ((Atom a []):ys)) ++ showMathExprLatexForPlus xs
134136
showMathExprLatexForPlus (x:xs) = " + " ++ showMathExprLatex x ++ showMathExprLatexForPlus xs
135137
showMathExprLatex (Multiply []) = ""
@@ -193,6 +195,7 @@ showMathExprMathematica (Plus (x:xs)) = showMathExprMathematica x ++ showMathExp
193195
showMathExprMathematicaForPlus :: [MathExpr] -> String
194196
showMathExprMathematicaForPlus [] = ""
195197
showMathExprMathematicaForPlus ((NegativeAtom a):xs) = " - " ++ a ++ showMathExprMathematicaForPlus xs
198+
showMathExprMathematicaForPlus ((Multiply (NegativeAtom "1":ys)):xs) = " - " ++ showMathExprMathematica (Multiply ys) ++ showMathExprMathematicaForPlus xs
196199
showMathExprMathematicaForPlus ((Multiply (NegativeAtom a:ys)):xs) = " - " ++ showMathExprMathematica (Multiply ((Atom a []):ys)) ++ showMathExprMathematicaForPlus xs
197200
showMathExprMathematicaForPlus (x:xs) = " + " ++ showMathExprMathematica x ++ showMathExprMathematicaForPlus xs
198201
showMathExprMathematica (Multiply []) = ""
@@ -227,7 +230,7 @@ showMathExprMathematicaArg lvs = showMathExprMathematica (head lvs) ++ ", " ++ (
227230
showMathExprMathematicaIndices :: [MathIndex] -> String
228231
showMathExprMathematicaIndices [a] = showMathIndexMathematica a
229232
showMathExprMathematicaIndices lvs = showMathIndexMathematica (head lvs) ++ showMathExprMathematicaIndices (tail lvs)
230-
233+
231234
showMathIndexMathematica :: MathIndex -> String
232235
showMathIndexMathematica (Super a) = showMathExprMathematica a
233236
showMathIndexMathematica (Sub a) = showMathExprMathematica a
@@ -247,15 +250,15 @@ symbol :: Parser Char
247250
symbol = oneOf "!$%&*+-/:<=>?@#"
248251

249252
parseAtom :: Parser MathExpr
250-
parseAtom = do
253+
parseAtom = do
251254
first <- letter <|> symbol <|> digit
252255
rest <- many (letter <|> digit <|> symbol)
253256
let atom = first : rest
254257
ys <- many parseScript
255258
return $ Atom atom ys
256259

257260
parseAtom' :: Parser MathExpr
258-
parseAtom' = do
261+
parseAtom' = do
259262
first <- letter <|> symbol <|> digit
260263
rest <- many (letter <|> digit <|> symbol)
261264
let atom = first : rest
@@ -266,7 +269,7 @@ parsePartial = do
266269
xs <- parseAtom
267270
is <- many1 (char '|' >> parseAtom)
268271
return $ Partial xs is
269-
272+
270273
parseNegativeAtom :: Parser MathExpr
271274
parseNegativeAtom = do
272275
char '-'

0 commit comments

Comments
 (0)