Changeset 4 for src/Shell.hs
- Timestamp:
- 02/06/05 20:01:10 (4 years ago)
- svk:copy_cache_prev:
- 1041
- Files:
-
- 1 modified
-
src/Shell.hs (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Shell.hs
r1 r4 1 {-# OPTIONS -cpp #-} 1 {-# OPTIONS -fglasgow-exts -cpp #-} 2 3 {- 4 Interactive shell. 5 6 There is an inn, a merry old inn, 7 beneath an old grey hill, 8 And there they brew a beer so brown 9 That the Man in the Moon himself came down 10 one night to drink his fill... 11 -} 12 13 module Shell where 14 import Internals 15 import AST 16 2 17 #define READLINE 1 3 18 #include "config.h" 4 19 5 {-------------------------------------------------------------------------------6 7 Copyright: Bernie Pope 20048 9 Module: Shell10 11 Description: The Baskell interpreter command line.12 13 Primary Authors: Bernie Pope14 15 Notes:16 17 Will use GNU readline if it is available.18 19 -------------------------------------------------------------------------------}20 21 module Shell22 ( Command (..)23 , getCommand24 , initializeShell25 )26 where27 28 import AST29 import Char30 20 #ifdef READLINE 31 21 import qualified System.Console.Readline as Readline 32 ( readline33 , addHistory34 , initialize35 )36 22 #endif 37 38 --------------------------------------------------------------------------------39 23 40 24 data Command … … 46 30 | Type Exp 47 31 | Help 48 #ifdef DEBUG49 | ShowAST50 | ShowDepend51 #endif52 32 53 33 -- read some input from the user 54 34 -- parse the input and return the corresponding command 55 35 getCommand :: IO Command 56 getCommand 57 = do input <- readline "pugs> " 58 case input of 59 Nothing -> return Quit 60 Just line 61 -> if all isSpace line 62 then getCommand 63 else do 64 addHistory line 65 return $ parseCommandLine line 36 getCommand = do 37 input <- readline "pugs> " 38 doCommand input 39 40 doCommand Nothing = return Quit 41 doCommand (Just line) 42 | all isSpace line = getCommand 43 | (s, _) <- break (== '#') line 44 , all isSpace s = getCommand 45 | otherwise = do 46 addHistory line 47 return $ parseCommandLine line 66 48 67 49 parseCommandLine :: String -> Command … … 70 52 parseCommandLine (':':'q':_) = Quit 71 53 parseCommandLine (':':'h':_) = Help 72 parseCommandLine (':':'b':_) = Browse73 parseCommandLine (':':'l':str) = Load . unwords . tail $ words str54 -- parseCommandLine (':':'b':_) = Browse 55 -- parseCommandLine (':':'l':str) = Load . unwords . tail $ words str 74 56 parseCommandLine str = Eval str 75 76 --------------------------------------------------------------------------------77 78 -- optional support for GNU Readline79 57 80 58 initializeShell :: IO ()
