module Language.PureScript.Interactive.Directive where
import Prelude.Compat
import Data.Maybe (fromJust, listToMaybe)
import Data.List (isPrefixOf)
import Data.Tuple (swap)
import Language.PureScript.Interactive.Types
directives :: [Directive]
directives = map fst directiveStrings
directiveStrings :: [(Directive, [String])]
directiveStrings =
[ (Help , ["?", "help"])
, (Quit , ["quit"])
, (Reload , ["reload"])
, (Clear , ["clear"])
, (Browse , ["browse"])
, (Type , ["type"])
, (Kind , ["kind"])
, (Show , ["show"])
, (Paste , ["paste"])
, (Complete , ["complete"])
, (Print , ["print"])
]
directiveStrings' :: [(String, Directive)]
directiveStrings' = concatMap go directiveStrings
where
go (dir, strs) = map (\s -> (s, dir)) strs
strings :: [String]
strings = concatMap snd directiveStrings
stringsFor :: Directive -> [String]
stringsFor d = fromJust (lookup d directiveStrings)
stringFor :: Directive -> String
stringFor = head . stringsFor
directivesFor' :: String -> [(Directive, String)]
directivesFor' str = go directiveStrings'
where
go = map swap . filter ((str `isPrefixOf`) . fst)
directivesFor :: String -> [Directive]
directivesFor = map fst . directivesFor'
directiveStringsFor :: String -> [String]
directiveStringsFor = map snd . directivesFor'
parseDirective :: String -> Maybe Directive
parseDirective = listToMaybe . directivesFor
help :: [(Directive, String, String)]
help =
[ (Help, "", "Show this help menu")
, (Quit, "", "Quit PSCi")
, (Reload, "", "Reload all imported modules while discarding bindings")
, (Clear, "", "Discard all imported modules and declared bindings")
, (Browse, "<module>", "See all functions in <module>")
, (Type, "<expr>", "Show the type of <expr>")
, (Kind, "<type>", "Show the kind of <type>")
, (Show, "import", "Show all imported modules")
, (Show, "loaded", "Show all loaded modules")
, (Show, "print", "Show the repl's current printing function")
, (Paste, "paste", "Enter multiple lines, terminated by ^D")
, (Complete, "<prefix>", "Show completions for <prefix> as if pressing tab")
, (Print, "<fn>", "Set the repl's printing function to <fn> (which must be fully qualified)")
]