Skip to content
Draft
Show file tree
Hide file tree
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
25 changes: 12 additions & 13 deletions code/drasil-code/lib/Language/Drasil/Code/Imperative/Modules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import Language.Drasil.Choices (Comments(..), ConstantStructure(..),
Logging(..), Structure(..), hasSampleInput, InternalConcept(..))
import Language.Drasil.CodeSpec (HasOldCodeSpec(..))
import Language.Drasil.Expr.Development (Completeness(..))
import Language.Drasil.Printers (SingleLine(OneLine), codeExprDoc, showHasSymbImpl, PrintingInformation)
import Language.Drasil.Printers (SingleLine(OneLine), showHasSymbImpl, PrintingInformation)

import Drasil.GOOL (MSBody, MSBlock, SVariable, SValue, MSStatement,
SMethod, CSStateVar, SClass, SharedProg, OOProg, BodySym(..), bodyStatements,
Expand All @@ -63,7 +63,7 @@ import Drasil.GOOL (MSBody, MSBlock, SVariable, SValue, MSStatement,
VisibilitySym(..), MethodSym(..), StateVarSym(..), pubDVar, convType,
convTypeOO, VisibilityTag(..))

import qualified Drasil.GOOL as OO (SFile)
import qualified Drasil.GOOL as OO (SFile, SValue)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These imports (of SFile and SValue), as well as ProcProg` all seem to point to something being odd here.

import Drasil.GProc (ProcProg)
import qualified Drasil.GProc as Proc (SFile)

Expand Down Expand Up @@ -419,15 +419,15 @@ printConstraint v c = do
printConstraint' _ (Range _ (Bounded (_, e1) (_, e2))) = do
lb <- convExpr e1
ub <- convExpr e2
return $ [printStr "between ", print lb] ++ printExpr e1 db ++
[printStr " and ", print ub] ++ printExpr e2 db ++ [printStrLn "."]
return $ [printStr "between "] ++ printExpr lb db ++
[printStr " and "] ++ printExpr ub db ++ [printStrLn "."]
printConstraint' _ (Range _ (UpTo (_, e))) = do
ub <- convExpr e
return $ [printStr "below ", print ub] ++ printExpr e db ++
return $ [printStr "below "] ++ printExpr ub db ++
[printStrLn "."]
printConstraint' _ (Range _ (UpFrom (_, e))) = do
lb <- convExpr e
return $ [printStr "above ", print lb] ++ printExpr e db ++ [printStrLn "."]
return $ [printStr "above "] ++ printExpr lb db ++ [printStrLn "."]
Comment on lines 419 to +430
Copy link
Collaborator Author

@balacij balacij Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question to ask ourselves first is: What do we want the format of the constraint violation messages to be?

I somewhat like these, but I would also like to see CON$X$ (where CON$X$ is a label we defined in the SRS for a constraint) added as a prefix.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that more traceability in constraint violation messages would be even better.

printConstraint' name (Elem _ e) = do
lb <- convExpr (Variable ("set_" ++ name) e)
return $ [printStr "an element of the set ", print lb] ++ [printStrLn "."]
Expand All @@ -437,9 +437,8 @@ printConstraint v c = do
-- | Don't print expressions that are just literals, because that would be
-- redundant (the values are already printed by printConstraint).
-- If expression is more than just a literal, print it in parentheses.
printExpr :: (SharedProg r) => CodeExpr -> PrintingInformation -> [MSStatement r]
printExpr Lit{} _ = []
printExpr e db = [printStr $ " (" ++ render (codeExprDoc db OneLine e) ++ ")"]
printExpr :: (SharedProg r) => OO.SValue r -> PrintingInformation -> [MSStatement r]
printExpr e db = [print e] -- [printStr " (", print e, printStr ")"] -- ++ render (codeExprDoc db OneLine e) ++ ")"]

-- | | Generates a function for reading inputs from a file.
genInputFormat :: (OOProg r) => VisibilityTag ->
Expand Down Expand Up @@ -984,15 +983,15 @@ printConstraintProc c = do
printConstraint' (Range _ (Bounded (_, e1) (_, e2))) = do
lb <- convExprProc e1
ub <- convExprProc e2
return $ [printStr "between ", print lb] ++ printExpr e1 db ++
[printStr " and ", print ub] ++ printExpr e2 db ++ [printStrLn "."]
return $ [printStr "between "] ++ printExpr lb db ++
[printStr " and "] ++ printExpr ub db ++ [printStrLn "."]
printConstraint' (Range _ (UpTo (_, e))) = do
ub <- convExprProc e
return $ [printStr "below ", print ub] ++ printExpr e db ++
return $ [printStr "below "] ++ printExpr ub db ++
[printStrLn "."]
printConstraint' (Range _ (UpFrom (_, e))) = do
lb <- convExprProc e
return $ [printStr "above ", print lb] ++ printExpr e db ++ [printStrLn "."]
return $ [printStr "above "] ++ printExpr lb db ++ [printStrLn "."]
printConstraint' (Elem _ e) = do
lb <- convExprProc e
return $ [printStr "an element of the set ", print lb] ++ [printStrLn "."]
Expand Down
5 changes: 1 addition & 4 deletions code/drasil-lang/lib/Drasil/Code/CodeExpr/Convert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,10 @@ realInterval (Bounded (il, el) (ir, er)) = Bounded (il, expr el) (ir, expr er)
realInterval (UpTo (i, e)) = UpTo (i, expr e)
realInterval (UpFrom (i, e)) = UpFrom (i, expr e)

con :: E.Expr -> CodeExpr
con = expr

-- | Convert constrained expressions ('ConstraintE') into 'Constraint''CodeExpr's.
constraint :: ConstraintE -> Constraint CodeExpr
constraint (Range r ri) = Range r (realInterval ri)
constraint (Elem r ri) = Elem r (con ri)
constraint (Elem r ri) = Elem r (expr ri)

-- | Convert 'DomainDesc Expr Expr' into 'DomainDesc CodeExpr CodeExpr's.
renderDomainDesc :: DiscreteDomainDesc E.Expr E.Expr -> DiscreteDomainDesc CodeExpr CodeExpr
Expand Down
21 changes: 8 additions & 13 deletions code/drasil-lang/lib/Language/Drasil/Document/Contents.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,19 @@ module Language.Drasil.Document.Contents (
unlbldCode
) where

import Drasil.Code.CodeExpr.Lang (CodeExpr)
import Control.Lens ((^.))

import Language.Drasil.Classes (Definition(..))
import Language.Drasil.ShortName (HasShortName(..), getSentSN)
import Language.Drasil.Document (llcc, ulcc)
import Language.Drasil.Document.Core
(LabelledContent,
RawContent(Enumeration, EqnBlock, CodeBlock),
Contents(UlC),
ListTuple,
ItemType(Flat),
ListType(Simple))
import Language.Drasil.Document.Combinators (bulletFlat, mkEnumAbbrevList)
import Language.Drasil.Document.Core (LabelledContent, RawContent(Enumeration,
EqnBlock, CodeBlock), Contents(UlC), ListTuple, ItemType(Flat), ListType(Simple))
import Language.Drasil.Expr.Lang (Expr)
import Language.Drasil.Label.Type ( Referable(refAdd) )
import Language.Drasil.ModelExpr.Lang (ModelExpr)
import Language.Drasil.Reference (Reference)
import Language.Drasil.Sentence (Sentence (..))
import Language.Drasil.Document.Combinators (bulletFlat, mkEnumAbbrevList)
import Language.Drasil.Label.Type ( Referable(refAdd) )

import Control.Lens ((^.))

-- | Displays a given expression and attaches a 'Reference' to it.
lbldExpr :: ModelExpr -> Reference -> LabelledContent
Expand All @@ -38,7 +33,7 @@ unlbldExpr :: ModelExpr -> Contents
unlbldExpr c = UlC $ ulcc $ EqnBlock c

-- | Unlabelled code expression
unlbldCode :: CodeExpr -> Contents
unlbldCode :: Expr -> Contents
unlbldCode c = UlC $ ulcc $ CodeBlock c

-- | Creates a bulleted list.
Expand Down
9 changes: 4 additions & 5 deletions code/drasil-lang/lib/Language/Drasil/Document/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
-- | Contains types and functions common to aspects of generating documents.
module Language.Drasil.Document.Core where

import Control.Lens ((^.), makeLenses, Lens', set, view)

import Drasil.Database (HasChunkRefs(..), HasUID(..), UID)

import Drasil.Code.CodeExpr.Lang (CodeExpr)
import Language.Drasil.Expr.Lang (Expr)
import Language.Drasil.Chunk.Citation (BibRef)
import Language.Drasil.ShortName (HasShortName(shortname))
import Language.Drasil.ModelExpr.Lang (ModelExpr)
Expand All @@ -13,8 +15,6 @@ import Language.Drasil.Label.Type (getAdd, prepend, IRefProg,
import Language.Drasil.Reference (Reference)
import Language.Drasil.Sentence (Sentence)

import Control.Lens ((^.), makeLenses, Lens', set, view)

-- * Lists

-- | Denotes the different possible types that can be used as a list.
Expand Down Expand Up @@ -78,8 +78,7 @@ data RawContent =
-- ^ For creating figures in a document includes whether the figure has a caption.
| Bib BibRef -- ^ Grants the ability to reference something.
| Graph [(Sentence, Sentence)] (Maybe Width) (Maybe Height) Lbl -- ^ Contain a graph with coordinates ('Sentence's), maybe a width and height, and a label ('Sentence').
| CodeBlock CodeExpr -- ^ Block for codes
-- TODO: Fill this one in.
| CodeBlock Expr -- ^ Block for codes

-- | An identifier is just a 'String'.
type Identifier = String
Expand Down
9 changes: 2 additions & 7 deletions code/drasil-printers/lib/Language/Drasil/Plain/Print.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Language.Drasil.Plain.Print (
-- * Types
SingleLine(..),
-- * Functions
exprDoc, codeExprDoc, sentenceDoc, symbolDoc, unitDoc, showSymb,
exprDoc, sentenceDoc, symbolDoc, unitDoc, showSymb,
showHasSymbImpl
) where

Expand All @@ -13,14 +13,13 @@ import Text.PrettyPrint.HughesPJ (Doc, (<>), (<+>), brackets, comma, double,
doubleQuotes, empty, hcat, hsep, integer, parens, punctuate, space, text,
vcat, render)

import qualified Drasil.Code.CodeExpr.Development as C (CodeExpr)
import Language.Drasil (Sentence, Special(..), Stage(..), Symbol, USymb(..))
import qualified Language.Drasil as L (Expr, HasSymbol(..))
import Utils.Drasil (toPlainName)

import Language.Drasil.Printing.AST (Expr(..), Spec(..), Ops(..), Fence(..),
OverSymb(..), Fonts(..), Spacing(..), LinkType(..))
import Language.Drasil.Printing.Import (expr, codeExpr, spec, symbol)
import Language.Drasil.Printing.Import (expr, spec, symbol)
import Language.Drasil.Printing.PrintingInformation (PrintingInformation)

-- | Data is either linear or not.
Expand All @@ -30,10 +29,6 @@ data SingleLine = OneLine | MultiLine
exprDoc :: PrintingInformation -> SingleLine -> L.Expr -> Doc
exprDoc pinfo sl e = pExprDoc sl (expr e pinfo)

-- | Create code expressions for a document in 'Doc' format.
codeExprDoc :: PrintingInformation -> SingleLine -> C.CodeExpr -> Doc
codeExprDoc pinfo sl e = pExprDoc sl (codeExpr e pinfo)
Comment on lines -33 to -35
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is used by drasil-code for a single purpose: rendering CodeExpr-based quantity constraints into human-readable text for outputting input value constraint violation messages (see stable/ changes).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like reasonable functionality - where does it belong? And maybe it should be in two stages (i.e. codeExprDoc would get fed the results of codeExpr e pinfo so that codeExpr would not be needed here).


-- | Create sentences for a document in 'Doc' format.
sentenceDoc :: PrintingInformation -> SingleLine -> Sentence -> Doc
sentenceDoc pinfo sl s = specDoc sl (spec pinfo s)
Expand Down
4 changes: 2 additions & 2 deletions code/drasil-printers/lib/Language/Drasil/Printers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Language.Drasil.Printers (
-- ** Types
, SingleLine(..)
-- ** Functions
, sentenceDoc, exprDoc, codeExprDoc, symbolDoc, unitDoc, showSymb,
, sentenceDoc, exprDoc, symbolDoc, unitDoc, showSymb,
showHasSymbImpl
-- * TeX
, genTeX
Expand All @@ -48,7 +48,7 @@ import Language.Drasil.Markdown.Config (makeBook, makeRequirements)
import Language.Drasil.Markdown.CreateMd (makeMd, introInfo, verInfo, unsupOS,
extLibSec, instDoc, regularSec, endNote, whatInfo)
import Language.Drasil.Plain.Print (SingleLine(..), sentenceDoc, exprDoc,
codeExprDoc, symbolDoc, unitDoc, showSymb, showHasSymbImpl)
symbolDoc, unitDoc, showSymb, showHasSymbImpl)
import Language.Drasil.TeX.Print (genTeX)
import Language.Drasil.Printing.PrintingInformation (PrintingInformation,
HasPrintingOptions(..), Notation(..), piSys,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
-- | Re-export top-level functions for easy use across drasil-printers.
module Language.Drasil.Printing.Import (
expr, codeExpr, literal, modelExpr,
expr, literal, modelExpr,
space, spec, symbol,
makeDocument, makeProject
) where

import Language.Drasil.Printing.Import.CodeExpr (codeExpr)
import Language.Drasil.Printing.Import.Document (makeDocument, makeProject)
import Language.Drasil.Printing.Import.Expr (expr)
import Language.Drasil.Printing.Import.Literal (literal)
Expand Down
Loading
Loading