hscParseThingWithLocation :: (Outputable thing, Data thing) => String -> Int
                          -> Lexer.P thing -> String -> Hsc thing
hscParseThingWithLocation source linenumber parser str
  = {-# SCC "Parser" #-} do
    -- withTiming getDynFlags
    --            (text "Parser [source]")
    --            (const ()) $
    dflags <- getDynFlags
    liftIO $ showPass dflags "Parser"

    let buf = stringToStringBuffer str
        loc = mkRealSrcLoc (fsLit source) linenumber 1

    case unP parser (mkPState dflags buf loc) of
        PFailed span err ->
              liftIO $ throwOneError (mkPlainErrMsg dflags span err)
        -- PFailed warnFn span err -> do
        --     logWarningsReportErrors (warnFn dflags)
        --     handleWarnings
        --     let msg = mkPlainErrMsg dflags span err
        --     throwErrors $ unitBag msg

        POk pst thing -> do
            logWarningsReportErrors (getMessages pst)
            liftIO $ dumpIfSet_dyn dflags Opt_D_dump_parsed "Parser" (ppr thing)
            return thing
        -- POk pst thing -> do
        --     logWarningsReportErrors (getMessages pst dflags)
        --     liftIO $ dumpIfSet_dyn dflags Opt_D_dump_parsed "Parser" (ppr thing)
            -- liftIO $ dumpIfSet_dyn dflags Opt_D_dump_parsed_ast "Parser AST" $
            --                        showAstData NoBlankSrcSpan thing
            -- return thing
hscParseThingWithLocation :: (Outputable thing, Data thing) => String -> Int
                          -> Lexer.P thing -> String -> Hsc thing
hscParseThingWithLocation source linenumber parser str
  = {-# SCC "Parser" #-} do
    -- withTiming getDynFlags
    --            (text "Parser [source]")
    --            (const ()) $
    dflags <- getDynFlags
    liftIO $ showPass dflags "Parser"

    let buf = stringToStringBuffer str
        loc = mkRealSrcLoc (fsLit source) linenumber 1

    case unP parser (mkPState dflags buf loc) of
        PFailed span err ->
              liftIO $ throwOneError (mkPlainErrMsg dflags span err)
        -- PFailed warnFn span err -> do
        --     logWarningsReportErrors (warnFn dflags)
        --     handleWarnings
        --     let msg = mkPlainErrMsg dflags span err
        --     throwErrors $ unitBag msg

        POk pst thing -> do
            logWarningsReportErrors (getMessages pst)
            liftIO $ dumpIfSet_dyn dflags Opt_D_dump_parsed "Parser" (ppr thing)
            return thing
        -- POk pst thing -> do
        --     logWarningsReportErrors (getMessages pst dflags)
        --     liftIO $ dumpIfSet_dyn dflags Opt_D_dump_parsed "Parser" (ppr thing)
            -- liftIO $ dumpIfSet_dyn dflags Opt_D_dump_parsed_ast "Parser AST" $
            --                        showAstData NoBlankSrcSpan thing
            -- return thing
hscParseThingWithLocation source linenumber parser str
  = {-# SCC "Parser" #-} do
    -- withTiming getDynFlags
    --            (text "Parser [source]")
    --            (const ()) $
    dflags <- getDynFlags
    liftIO $ showPass dflags "Parser"

    let buf = stringToStringBuffer str
        loc = mkRealSrcLoc (fsLit source) linenumber 1

    case unP parser (mkPState dflags buf loc) of
        PFailed span err ->
              liftIO $ throwOneError (mkPlainErrMsg dflags span err)
        -- PFailed warnFn span err -> do
        --     logWarningsReportErrors (warnFn dflags)
        --     handleWarnings
        --     let msg = mkPlainErrMsg dflags span err
        --     throwErrors $ unitBag msg

        POk pst thing -> do
            logWarningsReportErrors (getMessages pst)
            liftIO $ dumpIfSet_dyn dflags Opt_D_dump_parsed "Parser" (ppr thing)
            return thing
        -- POk pst thing -> do
        --     logWarningsReportErrors (getMessages pst dflags)
        --     liftIO $ dumpIfSet_dyn dflags Opt_D_dump_parsed "Parser" (ppr thing)
            -- liftIO $ dumpIfSet_dyn dflags Opt_D_dump_parsed_ast "Parser AST" $
            --                        showAstData NoBlankSrcSpan thing
            -- return thing