Changeset 4 for src/Shell.hs

Show
Ignore:
Timestamp:
02/06/05 20:01:10 (4 years ago)
Author:
autrijus
svk:copy_cache_prev:
1041
Message:

* This be 6.0.0.

Files:
1 modified

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 
     13module Shell where 
     14import Internals 
     15import AST 
     16 
    217#define READLINE 1 
    318#include "config.h" 
    419 
    5 {------------------------------------------------------------------------------- 
    6  
    7         Copyright:              Bernie Pope 2004 
    8  
    9         Module:                 Shell 
    10  
    11         Description:            The Baskell interpreter command line.  
    12  
    13         Primary Authors:        Bernie Pope 
    14  
    15         Notes:  
    16  
    17         Will use GNU readline if it is available.  
    18  
    19 -------------------------------------------------------------------------------} 
    20  
    21 module Shell  
    22    ( Command (..) 
    23    , getCommand 
    24    , initializeShell 
    25    )  
    26    where 
    27  
    28 import AST 
    29 import Char 
    3020#ifdef READLINE 
    3121import qualified System.Console.Readline as Readline 
    32    ( readline 
    33    , addHistory 
    34    , initialize 
    35    ) 
    3622#endif 
    37  
    38 -------------------------------------------------------------------------------- 
    3923 
    4024data Command 
     
    4630   | Type Exp  
    4731   | Help 
    48 #ifdef DEBUG 
    49    | ShowAST 
    50    | ShowDepend 
    51 #endif 
    5232 
    5333-- read some input from the user 
    5434-- parse the input and return the corresponding command 
    5535getCommand :: 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 
     36getCommand = do 
     37    input <- readline "pugs> "  
     38    doCommand input 
     39 
     40doCommand Nothing = return Quit 
     41doCommand (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 
    6648 
    6749parseCommandLine :: String -> Command  
     
    7052parseCommandLine (':':'q':_)    = Quit 
    7153parseCommandLine (':':'h':_)    = Help 
    72 parseCommandLine (':':'b':_)    = Browse 
    73 parseCommandLine (':':'l':str)  = Load . unwords . tail $ words str 
     54-- parseCommandLine (':':'b':_)    = Browse 
     55-- parseCommandLine (':':'l':str)  = Load . unwords . tail $ words str 
    7456parseCommandLine str            = Eval str 
    75  
    76 -------------------------------------------------------------------------------- 
    77  
    78 -- optional support for GNU Readline   
    7957 
    8058initializeShell :: IO ()