module Language.Drasil.Code.Imperative.Comments (
renderTermAndUnit
) where
import Control.Monad.State (get)
import Text.PrettyPrint.HughesPJ ((<+>), parens, render)
import Drasil.Code.CodeVar (CodeIdea(..))
import Language.Drasil (phrase, MayHaveUnit(..), HasUnitSymbol(..))
import Language.Drasil.Code.Imperative.DrasilState (GenState, DrasilState(..))
import Language.Drasil.Printers (oneLineSentenceDoc, oneLineUnitDoc)
renderTermAndUnit :: (CodeIdea c) => c -> GenState String
renderTermAndUnit :: forall c. CodeIdea c => c -> GenState String
renderTermAndUnit c
l = do
g <- StateT DrasilState Identity DrasilState
forall s (m :: * -> *). MonadState s m => m s
get
let quant = c -> CodeChunk
forall c. CodeIdea c => c -> CodeChunk
codeChunk c
l
tm = PrintingInformation -> Sentence -> Doc
oneLineSentenceDoc (DrasilState -> PrintingInformation
printfo DrasilState
g) (Sentence -> Doc) -> Sentence -> Doc
forall a b. (a -> b) -> a -> b
$ CodeChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase CodeChunk
quant
unit = Doc -> Doc
parens (Doc -> Doc) -> (UnitDefn -> Doc) -> UnitDefn -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. USymb -> Doc
oneLineUnitDoc (USymb -> Doc) -> (UnitDefn -> USymb) -> UnitDefn -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnitDefn -> USymb
forall u. HasUnitSymbol u => u -> USymb
usymb (UnitDefn -> Doc) -> Maybe UnitDefn -> Maybe Doc
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CodeChunk -> Maybe UnitDefn
forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit CodeChunk
quant
pure $ render $ maybe tm (tm <+>) unit