@@ -3,9 +3,10 @@ module Copager2.IR.SExp
33 , feed
44 , build
55 , consume
6- , fmtPrint
76 ) where
87
8+ import Data.Function ((&) )
9+
910import Copager2.Core.Process (ProcessT , foldProcess )
1011import Copager2.Core.Progress (Progress (.. ))
1112import Copager2.Core.State (applyBuilding , updateBuilding )
@@ -19,7 +20,13 @@ data SExp ts rs
1920 = Empty
2021 | Atom (Token ts )
2122 | List (rs , [SExp ts rs ])
22- deriving Show
23+
24+ instance (Show ts , Show rs ) => Show (SExp ts rs ) where
25+ show Empty = " "
26+ show (Atom token) = " \" " ++ raw token ++ " \" "
27+ show (List (rule, rhs)) =
28+ let formattedRhs = rhs & map show
29+ in " (" ++ show rule ++ " " ++ unwords formattedRhs ++ " )"
2330
2431newtype SExpStack ts rs = SExpStack [SExp ts rs ]
2532
@@ -54,17 +61,3 @@ consume events = foldProcess events $ \event -> do
5461 Accept -> build
5562 Error err -> return $ Fail err
5663 _ -> feed event
57-
58- fmtPrint :: (Show ts , Show rs ) => SExp ts rs -> IO ()
59- fmtPrint = fmtPrint' 0
60-
61- fmtPrint' :: (Show ts , Show rs ) => Int -> SExp ts rs -> IO ()
62- fmtPrint' indent (List (rule, [Atom token])) = do
63- indentPrint indent (" - " ++ show rule ++ " : " ++ raw token)
64- fmtPrint' indent (List (rule, rhs)) = do
65- indentPrint indent (" - " ++ show rule)
66- mapM_ (fmtPrint' (indent + 2 )) rhs
67- fmtPrint' _ _ = return ()
68-
69- indentPrint :: Int -> String -> IO ()
70- indentPrint indent str = putStrLn $ replicate indent ' ' ++ str
0 commit comments