Skip to content

Commit

Permalink
Added Roman Symbol constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
samm82 committed Jun 28, 2019
1 parent af2acf8 commit b7582bb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
1 change: 1 addition & 0 deletions code/drasil-code/Language/Drasil/Chunk/Code.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ programName = toCodeName . abrv

symbToCodeName :: Symbol -> String
symbToCodeName (Atomic s) = toCodeName s
symbToCodeName (Roman s) = toCodeName s
symbToCodeName (Special sp) = specialToCodeName sp
--symbToCodeName (Greek g) = greekToCodeName g
symbToCodeName (Atop d s) = decorate (symbToCodeName s) d
Expand Down
11 changes: 10 additions & 1 deletion code/drasil-lang/Language/Drasil/Symbol.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ import Data.Char (toLower)
data Decoration = Hat | Vector | Prime deriving (Eq, Ord)

-- | Symbols can be:
-- - atomic (strings such as "A" or "max" that represent a single idea)
-- - atomic (strings such as "A" or "c" that represent a single idea)
-- - roman (same as atomic, but should be displayed without italics,
-- and in a math environment, such as "max")
-- - special characters (ex. unicode)
-- - Decorated symbols
-- - Concatenations of symbols, including subscripts and superscripts
-- - empty! (this is to give this a monoid-like flavour)
data Symbol =
Atomic String
| Roman String

This comment has been minimized.

Copy link
@JacquesCarette

JacquesCarette Jun 29, 2019

Owner

Also, now that I see the use of this, I wonder if what we need is a set of qualifiers to Atomic instead of new constructors.

| Special Special
| Atop Decoration Symbol
| Corners [Symbol] [Symbol] [Symbol] [Symbol] Symbol
Expand Down Expand Up @@ -108,6 +111,12 @@ compsy (Atomic x) (Atomic y) =
other -> other
compsy (Atomic _) _ = LT
compsy _ (Atomic _) = GT
compsy (Roman x) (Roman y) =
case compare (map toLower x) (map toLower y) of
EQ -> compare x y
other -> other
compsy (Roman _) _ = LT
compsy _ (Roman _) = GT
compsy Empty Empty = EQ

-- | Helper for creating a symbol with a superscript on the left side of the symbol.
Expand Down
8 changes: 4 additions & 4 deletions code/drasil-printers/Language/Drasil/HTML/Print.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import Control.Arrow (second)

import qualified Language.Drasil as L (People, Person,
CitationKind(Misc, Book, MThesis, PhDThesis, Article),
Symbol(Corners, Concat, Special, Atomic, Empty, Atop),
DType(Data, Theory, Instance, General), MaxWidthPercent,
Decoration(Prime, Hat, Vector), Document,
nameStr, rendPersLFM, rendPersLFM', rendPersLFM'', special, USymb(US))
Symbol(..), DType(Data, Theory, Instance, General), MaxWidthPercent,
Decoration(Prime, Hat, Vector), Document, nameStr, rendPersLFM,
rendPersLFM', rendPersLFM'', special, USymb(US))

import Language.Drasil.HTML.Monad (unPH)
import Language.Drasil.HTML.Helpers (articleTitle, author, ba, body, bold,
Expand Down Expand Up @@ -112,6 +111,7 @@ pSpec (Quote q) = text "&quot;" <> pSpec q <> text "&quot;"
-- | Renders symbols for HTML document
symbol :: L.Symbol -> String
symbol (L.Atomic s) = s
symbol (L.Roman s) = s
symbol (L.Special s) = unPH $ L.special s
symbol (L.Concat sl) = concatMap symbol sl
--symbol (Greek g) = unPH $ greek g
Expand Down
1 change: 1 addition & 0 deletions code/drasil-printers/Language/Drasil/Printing/Import.hs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ eop sm Add (AllDD _ Discrete) e = P.Row [P.MO P.Summ, P.Row [expr e sm]]

symbol :: Symbol -> P.Expr
symbol (Atomic s) = P.Ident s
symbol (Roman s) = P.Ident s
symbol (Special s) = P.Spec s
--symbol (Greek g) = P.Gr g
symbol (Concat sl) = P.Row $ map symbol sl
Expand Down
16 changes: 9 additions & 7 deletions code/drasil-printers/Language/Drasil/TeX/Print.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ print sm = foldr (($+$) . (`lo` sm)) empty
------------------ Symbol ----------------------------
symbol :: L.Symbol -> String
symbol (L.Atomic s) = s
symbol (L.Roman s) = "\\text" ++ brace s
symbol (L.Special s) = unPL $ L.special s
symbol (L.Concat sl) = concatMap symbol sl
--
Expand Down Expand Up @@ -272,13 +273,14 @@ escapeChars '_' = "\\_"
escapeChars c = [c]

symbolNeeds :: L.Symbol -> MathContext
symbolNeeds (L.Atomic _) = Text
symbolNeeds (L.Special _) = Math
symbolNeeds (L.Concat []) = Math
symbolNeeds (L.Concat (s:_)) = symbolNeeds s
symbolNeeds L.Corners{} = Math
symbolNeeds (L.Atop _ _) = Math
symbolNeeds L.Empty = Curr
symbolNeeds (L.Atomic _) = Text
symbolNeeds (L.Roman _) = Math
symbolNeeds (L.Special _) = Math
symbolNeeds (L.Concat []) = Math
symbolNeeds (L.Concat (s:_)) = symbolNeeds s
symbolNeeds L.Corners{} = Math
symbolNeeds (L.Atop _ _) = Math
symbolNeeds L.Empty = Curr

pUnit :: L.USymb -> D
pUnit (L.US ls) = formatu t b
Expand Down

1 comment on commit b7582bb

@JacquesCarette
Copy link
Owner

Choose a reason for hiding this comment

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

This is the right code, but the wrong design (as commented in the issue). We should not be trying to encode display information in the symbols - instead, we should embed semantic information in the symbol that later lets us derive display information.

Please sign in to comment.