Skip to content

Commit

Permalink
refactor: removed Internal qualifier for RT
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 committed Apr 8, 2024
1 parent efee893 commit 229104e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions src/Text/Gigaparsec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ import Text.Gigaparsec.Errors.ErrorGen (vanillaGen)
import Data.Functor (void)
import Control.Applicative (liftA2, (<|>), empty, many, some, (<**>)) -- liftA2 required until 9.6

Check warning on line 93 in src/Text/Gigaparsec.hs

View workflow job for this annotation

GitHub Actions / GHC latest, Cabal latest

The import of ‘liftA2’

Check warning on line 93 in src/Text/Gigaparsec.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6, Cabal latest

The import of ‘liftA2’

Check warning on line 93 in src/Text/Gigaparsec.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6, Cabal latest

The import of ‘liftA2’
import Control.Selective (select, branch)
import Control.Monad.RT qualified as Internal (RT, runRT, rtToIO)
import Control.Monad.RT (RT, runRT, rtToIO)

import Data.Set qualified as Set (singleton, empty)
import GHC.Generics (Generic)
Expand Down Expand Up @@ -137,7 +137,7 @@ parse :: forall err a. ErrorBuilder err
=> Parsec a -- ^ the parser to execute
-> String -- ^ the input to parse
-> Result err a -- ^ result of the parse, either an error or result
parse p inp = Internal.runRT $ _parse Nothing p inp
parse p inp = runRT $ _parse Nothing p inp

{-|
Runs a parser against some input, pretty-printing the result to the terminal.
Expand All @@ -154,7 +154,7 @@ parseRepl :: Show a
-> String -- ^ the input to parse
-> IO ()
parseRepl p inp =
do res <- Internal.rtToIO $ _parse Nothing p inp
do res <- rtToIO $ _parse Nothing p inp
result putStrLn print res

{-# SPECIALISE parseFromFile :: Parsec a -> String -> IO (Result String a) #-}
Expand All @@ -180,16 +180,16 @@ parseFromFile :: forall err a. ErrorBuilder err
-> IO (Result err a) -- ^ the result of the parse, error or otherwise
parseFromFile p f =
do inp <- readFile f
Internal.rtToIO $ _parse (Just f) p inp
rtToIO $ _parse (Just f) p inp

--TODO: parseFromHandle?

{-# INLINE _parse #-}
_parse :: forall err a. ErrorBuilder err => Maybe FilePath -> Parsec a -> String -> Internal.RT (Result err a)
_parse :: forall err a. ErrorBuilder err => Maybe FilePath -> Parsec a -> String -> RT (Result err a)
_parse file (Parsec p) inp = p (emptyState inp) good bad
where good :: a -> Internal.State -> Internal.RT (Result err a)
where good :: a -> Internal.State -> RT (Result err a)
good x _ = return (Success x)
bad :: Internal.Error -> Internal.State -> Internal.RT (Result err a)
bad :: Internal.Error -> Internal.State -> RT (Result err a)
bad err _ = return (Failure (Internal.fromError file inp err))

{-|
Expand Down
14 changes: 7 additions & 7 deletions src/Text/Gigaparsec/Debug.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Text.Gigaparsec.Internal qualified as Internal

import Data.Ref (Ref, readRef)
import Control.Monad (when, forM)
import Control.Monad.RT.Unsafe qualified as Internal
import Control.Monad.RT.Unsafe (RT, unsafeIOToRT)
import System.IO (hGetEcho, hSetEcho, hPutStr, stdin, stdout, Handle)
import Data.List (intercalate, isPrefixOf)
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
Expand Down Expand Up @@ -94,7 +94,7 @@ on either entry, exit, or both. The parse is resumed by entering any character o
debugWith :: DebugConfig -> String -> Parsec a -> Parsec a
debugWith config@DebugConfig{ascii} name (Internal.Parsec p) = Internal.Parsec $ \st good bad -> do
-- TODO: could make it so the postamble can print input information from the entry?
ascii' <- (\colourful -> ascii || not colourful) <$> Internal.unsafeIOToRT supportsPretty
ascii' <- (\colourful -> ascii || not colourful) <$> unsafeIOToRT supportsPretty
let config' = config { ascii = ascii' }
doDebug name Enter st "" config'
let good' x st' = do
Expand Down Expand Up @@ -127,12 +127,12 @@ shouldBreak :: Direction -> Break -> Bool
shouldBreak Enter = breakOnEntry
shouldBreak Exit = breakOnExit

doDebug :: String -> Direction -> Internal.State -> String -> DebugConfig -> Internal.RT ()
doDebug :: String -> Direction -> Internal.State -> String -> DebugConfig -> RT ()
doDebug name dir st end DebugConfig{..} = do
printInfo handle name dir st end ascii watchedRegs
when (shouldBreak dir breakPoint) waitForUser

printInfo :: Handle -> String -> Direction -> Internal.State -> String -> Bool -> [WatchedReg] -> Internal.RT ()
printInfo :: Handle -> String -> Direction -> Internal.State -> String -> Bool -> [WatchedReg] -> RT ()
printInfo handle name dir st@Internal.State{input, line, col} end ascii regs = do
let cs = replace "\n" (newline ascii)
. replace " " (space ascii)
Expand All @@ -147,11 +147,11 @@ printInfo handle name dir st@Internal.State{input, line, col} end ascii regs = d
else (++ [""]) . ("watched registers:" :) <$>
forM regs (\(WatchedReg rname reg) ->
(\x -> " " ++ rname ++ " = " ++ show x) <$> readRef reg)
Internal.unsafeIOToRT $
unsafeIOToRT $
hPutStr handle $ indentAndUnlines st ((prelude ++ cs' ++ end) : caret : regSummary)

waitForUser :: Internal.RT ()
waitForUser = Internal.unsafeIOToRT $ do
waitForUser :: RT ()
waitForUser = unsafeIOToRT $ do
echo <- hGetEcho stdin
hSetEcho stdin False
putStrLn "..."
Expand Down

0 comments on commit 229104e

Please sign in to comment.