diff options
| author | Vivian McPhail <haskell.vivian.mcphail@gmail.com> | 2010-11-05 05:13:08 +0000 |
|---|---|---|
| committer | Vivian McPhail <haskell.vivian.mcphail@gmail.com> | 2010-11-05 05:13:08 +0000 |
| commit | 4edbeb14e25f71824c53c524028d12440928707e (patch) | |
| tree | 42aaf834306bd335e32f424829af28a1d69d6fbb /compiler/parser | |
| parent | a056bcdea7901557f8c97f0da69ae194338e550d (diff) | |
| download | haskell-4edbeb14e25f71824c53c524028d12440928707e.tar.gz | |
multiline commands in GHCi #4316
This patch adds support for multiline commands in GHCi.
The first line of input is lexed. If there is an active
layout context once the lexer reaches the end of file, the
user is prompted for more input.
Multiline input is exited by an empty line and can be escaped
with a user interrupt.
Multiline mode is toggled with `:set +m`
Diffstat (limited to 'compiler/parser')
| -rw-r--r-- | compiler/parser/Lexer.x | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x index 9237384efc..5e6535678e 100644 --- a/compiler/parser/Lexer.x +++ b/compiler/parser/Lexer.x @@ -51,6 +51,7 @@ module Lexer ( failLocMsgP, failSpanMsgP, srcParseFail, getMessages, popContext, pushCurrentContext, setLastToken, setSrcLoc, + activeContext, nextIsEOF, getLexState, popLexState, pushLexState, extension, bangPatEnabled, datatypeContextsEnabled, addWarning, @@ -1670,6 +1671,11 @@ getInput = P $ \s@PState{ loc=l, buffer=b } -> POk s (AI l b) setInput :: AlexInput -> P () setInput (AI l b) = P $ \s -> POk s{ loc=l, buffer=b } () +nextIsEOF :: P Bool +nextIsEOF = do + AI _ s <- getInput + return $ atEnd s + pushLexState :: Int -> P () pushLexState ls = P $ \s@PState{ lex_state=l } -> POk s{lex_state=ls:l} () @@ -1684,6 +1690,15 @@ popNextToken = P $ \s@PState{ alr_next_token = m } -> POk (s {alr_next_token = Nothing}) m +activeContext :: P Bool +activeContext = do + ctxt <- getALRContext + expc <- getAlrExpectingOCurly + impt <- implicitTokenPending + case (ctxt,expc) of + ([],Nothing) -> return impt + _other -> return True + setAlrLastLoc :: SrcSpan -> P () setAlrLastLoc l = P $ \s -> POk (s {alr_last_loc = l}) () @@ -1707,6 +1722,13 @@ setJustClosedExplicitLetBlock b setNextToken :: Located Token -> P () setNextToken t = P $ \s -> POk (s {alr_next_token = Just t}) () +implicitTokenPending :: P Bool +implicitTokenPending + = P $ \s@PState{ alr_pending_implicit_tokens = ts } -> + case ts of + [] -> POk s False + _ -> POk s True + popPendingImplicitToken :: P (Maybe (Located Token)) popPendingImplicitToken = P $ \s@PState{ alr_pending_implicit_tokens = ts } -> |
