Need help! Removing codeExprDoc from drasil-printers?#4509
Need help! Removing codeExprDoc from drasil-printers?#4509
codeExprDoc from drasil-printers?#4509Conversation
| -- | Create code expressions for a document in 'Doc' format. | ||
| codeExprDoc :: PrintingInformation -> SingleLine -> C.CodeExpr -> Doc | ||
| codeExprDoc pinfo sl e = pExprDoc sl (codeExpr e pinfo) |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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).
| {-# LANGUAGE GADTs #-} | ||
|
|
||
| -- | Defines functions to render 'CodeExpr's as printable 'P.Expr's. | ||
| module Language.Drasil.Printing.Import.CodeExpr (codeExpr) where |
There was a problem hiding this comment.
The reason why I tried to delete this file at all is because, well, it is odd. CodeExpr is intended for rendering into GOOL (solely, to my knowledge), not necessarily rendering comments. Considering it is only used for a single purpose (the input constraint violation error messages), I'm not sure if the approach taken to outputting messages is a good one.
There was a problem hiding this comment.
I could be wrong here as well!
But I neglected to also mention the initial reason I was looking at this code at all: drasil-printers and drasil-code have a cyclic dependency that we are currently avoiding through pushing some code from drasil-code into drasil-lang. This includes the "code variable chunks" and CodeExpr. My goal is to be able to move the drasil-code-related code from drasil-lang into drasil-code.
There was a problem hiding this comment.
I certainly agree with that goal.
| std::cout << ", but is expected to be "; | ||
| std::cout << "between "; | ||
| std::cout << 0.1; | ||
| std::cout << " (d_min)"; |
There was a problem hiding this comment.
While here we output a variable name in "implementation" Stage, in other areas, we have the flexibility of printing any general CodeExpr.
There was a problem hiding this comment.
Indeed. But removing this output points to a real problem, i.e. these changes should not do that!
| print(Float32(0.0)) | ||
| print(" and ") | ||
| print(pi / Float32(2.0)) | ||
| print(" ((pi)/(2))") |
There was a problem hiding this comment.
For example,
| 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 "."] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I agree that more traceability in constraint violation messages would be even better.
|
One solution to all of this is to split up Another solution (the one I decided on for this PR) is to delete However, if we wanted to maintain the status quo with this PR for the sake of maintaining the status quo, we should be able to avoid converting the constraint maps of |
codeExpr from drasil-printers?codeExprDoc from drasil-printers?
| convTypeOO, VisibilityTag(..)) | ||
|
|
||
| import qualified Drasil.GOOL as OO (SFile) | ||
| import qualified Drasil.GOOL as OO (SFile, SValue) |
There was a problem hiding this comment.
These imports (of SFile and SValue), as well as ProcProg` all seem to point to something being odd here.
| -- | Create code expressions for a document in 'Doc' format. | ||
| codeExprDoc :: PrintingInformation -> SingleLine -> C.CodeExpr -> Doc | ||
| codeExprDoc pinfo sl e = pExprDoc sl (codeExpr e pinfo) |
There was a problem hiding this comment.
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).
| {-# LANGUAGE GADTs #-} | ||
|
|
||
| -- | Defines functions to render 'CodeExpr's as printable 'P.Expr's. | ||
| module Language.Drasil.Printing.Import.CodeExpr (codeExpr) where |
There was a problem hiding this comment.
I certainly agree with that goal.
| std::cout << ", but is expected to be "; | ||
| std::cout << "between "; | ||
| std::cout << 0.1; | ||
| std::cout << " (d_min)"; |
There was a problem hiding this comment.
Indeed. But removing this output points to a real problem, i.e. these changes should not do that!
I will annotate this PR for discussion, but this PR and branch are expected to be deleted in the end.
The goal of my work is to move the
Drasil.Code.*modules fromdrasil-langintodrasil-code. However, that work is currently impossible because it would create a cyclic dependency betweendrasil-printersanddrasil-code:drasil-printersrelies onCodeExprand the other modules inDrasil.Code(namely code variables) for describing howCodeExprcan be rendered intoDocs for human-readable, non-code purposes (I suppose ASCII variants).drasil-coderelies ondrasil-printersfor said rendering function and more (e.g., rendering functions forModelExpr,Sentence,Symbol, etc.).