on master help sign in
Merge pull request #258 from hannesm/reduce-code-duplication
22001e5Edwin Brady
src/Idris/Completion.hs+5−5
@@ -16,10 +16,10 @@ import Data.Maybe
16import System.Console.Haskeline
16import System.Console.Haskeline
17
17
18
18
19−fst4 :: (a, b, c, d) -> a
19+fst3 :: (a, b, c) -> a
20−fst4 (a, b, c, d) = a
20+fst3 (a, b, c) = a
21
21
22−commands = concatMap fst4 help
22+commands = concatMap fst3 help
23
23
24-- | A specification of the arguments that tactics can take
24-- | A specification of the arguments that tactics can take
25data TacticArg = NameTArg -- ^ Names: n1, n2, n3, ... n
25data TacticArg = NameTArg -- ^ Names: n1, n2, n3, ... n
@@ -98,8 +98,8 @@ isWhitespace = (flip elem) " \t\n"
98
98
99lookupInHelp :: String -> Maybe CmdArg
99lookupInHelp :: String -> Maybe CmdArg
100lookupInHelp cmd = lookupInHelp' cmd help
100lookupInHelp cmd = lookupInHelp' cmd help
101− where lookupInHelp' cmd ((cmds, _, _, arg):xs) | elem cmd cmds = Just arg
101+ where lookupInHelp' cmd ((cmds, arg, _):xs) | elem cmd cmds = Just arg
102− | otherwise = lookupInHelp' cmd xs
102+ | otherwise = lookupInHelp' cmd xs
103 lookupInHelp' cmd [] = Nothing
103 lookupInHelp' cmd [] = Nothing
104
104
105-- | Get the completion function for a particular command
105-- | Get the completion function for a particular command
src/Idris/Help.hs+38−28
@@ -6,34 +6,44 @@ data CmdArg = ExprArg -- ^ The command takes an expression
6 | ModuleArg -- ^ The command takes a module name
6 | ModuleArg -- ^ The command takes a module name
7 | OptionArg -- ^ The command takes an option
7 | OptionArg -- ^ The command takes an option
8 | MetaVarArg -- ^ The command takes a metavariable
8 | MetaVarArg -- ^ The command takes a metavariable
9− | NoArg -- ^ No completion yet
9+ | NoArg -- ^ No completion (yet!?)
10+ | SpecialHeaderArg -- ^ do not use
10
11
11−-- TODO: Merge the second and fourth elements of the following tuples
12+instance Show CmdArg where
13+ show ExprArg = "<expr>"
14+ show NameArg = "<name>"
15+ show FileArg = "<filename>"
16+ show ModuleArg = "<module>"
17+ show OptionArg = "<option>"
18+ show MetaVarArg = "<metavar>"
19+ show NoArg = ""
20+ show SpecialHeaderArg = "Arguments"
21+
12−help :: [([String], String, String, CmdArg)]
22+help :: [([String], CmdArg, String)]
13help =
23help =
14− [ (["<expr>"], "", "Evaluate an expression", NoArg),
24+ [ (["<expr>"], NoArg, "Evaluate an expression"),
15− ([":t"], "<expr>", "Check the type of an expression", ExprArg),
25+ ([":t"], ExprArg, "Check the type of an expression"),
16− ([":miss", ":missing"], "<name>", "Show missing clauses", NameArg),
26+ ([":miss", ":missing"], NameArg, "Show missing clauses"),
17− ([":i", ":info"], "<name>", "Display information about a type class", NameArg),
27+ ([":i", ":info"], NameArg, "Display information about a type class"),
18− ([":total"], "<name>", "Check the totality of a name", NameArg),
28+ ([":total"], NameArg, "Check the totality of a name"),
19− ([":r",":reload"], "", "Reload current file", NoArg),
29+ ([":r",":reload"], NoArg, "Reload current file"),
20− ([":l",":load"], "<filename>", "Load a new file", FileArg),
30+ ([":l",":load"], FileArg, "Load a new file"),
21− ([":m",":module"], "<module>", "Import an extra module", ModuleArg), -- NOTE: dragons
31+ ([":m",":module"], ModuleArg, "Import an extra module"), -- NOTE: dragons
22− ([":e",":edit"], "", "Edit current file using $EDITOR or $VISUAL", NoArg),
32+ ([":e",":edit"], NoArg, "Edit current file using $EDITOR or $VISUAL"),
23− ([":m",":metavars"], "", "Show remaining proof obligations (metavariables)", MetaVarArg),
33+ ([":m",":metavars"], MetaVarArg, "Show remaining proof obligations (metavariables)"),
24− ([":p",":prove"], "<name>", "Prove a metavariable", MetaVarArg),
34+ ([":p",":prove"], MetaVarArg, "Prove a metavariable"),
25− ([":a",":addproof"], "<name>", "Add proof to source file", NameArg),
35+ ([":a",":addproof"], NameArg, "Add proof to source file"),
26− ([":rmproof"], "<name>", "Remove proof from proof stack", NameArg),
36+ ([":rmproof"], NameArg, "Remove proof from proof stack"),
27− ([":showproof"], "<name>", "Show proof", NameArg),
37+ ([":showproof"], NameArg, "Show proof"),
28− ([":proofs"], "", "Show available proofs", NoArg),
38+ ([":proofs"], NoArg, "Show available proofs"),
29− ([":x"], "<expr>", "Execute IO actions resulting from an expression using the interpreter", ExprArg),
39+ ([":x"], ExprArg, "Execute IO actions resulting from an expression using the interpreter"),
30− ([":c",":compile"], "<filename>", "Compile to an executable <filename>", FileArg),
40+ ([":c",":compile"], FileArg, "Compile to an executable <filename>"),
31− ([":js", ":javascript"], "<filename>", "Compile to JavaScript <filename>", FileArg),
41+ ([":js", ":javascript"], FileArg, "Compile to JavaScript <filename>"),
32− ([":exec",":execute"], "", "Compile to an executable and run", NoArg),
42+ ([":exec",":execute"], NoArg, "Compile to an executable and run"),
33− ([":dynamic"], "<filename>", "Dynamically load a C library (similar to %dynamic)", FileArg),
43+ ([":dynamic"], FileArg, "Dynamically load a C library (similar to %dynamic)"),
34− ([":dynamic"], "", "List dynamically loaded C libraries", NoArg),
44+ ([":dynamic"], NoArg, "List dynamically loaded C libraries"),
35− ([":?",":h",":help"], "", "Display this help text", NoArg),
45+ ([":?",":h",":help"], NoArg, "Display this help text"),
36− ([":set"], "<option>", "Set an option (errorcontext, showimplicits)", OptionArg),
46+ ([":set"], OptionArg, "Set an option (errorcontext, showimplicits)"),
37− ([":unset"], "<option>", "Unset an option", OptionArg),
47+ ([":unset"], OptionArg, "Unset an option"),
38− ([":q",":quit"], "", "Exit the Idris system", NoArg)
48+ ([":q",":quit"], NoArg, "Exit the Idris system")
39 ]
49 ]
src/Idris/REPL.hs+3−3
@@ -443,7 +443,7 @@ displayHelp = let vstr = showVersion version in
443 "--------------" ++ map (\x -> '-') vstr ++ "\n\n" ++
443 "--------------" ++ map (\x -> '-') vstr ++ "\n\n" ++
444 concatMap cmdInfo helphead ++
444 concatMap cmdInfo helphead ++
445 concatMap cmdInfo help
445 concatMap cmdInfo help
446− where cmdInfo (cmds, args, text, _) = " " ++ col 16 12 (showSep " " cmds) args text
446+ where cmdInfo (cmds, args, text) = " " ++ col 16 12 (showSep " " cmds) (show args) text
447 col c1 c2 l m r =
447 col c1 c2 l m r =
448 l ++ take (c1 - length l) (repeat ' ') ++
448 l ++ take (c1 - length l) (repeat ' ') ++
449 m ++ take (c2 - length m) (repeat ' ') ++ r ++ "\n"
449 m ++ take (c2 - length m) (repeat ' ') ++ r ++ "\n"
@@ -496,8 +496,8 @@ parseArgs ("-XTypeProviders":ns) = Extension TypeProviders : (parseArgs ns)
496parseArgs (n:ns) = Filename n : (parseArgs ns)
496parseArgs (n:ns) = Filename n : (parseArgs ns)
497
497
498helphead =
498helphead =
499− [ (["Command"], "Arguments", "Purpose", ""),
499+ [ (["Command"], SpecialHeaderArg, "Purpose"),
500− ([""], "", "", "")
500+ ([""], NoArg, "")
501 ]
501 ]
502
502
503
503