diff options
author | Vladislav Zavialov <vlad.z.4096@gmail.com> | 2020-01-02 15:13:03 +0300 |
---|---|---|
committer | Vladislav Zavialov <vlad.z.4096@gmail.com> | 2020-01-02 23:05:24 +0300 |
commit | 94e45f585038c291a013295aa3298d6cf6d62dfb (patch) | |
tree | 4322ed266ab7d773ce28dc5b238f10540a75ca06 /compiler/parser/Lexer.x | |
parent | b84c09d533faf576c406ce9f7163efecf3037787 (diff) | |
download | haskell-wip/lexer-dbg.tar.gz |
Add lexerDbg to dump the tokens fed to the parserwip/lexer-dbg
This a small utility function that comes in handy when debugging the
lexer and the parser.
Diffstat (limited to 'compiler/parser/Lexer.x')
-rw-r--r-- | compiler/parser/Lexer.x | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x index fc6779a359..efae29e84e 100644 --- a/compiler/parser/Lexer.x +++ b/compiler/parser/Lexer.x @@ -49,7 +49,7 @@ {-# OPTIONS_GHC -funbox-strict-fields #-} module Lexer ( - Token(..), lexer, pragState, mkPState, mkPStatePure, PState(..), + Token(..), lexer, lexerDbg, pragState, mkPState, mkPStatePure, PState(..), P(..), ParseResult(..), mkParserFlags, mkParserFlags', ParserFlags(..), appendWarning, appendError, @@ -2808,7 +2808,8 @@ lexError str = do -- This is the top-level function: called from the parser each time a -- new token is to be read from the input. -lexer :: Bool -> (Located Token -> P a) -> P a +lexer, lexerDbg :: Bool -> (Located Token -> P a) -> P a + lexer queueComments cont = do alr <- getBit AlternativeLayoutRuleBit let lexTokenFun = if alr then lexTokenAlr else lexToken @@ -2827,6 +2828,11 @@ lexer queueComments cont = do then queueComment (L (RealSrcSpan span) tok) >> lexer queueComments cont else cont (L (RealSrcSpan span) tok) +-- Use this instead of 'lexer' in Parser.y to dump the tokens for debugging. +lexerDbg queueComments cont = lexer queueComments contDbg + where + contDbg tok = trace ("token: " ++ show (unLoc tok)) (cont tok) + lexTokenAlr :: P (RealLocated Token) lexTokenAlr = do mPending <- popPendingImplicitToken t <- case mPending of |