Commit 69c0bb43 authored by Thorsten Wißmann's avatar Thorsten Wißmann 🐧

Draft for pretty printer

parent 14c8134e
......@@ -10,6 +10,8 @@ import Copar.Coalgebra.Parser.Internal
import Copar.RefinementInterface
import Copar.Parser.Types
import Data.Text (Text,pack)
type MorphParser l f1 = StateT (ParserState l f1) Parser
class ParseMorphism f where
......@@ -17,3 +19,5 @@ class ParseMorphism f where
:: (Ord x)
=> f (MorphParser l f1 x)
-> MorphParser l f1 (F1 f, Vector (x, Label f))
printMorphismPoint :: f Text -> Text
printMorphismPoint _ = pack "TODO"
......@@ -52,6 +52,7 @@ newtype Options = Options
data SubCommand
= HelpCommand (Maybe HelpCommand)
| RefineCommand RefineOptions
| PrettyPrintCommand PrettyPrintOptions
| GraphCommand GraphOptions
| DebugCommand DebugCommand
......@@ -72,6 +73,16 @@ subcommand =
)
)
)
-- <> (command
-- "pretty-print"
-- (info
-- (PrettyPrintCommand <$> prettyPrintOptions)
-- (progDesc
-- "Print the given input coalgebra after parsing."
-- <> footerDoc (Just (toAnsiWlPprint prettyPrintHelp))
-- )
-- )
-- )
<> (command
"graph"
(info
......@@ -187,6 +198,28 @@ refineOptions = do
)
pure RefineOptions { .. }
data PrettyPrintOptions = PrettyPrintOptions
{ prettyPrintInputFile :: Maybe FilePath
}
prettyPrintHelp :: Doc AnsiStyle
prettyPrintHelp = reflow "This directly prints an input coalgebra after parsing."
prettyPrintOptions :: Parser PrettyPrintOptions
prettyPrintOptions = do
prettyPrintInputFile <- optional
(argument
str
( metavar "INPUT_FILE"
<> help
"Name of file to read the input coalgebra from or \"-\" for standard input. \
\See the \"help\" command for a description of available syntax."
<> value "-"
<> showDefault
)
)
pure PrettyPrintOptions { .. }
data GraphOptions = GraphOptions
{ graphInputFile :: Maybe FilePath
, graphOutputFile :: Maybe FilePath
......@@ -454,6 +487,19 @@ main = do
finalizeStats stats
(PrettyPrintCommand r) -> do
(f, (symbolTable, encoding)) <- do
let parserConfig = P.Config
{ functorTransforms = P.DontApplyTransformations
, sanityChecks = P.DisableSanityChecks
, functor = Nothing
}
readCoalgebra parserConfig (prettyPrintInputFile r)
>>= \case
Left err -> hPutStrLn stderr err >> exitFailure
Right res -> evaluate res
hPutStrLn stderr "tesetste"
(GraphCommand r) -> do
(f, (symbolTable, encoding)) <- do
let transPolicy = if graphApplyTransformations r
......
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