Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small LE transpiler fix #432

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions lib/haskell/natural4/src/LS/XPile/LogicalEnglish/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import Prettyprinter
hsep,
line,
-- parens,
punctuate,
list,
indent,
nest,
Expand Down Expand Up @@ -60,7 +59,7 @@ import LS.XPile.LogicalEnglish.GenNLAs (NLATxt)
data LEProg = MkLEProg { keptnlats :: [NLATxt]
, subsumednlats :: [NLATxt]
-- ^ this wouldn't be *all* of the filtered-out NLATxts -- just those that are equiv up to var names (and have the same number of vars)
, leHCs :: [LEhcPrint]
, leHCs :: [LEhcPrint]
, commentSym :: T.Text
}

Expand Down Expand Up @@ -136,8 +135,19 @@ instance Pretty TxtAtomicBP where
where
prettyprop = hsep . map pretty

endWithDot txt = [__di|#{ txt }.|]

-- endWithDot txt = [__di|#{ txt }.|]

-- | Like punctuate from the pretty printer lib, except that this puts `p` at the end of every doc
punctuate'
:: Doc ann -- ^ Punctuation, e.g. 'comma'
-> [Doc ann]
-> [Doc ann]
punctuate' p = go
where
go [] = []
go [d] = [d <> p]
go (d:ds) = (d <> p) : go ds

instance Pretty LEProg where

{-
Expand All @@ -147,16 +157,16 @@ instance Pretty LEProg where
-}
pretty :: forall ann. LEProg -> Doc ann
pretty MkLEProg{..} =
let
indentedNLAs :: Doc ann = endWithDot . nestVsepSeq . punctuate comma . map pretty . sort $ keptnlats
let
indentedNLAs :: Doc ann = nestVsepSeq . punctuate' comma . map pretty . sort $ keptnlats
prettyLEhcs :: Doc ann = vvsep $ map ((<> dot) . pretty) leHCs
{- ^ Assume commas and dots already replaced in NLAs and LEHcs
(can't replace here b/c we sometimes do want the dot, e.g. for numbers) -}

prependWithCommentOp :: Doc ann -> Doc ann = (pretty commentSym <+>)
removedNLAs :: Doc ann = vsep . map (prependWithCommentOp . pretty) $ subsumednlats
removedNLAsection :: Doc ann = if length subsumednlats > 0
then
removedNLAsection :: Doc ann = if not (null subsumednlats)
then
line <> [__di|%% Some of the removed templates (just the equiv-up-to-var-names-with-same-num-vars ones):
#{indentLE removedNLAs}|]
else ""
Expand Down
Loading