content: -- File generated by the BNF Converter (bnfc 2.9.5).
  
  -- | Program to test parser.
  
  module Main where
  
  import System.Exit        ( exitFailure )
  import Control.Monad      ( when )
  import Data.Text.Lazy qualified as Text
  import TextuaL4.AbsTextuaL qualified as TL4
  import TextuaL4.Transform
  import TextuaL4.LexTextuaL   ( Token, mkPosToken )
  import TextuaL4.ParTextuaL   ( pRule, myLexer )
  import Text.Pretty.Simple (pShowNoColor)
  
  type Err        = Either String
  type ParseFun a = [Token] -> Err a
  type Verbosity  = Int
  
  putStrV :: Verbosity -> String -> IO ()
  putStrV v s = when (v > 1) $ putStrLn s
  
  run :: Verbosity -> ParseFun TL4.Rule -> String -> IO ()
  run v p s =
    case p ts of
      Left err -> do
        putStrLn "\nParse              Failed...\n"
        putStrV v "Tokens:"
        mapM_ (putStrV v . showPosToken . mkPosToken) ts
        putStrLn err
        exitFailure
      Right tree -> do
        putStrLn "\nParse Successful!"
        showTree v tree
        putStrLn "\n\n[Transformed into L4 tree]\n"
        let l4tree = transRule tree
        putStrLn $ Text.unpack $ pShowNoColor l4tree
  
   where
    ts = myLexer s
    showPosToken ((l,c),t) = concat [ show l, ":", show c, "\t", show t ]
  
  showTree :: (Show a) => Int -> a -> IO ()
  showTree v tree = do
    putStrV v $ "\n[Abstract Syntax]\n\n" ++ show tree
  
  
  main :: IO ()
  main = getContents >>= run 2 pRule
  
  
  