Commit ae3c2dda authored by Hans-Peter Deifel's avatar Hans-Peter Deifel 🐢

Merge branch 'print-as-debug-command' [#35]

parents 7fe7c5e7 09b1f842
......@@ -377,6 +377,55 @@ options :: Parser Options
options = Options <$> subcommand
data DebugCommand = DebugFunctor Bool (FunctorExpression SomeFunctor Sort)
| DebugCoalgebra DebugCoalgebraOptions
data DebugCoalgebraOptions = DebugCoalgebraOptions
{ debugCoalgebraApplyTransformations :: Bool
, debugCoalgebraEnableSanity :: Bool
, debugCoalgebraFunctor :: Maybe (FunctorExpression SomeFunctor Sort)
, debugCoalgebraInputFile :: Maybe FilePath
}
debugCoalgebraOptions :: Parser DebugCoalgebraOptions
debugCoalgebraOptions = do
debugCoalgebraInputFile <- 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
)
)
debugCoalgebraFunctor <- optional
(option
functorReader
( long "functor"
<> short 'f'
<> metavar "FUNCTOR_EXPR"
<> help
"Functor for the input coalgebra. This is normally the first line of \
\the input, but can also alternatively be given here."
)
)
debugCoalgebraApplyTransformations <- not <$> switch
( long "no-functor-transforms"
<> help
"Don't try to optimize functor expression. \
\This flag can drastically *reduce* performace."
)
debugCoalgebraEnableSanity <- not <$> switch
( long "no-sanity-checks"
<> help
"Disable sanity checks in the parser. Do not use this lightly. It \
\might speed up the parser but require the input to be absolutely \
\correct. Otherwise, nasal demons might be created."
)
pure DebugCoalgebraOptions { .. }
debugCommand :: Parser DebugCommand
debugCommand = hsubparser $ command
......@@ -394,6 +443,11 @@ debugCommand = hsubparser $ command
"Parse a functor expression and its internal representation."
)
)
<>
command "print-coalgebra"
(info
(DebugCoalgebra <$> debugCoalgebraOptions)
(progDesc "Parse a coalgebra and immediately print it again."))
----------------------------------------------------------------------
-- File handling
......@@ -586,6 +640,32 @@ main = do
| applyTrans -> T.putStrLn (printFunctor (applyFunctorRewrites f))
| otherwise -> T.putStrLn (printFunctor f)
DebugCommand (DebugCoalgebra r) -> do
(f, (symbolTable, encoding)) <- do
let transPolicy = if debugCoalgebraApplyTransformations r
then P.ApplyTransformations
else P.DontApplyTransformations
let sanity = if debugCoalgebraEnableSanity r
then P.EnableSanityChecks
else P.DisableSanityChecks
let parserConfig = P.Config
{ functorTransforms = transPolicy
, sanityChecks = sanity
, functor = debugCoalgebraFunctor r
}
readCoalgebra parserConfig (debugCoalgebraInputFile r)
>>= \case
Left err -> hPutStrLn stderr err >> exitFailure
Right res -> evaluate res
T.putStrLn $ printParseableFunctor f
T.putStrLn ""
LT.putStrLn $ Build.toLazyText $ printEncoding encoding symbolTable (sortTable f)
helpOverview :: Text -> Doc AnsiStyle
helpOverview argv0 =
reflow
......
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