@@ -0,0 +1,79 @@
1+-----------------------------------------------------------------------------
8+-- Stability : experimental
12+-- Directives for PSCI.
14+-----------------------------------------------------------------------------
16+module Directive where
18+import Control.Applicative
19+import Data.List (find, isPrefixOf)
33+-- Maps given directive relating command strings.
35+commands :: Directive -> [String]
36+commands Help = ["?", "help"]
37+commands Quit = ["quit"]
38+commands Reset = ["reset"]
39+commands Import = ["import"]
40+commands Browse = ["browse"]
41+commands Load = ["load", "module"]
42+commands Type = ["type"]
43+commands Kind = ["kind"]
44+commands Show = ["show"]
47+-- Tries to parse given string into a directive.
49+parseDirective :: String -> Maybe Directive
50+parseDirective cmd = fst <$> find (matches . snd) mapping
52+ mapping :: [(Directive, [String])]
53+ mapping = zip directives (map commands directives)
55+ matches :: [String] -> Bool
56+ matches = any (cmd `isPrefixOf`)
61+help :: [(Directive, String, String)]
63+ [ (Help, "", "Show this help menu")
64+ , (Quit, "", "Quit PSCi")
65+ , (Reset, "", "Reset")
66+ , (Import, "<module>", "Import <module> for use in PSCI")
67+ , (Browse, "<module>", "Browse <module>")
68+ , (Load, "<file>", "Load <file> for importing")
69+ , (Type, "<expr>", "Show the type of <expr>")
70+ , (Kind, "<type>", "Show the kind of <type>")
71+ , (Show, "import", "Show imported modules")
72+ , (Show, "loaded", "Show loaded modules")
76+-- List of all avaliable directives.
78+directives :: [Directive]
79+directives = map (\(dir, _, _) -> dir) help