Commit 073f7cfd authored by Vladislav Zavialov's avatar Vladislav Zavialov Committed by Marge Bot

Add lexerDbg to dump the tokens fed to the parser

This a small utility function that comes in handy when debugging the
lexer and the parser.
parent ae6b6276
Pipeline #14217 passed with stages
in 458 minutes and 36 seconds
......@@ -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
......
......@@ -618,6 +618,8 @@ TH_QQUASIQUOTE { L _ (ITqQuasiQuote _) }
%monad { P } { >>= } { return }
%lexer { (lexer True) } { L _ ITeof }
-- Replace 'lexer' above with 'lexerDbg'
-- to dump the tokens fed to the parser.
%tokentype { (Located Token) }
-- Exported parsers
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment