summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilFreeman <>2015-03-18 16:23:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2015-03-18 16:23:00 (GMT)
commitad6f41a143ca4f20deda05bbb844f2fa330bcc94 (patch)
tree0735b812d09d458f02e9f1d11548ace781ff44a5
parent60cc603d9533094f3e224517801af909e62f0c5a (diff)
version 0.6.9.10.6.9.1
-rw-r--r--psci/Directive.hs79
-rw-r--r--purescript.cabal3
2 files changed, 81 insertions, 1 deletions
diff --git a/psci/Directive.hs b/psci/Directive.hs
new file mode 100644
index 0000000..c7bebd2
--- /dev/null
+++ b/psci/Directive.hs
@@ -0,0 +1,79 @@
+-----------------------------------------------------------------------------
+--
+-- Module : Directive
+-- Copyright :
+-- License : MIT
+--
+-- Maintainer :
+-- Stability : experimental
+-- Portability :
+--
+-- |
+-- Directives for PSCI.
+--
+-----------------------------------------------------------------------------
+
+module Directive where
+
+import Data.List (nub, isPrefixOf)
+
+data Directive
+ = Help
+ | Quit
+ | Reset
+ | Browse
+ | Load
+ | Type
+ | Kind
+ | Show
+ deriving Eq
+
+-- |
+-- Maps given directive to relating command strings.
+--
+commands :: Directive -> [String]
+commands Help = ["?", "help"]
+commands Quit = ["quit"]
+commands Reset = ["reset"]
+commands Browse = ["browse"]
+commands Load = ["load", "module"]
+commands Type = ["type"]
+commands Kind = ["kind"]
+commands Show = ["show"]
+
+-- |
+-- Tries to parse given string into a directive.
+--
+parseDirective :: String -> Maybe Directive
+parseDirective cmd =
+ case filter (matches . snd) mapping of
+ [directive] -> Just $ fst directive
+ _ -> Nothing
+ where
+ mapping :: [(Directive, [String])]
+ mapping = zip directives (map commands directives)
+
+ matches :: [String] -> Bool
+ matches = any (cmd `isPrefixOf`)
+
+-- |
+-- The help menu.
+--
+help :: [(Directive, String, String)]
+help =
+ [ (Help, "", "Show this help menu")
+ , (Quit, "", "Quit PSCi")
+ , (Reset, "", "Reset")
+ , (Browse, "<module>", "Browse <module>")
+ , (Load, "<file>", "Load <file> for importing")
+ , (Type, "<expr>", "Show the type of <expr>")
+ , (Kind, "<type>", "Show the kind of <type>")
+ , (Show, "import", "Show imported modules")
+ , (Show, "loaded", "Show loaded modules")
+ ]
+
+-- |
+-- List of all avaliable directives.
+--
+directives :: [Directive]
+directives = nub . map (\(dir, _, _) -> dir) $ help
diff --git a/purescript.cabal b/purescript.cabal
index 9f31d36..fb6e028 100644
--- a/purescript.cabal
+++ b/purescript.cabal
@@ -1,5 +1,5 @@
name: purescript
-version: 0.6.9
+version: 0.6.9.1
cabal-version: >=1.8
build-type: Simple
license: MIT
@@ -151,6 +151,7 @@ executable psci
hs-source-dirs: psci
other-modules: Commands
Parser
+ Directive
ghc-options: -Wall -O2
executable psc-docs