Skip to content

Commit

Permalink
Added WrapType and expanded wrap function
Browse files Browse the repository at this point in the history
  • Loading branch information
samm82 committed Jul 23, 2018
1 parent 85b420a commit c057b92
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
21 changes: 12 additions & 9 deletions code/drasil-data/Data/Drasil/SentenceStructures.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Data.Drasil.SentenceStructures
, fmtPhys, fmtSfwr, typUncr
, mkTableFromColumns
, acroA, acroGD, acroGS, acroIM, acroLC, acroPS, acroR, acroT
, EnumType(..)
, EnumType(..), WrapType(..)
) where

import Language.Drasil
Expand Down Expand Up @@ -67,17 +67,20 @@ foldlOptions [a,b] = a `sOr` b
foldlOptions lst = foldle1 sC (\a b -> a `sC` S "or" +:+ b) lst

data EnumType = Numb | Upper | Lower
data WrapType = Parens | Paren | Period

-- | creates an list of elements with "enumerators" in "wrappers", separated by a sep, and ending with "and"
foldlInlineList :: EnumType -> Sentence -> [Sentence] -> Sentence
foldlInlineList enum sep lst = makeList sep $ map (\(a, b) -> a +:+ b) $ zip (numList enum $ length lst) lst
foldlInlineList :: EnumType -> WrapType -> Sentence -> [Sentence] -> Sentence
foldlInlineList e w sep lst = makeList sep $ map (\(a, b) -> a +:+ b) $ zip (numList e w $ length lst) lst
where
numList :: EnumType -> Int -> [Sentence]
numList Numb len = map (\x -> wrap $ S $ show x) [1..len]
numList Upper len = map (\x -> wrap $ S $ [x]) (take len ['A'..'Z'])
numList Lower len = map (\x -> wrap $ S $ [x]) (take len ['a'..'z'])
wrap :: Sentence -> Sentence
wrap = sParen
numList :: EnumType -> WrapType -> Int -> [Sentence]
numList Numb w len = map (\x -> wrap w $ S $ show x) [1..len]
numList Upper w len = map (\x -> wrap w $ S $ [x]) (take len ['A'..'Z'])
numList Lower w len = map (\x -> wrap w $ S $ [x]) (take len ['a'..'z'])
wrap :: WrapType -> Sentence -> Sentence
wrap Parens x = sParen x
wrap Paren x = x :+: S ")"
wrap Period x = x :+: S "."

-- Helper function to foldlInlineList - not exported
makeList :: Sentence -> [Sentence] -> Sentence
Expand Down
6 changes: 3 additions & 3 deletions code/drasil-example/Drasil/GlassBR/Assumptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import Drasil.DocLang (cite, refA)
import Data.Drasil.Concepts.Documentation as Doc (condition, constant, practice, reference, scenario,
system, value)
import Data.Drasil.Concepts.Math (calculation, surface, shape)
import Data.Drasil.SentenceStructures (EnumType(Numb) ,sAnd, foldlSent, foldlSent_, foldlOptions,
foldlList, foldlInlineList, sOf, sIn)
import Data.Drasil.SentenceStructures (EnumType(Numb), WrapType(Parens), foldlSent, foldlSent_,
foldlOptions, foldlList, foldlInlineList, sAnd, sIn, sOf)
import Data.Drasil.Concepts.PhysicalProperties (materialProprty)

import Drasil.GlassBR.Unitals ( lite, explosion, lateral, load_dur, explosion,
Expand Down Expand Up @@ -47,7 +47,7 @@ a1Desc = foldlSent [S "The standard E1300-09a for",
"laminated", "insulating"], S "glass constructions" `sOf` S "rectangular",
phrase shape, S "with continuous", phrase lateral, S "support along",
(foldlOptions $ map S ["one", "two", "three", "four"]) +:+. plural edge, S "This",
phrase practice +: S "assumes that", (foldlInlineList Numb (S ";") $ map foldlSent_
phrase practice +: S "assumes that", (foldlInlineList Numb Parens (S ";") $ map foldlSent_
[[S "the supported glass", plural edge, S "for two, three" `sAnd` S "four-sided support",
plural condition, S "are simply supported" `sAnd` S "free to slip in",
phrase plane], [S "glass supported on two sides acts as a simply supported", phrase beam],
Expand Down

4 comments on commit c057b92

@JacquesCarette
Copy link
Owner

Choose a reason for hiding this comment

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

That Paren is for adding just a closing ) is very weird! Otherwise this is nice.

@samm82
Copy link
Collaborator Author

@samm82 samm82 commented on c057b92 Jul 24, 2018

Choose a reason for hiding this comment

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

I thought it could be useful in some settings - I'll remove it then

@JacquesCarette
Copy link
Owner

Choose a reason for hiding this comment

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

We try to not 'over-engineer' and thus only add functionality when we know it is going to be used at least twice in the current code base.

@samm82
Copy link
Collaborator Author

@samm82 samm82 commented on c057b92 Jul 24, 2018

Choose a reason for hiding this comment

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

Makes sense - should I remove Period then too? As it isn't used?

Please sign in to comment.