Skip to content
This repository has been archived by the owner on Aug 23, 2018. It is now read-only.

Added metacommand :list #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/Completion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@ complete =
lookupCompletions :: String -> Env.Task [Completion]
lookupCompletions string =
do env <- get
let defs = adjustDefs (Env.defs env)
let defs = Trie.unionL cmds $ Env.actualDefs env
return (completions string defs)
where
adjustDefs defs =
Trie.unionL cmds $
Trie.delete Env.firstVar $
Trie.delete Env.lastVar defs

cmds =
Trie.fromList
[ (":exit", "")
Expand Down
9 changes: 9 additions & 0 deletions src/Environment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ data Config
| Help (Maybe String)
| Exit
| Reset
| List
deriving (Show, Eq)


Expand All @@ -66,6 +67,10 @@ needsPrint maybeDefName =
Just _ ->
False

getName :: DefName -> String
getName (DataDef s) = s
getName (Import s) = s
getName (VarDef s) = s


-- ENVIRONMENT
Expand All @@ -82,6 +87,10 @@ data Env = Env
deriving Show


actualDefs :: Env -> Trie String
actualDefs env = Trie.delete firstVar $
Trie.delete lastVar (defs env)

empty :: FilePath -> FilePath -> Env
empty compiler interpreter =
Env compiler
Expand Down
8 changes: 8 additions & 0 deletions src/Eval/Meta.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ module Eval.Meta (eval) where
import Control.Monad.State (get, modify)
import Control.Monad.Trans (liftIO)
import qualified Data.List as List
import Data.Maybe
import qualified Data.Trie as Trie
import System.Exit (ExitCode(ExitSuccess))

import qualified Environment as Env
import Read (extractDefName)


eval :: Env.Config -> Env.Task (Maybe ExitCode)
Expand All @@ -19,6 +22,10 @@ eval config =
do displayErr "Bad command\n" m
display helpInfo

Env.List ->
do env <- get
display $ unlines $ map Env.getName $ concatMap (maybeToList . extractDefName) $ Trie.elems $ Env.actualDefs env

Env.InfoFlags m ->
do displayErr "Bad flag\n" m
display flagsInfo
Expand Down Expand Up @@ -89,4 +96,5 @@ helpInfo =
\ :help\t\t\tList available commands\n\
\ :flags\t\tManipulate flags sent to elm compiler\n\
\ :reset\t\tClears all previous imports\n\
\ :list\t\t\tLists all defined variables\n\
\ :exit\t\t\tExits elm-repl\n"
3 changes: 2 additions & 1 deletion src/Read.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}
module Read (input) where
module Read (input, extractDefName) where

import qualified Data.Char as Char
import qualified Data.List as List
Expand Down Expand Up @@ -52,6 +52,7 @@ config =
case flag of
"exit" -> ok Env.Exit
"reset" -> ok Env.Reset
"list" -> ok Env.List
"help" -> ok (Env.Help Nothing)
"flags" -> ok (Env.InfoFlags Nothing) <|> flags
_ -> return $ Env.Help (Just flag)
Expand Down