Skip to content

Commit

Permalink
Merge branch 'master' into addLabels
Browse files Browse the repository at this point in the history
  • Loading branch information
niazim3 committed Jul 6, 2018
2 parents a818d89 + 3b2993c commit 21b0c88
Show file tree
Hide file tree
Showing 24 changed files with 358 additions and 53 deletions.
46 changes: 39 additions & 7 deletions code/drasil-code/Language/Drasil/Code.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,44 @@ module Language.Drasil.Code (
) where

import Prelude hiding (break, print, return, log, exp)
import Language.Drasil.Code.Imperative.AST
import Language.Drasil.Code.Imperative.AST (alwaysDel, neverDel, assign, at, binExpr,
break, cast, constDecDef, extends, for,
forEach, ifCond, ifExists, listDec, listDec', listDecValues, listOf, litBool, litChar,
litFloat, litInt, litObj, litObj', litString, noElse, noParent, objDecDef, oneLiner, param,
params, paramToVar, print, printLn, printStr, printStrLn, printFile, printFileLn, printFileStr,
openFileR, openFileW, closeFile, getInput, getFileInput, getFileInputAll, getFileInputLine,
printFileStrLn, return, returnVar, switch, throw, tryCatch, typ, varDec, varDecDef,
while, zipBlockWith, zipBlockWith4, addComments, comment, commentDelimit,
endCommentDelimit, prefixFirstBlock, getterName, setterName, convertToClass,
convertToMethod, bodyReplace, funcReplace, valListReplace, objDecNew,
objDecNewVoid, objDecNew', objDecNewVoid',
listSize, listAccess, listAppend, listSlice, stringSplit,
var, svToVar, objMethodCall, objMethodCallVoid, valStmt, funcApp, funcApp', func, continue,
toAbsCode, getClassName, buildModule, moduleName,
(?!), (?<), (?<=), (?>), (?>=), (?==), (?!=), (?&&), (?||),
(#~), (#/^), (#|), (#+), (#-), (#*), (#/), (#%), (#^),
(&=), (&.=), (&=.), (&+=), (&-=), (&++), (&~-), (&.+=), (&.-=), (&.++), (&.~-),
($->), ($.), ($:), log, exp,
Body, Class, StateVar, Value, Parameter, Module, FunctionDecl,
Label, StateType, Library, Statement,
bool, int, float, char, string, infile, outfile, listT, obj,
arg, self,
methodType, methodTypeVoid, block, defaultValue, true, false,
pubClass, privClass, privMVar, pubMVar, pubGVar, privMethod, pubMethod, constructor,
mainMethod)

import Language.Drasil.Code.Imperative.LanguageRenderer (Options(..))
import Language.Drasil.Code.Imperative.Parsers.ConfigParser
import Language.Drasil.Code.CodeGeneration

import Language.Drasil.Code.Imperative.Parsers.ConfigParser (cSharpLabel, cppLabel,
goolLabel, javaLabel, objectiveCLabel, pythonLabel, luaLabel)

import Language.Drasil.Code.CodeGeneration (makeCode, createCodeFiles)

import Language.Drasil.Code.DataDesc (Ind(..), junk, junkLine, listEntry, multiLine, repeated, singleLine, singleton)
import Language.Drasil.CodeSpec (($:=), Choices(..), CodeSpec, Comments(..), ConstraintBehaviour(..), Func,
FuncStmt(..), ImplementationType(..), Lang(..), Logging(..), Mod(Mod), Structure(..), asExpr, asVC, codeSpec, fdec,
ffor, funcData, funcDef, packmod, relToQD)
import Language.Drasil.Generate (gen, genCode)

import Language.Drasil.CodeSpec (($:=), Choices(..), CodeSpec, Comments(..), ConstraintBehaviour(..),
Func, FuncStmt(..), ImplementationType(..), Lang(..), Logging(..), Mod(Mod), Structure(..),
asExpr, asVC, codeSpec, fdec, ffor, funcData, funcDef, packmod, relToQD,
)

import Language.Drasil.Generate (gen, genCode)
5 changes: 2 additions & 3 deletions code/drasil-code/Language/Drasil/Code/AST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

module Language.Drasil.Code.AST where

import Language.Drasil.Chunk
import Language.Drasil.Chunk.Eq
import Language.Drasil

type HighLevelCode = [Module]
type Name = String
Expand Down Expand Up @@ -41,4 +40,4 @@ data Objective where

data Output where
Str :: String -> Output
Var :: (Quantity c) => c -> Output
Var :: (Quantity c) => c -> Output
2 changes: 1 addition & 1 deletion code/drasil-code/Language/Drasil/Code/Code.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ data CodeType = Boolean
| String
| File
| List CodeType
| Object String
| Object String
2 changes: 1 addition & 1 deletion code/drasil-code/Language/Drasil/Code/CodeGeneration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Language.Drasil.Code.Imperative.LanguageRenderer (Options)
import Data.List (intercalate)
import qualified Data.Map as Map (fromList,keys,lookup,Map)
import Text.PrettyPrint.HughesPJ (Doc,render)
import System.IO
import System.IO (hPutStrLn, hClose, openFile, IOMode(WriteMode))
import Data.Function (fix)

-- | Map of (label,config) pairs for all supported languages.
Expand Down
2 changes: 1 addition & 1 deletion code/drasil-code/Language/Drasil/Code/DataDesc.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Language.Drasil.Code.DataDesc where

import Language.Drasil
import Language.Drasil.Chunk.Code
import Language.Drasil.Chunk.Code (CodeChunk, codevar)

import Data.List (nub)

Expand Down
3 changes: 2 additions & 1 deletion code/drasil-code/Language/Drasil/Code/Imperative/Helpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import Control.Monad (filterM)
import Data.Char (toUpper)
import Data.String.Utils (replace)
import Data.List (nub,intersperse)
import Text.PrettyPrint.HughesPJ
import Text.PrettyPrint.HughesPJ (Doc, vcat, hcat, text, char, doubleQuotes,
(<>), ($+$), comma, punctuate, nest)

blank :: Doc
blank = text ""
Expand Down
4 changes: 3 additions & 1 deletion code/drasil-data/Data/Drasil/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module Data.Drasil.Utils
, fmtU
, unwrap
, fterms
, mkDataDef, mkDataDef'
, prodUCTbl
, eqUnR
) where
Expand Down Expand Up @@ -176,6 +175,7 @@ unwrap :: (Maybe UnitDefn) -> Sentence
unwrap (Just a) = Sy (a ^. usymb)
unwrap Nothing = EmptyS

<<<<<<< HEAD
-- Used to help make Qdefinitions when uid, term, and symbol come from the same source
mkDataDef :: (Quantity c) => c -> Expr -> Label -> QDefinition
mkDataDef cncpt equation lbl = datadef (getUnit cncpt) lbl
Expand All @@ -192,6 +192,8 @@ mkDataDef' cncpt equation extraInfo refs lbl = datadef (getUnit cncpt) lbl
datadef Nothing lbl = fromEqn' (cncpt ^. uid) (cncpt ^. term) extraInfo
(eqSymb cncpt) equation refs lbl

=======
>>>>>>> master
prodUCTbl :: [[Sentence]] -> Contents
prodUCTbl cases = Table [S "Actor", titleize input_ +:+ S "and" +:+ titleize output_]
cases
Expand Down
10 changes: 8 additions & 2 deletions code/drasil-example/Drasil/DocumentLanguage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-- instead.
module Drasil.DocumentLanguage where

import Drasil.DocumentLanguage.Definitions (Fields, ddefn, derivation,
import Drasil.DocumentLanguage.Definitions (Fields, ddefn, ddefn', derivation,
instanceModel, gdefn, tmodel)

import Language.Drasil hiding (Manual, Vector) -- Manual - Citation name conflict. FIXME: Move to different namespace
Expand Down Expand Up @@ -193,6 +193,7 @@ data SCSSub where
TMs :: Fields -> [TheoryModel] -> SCSSub
GDs :: Fields -> [GenDefn] -> DerivationDisplay -> SCSSub
DDs :: Fields -> [QDefinition] -> DerivationDisplay -> SCSSub --FIXME: Need DD intro
DDs' :: Fields -> [DataDefinition] -> DerivationDisplay -> SCSSub --FIXME: Need DD intro -- should eventually replace and be renamed to DDs
IMs :: Fields -> [InstanceModel] -> DerivationDisplay -> SCSSub
Constraints :: Sentence -> Sentence -> Sentence -> [Contents] {-Fields -> [UncertainWrapper] -> [ConstrainedChunk]-} -> SCSSub --FIXME: temporary definition?
--FIXME: Work in Progress ^
Expand Down Expand Up @@ -430,14 +431,19 @@ mkSolChSpec si (SCSProg l) =
mkSubSCS _ (SCSSubVerb s) = s
mkSubSCS _ (TMs _ []) = error "There are no Theoretical Models"
mkSubSCS _ (GDs _ [] _) = SSD.genDefnF []
mkSubSCS _ (DDs _ [] _) = error "There are no Data Definitions"
mkSubSCS _ (DDs _ [] _) = error "There are no Data Definitions"
mkSubSCS _ (DDs' _ [] _) = error "There are no Data Definitions" --FIXME: temporary duplicate
mkSubSCS _ (IMs _ [] _) = error "There are no Instance Models"
mkSubSCS si' (TMs fields ts) =
SSD.thModF (siSys si') (map (tmodel fields (_sysinfodb si')) ts)
mkSubSCS si' (DDs fields dds ShowDerivation) = --FIXME: need to keep track of DD intro.
SSD.dataDefnF EmptyS (concatMap (\x -> ddefn fields (_sysinfodb si') x : derivation x) dds)
mkSubSCS si' (DDs fields dds _) =
SSD.dataDefnF EmptyS (map (ddefn fields (_sysinfodb si')) dds)
mkSubSCS si' (DDs' fields dds ShowDerivation) = --FIXME: need to keep track of DD intro. --FIXME: temporary duplicate
SSD.dataDefnF EmptyS (concatMap (\x -> ddefn' fields (_sysinfodb si') x : derivation x) dds)
mkSubSCS si' (DDs' fields dds _) = --FIXME: temporary duplicate
SSD.dataDefnF EmptyS (map (ddefn' fields (_sysinfodb si')) dds)
mkSubSCS si' (GDs fields gs' ShowDerivation) =
SSD.genDefnF (concatMap (\x -> gdefn fields (_sysinfodb si') x : derivation x) gs')
mkSubSCS si' (GDs fields gs' _) =
Expand Down
34 changes: 32 additions & 2 deletions code/drasil-example/Drasil/DocumentLanguage/Definitions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Drasil.DocumentLanguage.Definitions
, Field(..)
, Verbosity(..)
, tmodel
, ddefn
, ddefn, ddefn'
, gdefn, derivation
, instanceModel
, InclUnits(..)
Expand Down Expand Up @@ -50,6 +50,9 @@ tmodel fs m t = Defnt TM (foldr (mkTMField t m) [] fs) (refAdd t)
ddefn :: HasSymbolTable ctx => Fields -> ctx -> QDefinition -> Contents
ddefn fs m d = Defnt DD (foldr (mkQField d m) [] fs) (refAdd d)

ddefn' :: HasSymbolTable ctx => Fields -> ctx -> DataDefinition -> Contents
ddefn' fs m d = Defnt DD (foldr (mkDDField d m) [] fs) (refAdd d)

-- | Create a general definition using a list of fields, database of symbols,
-- and a 'GenDefn' (general definition) chunk (called automatically by 'SCSSub'
-- program)
Expand Down Expand Up @@ -97,7 +100,7 @@ tConToExpr (TCon AssumedCon x) = x
-- TODO: buildDescription gets list of constraints to expr and ignores 't'.

-- | Create the fields for a definition from a QDefinition (used by ddefn)
mkQField :: HasSymbolTable ctx => QDefinition -> ctx -> Field -> ModRow -> ModRow
mkQField :: (HasSymbolTable ctx) => QDefinition -> ctx -> Field -> ModRow -> ModRow
mkQField d _ l@Label fs = (show l, (Paragraph $ at_start d):[]) : fs
mkQField d _ l@Symbol fs = (show l, (Paragraph $ (P $ eqSymb d)):[]) : fs
mkQField d _ l@Units fs = (show l, (Paragraph $ (unit'2Contents d)):[]) : fs
Expand All @@ -110,6 +113,19 @@ mkQField d _ l@(Notes) fs = maybe fs (\ss -> (show l, map Paragraph ss) : fs) (d
mkQField _ _ label _ = error $ "Label " ++ show label ++ " not supported " ++
"for data definitions"

-- | Create the fields for a definition from a QDefinition (used by ddefn)
mkDDField :: (HasSymbolTable ctx) => DataDefinition -> ctx -> Field -> ModRow -> ModRow
mkDDField d _ l@Label fs = (show l, (Paragraph $ at_start d):[]) : fs
mkDDField d _ l@Symbol fs = (show l, (Paragraph $ (P $ eqSymb d)):[]) : fs
mkDDField d _ l@Units fs = (show l, (Paragraph $ (unit'2Contents d)):[]) : fs
mkDDField d _ l@DefiningEquation fs = (show l, (eqUnR $ sy d $= d ^. relat):[]) : fs --FIXME: appending symbol should be done in the printing stage
mkDDField d m l@(Description v u) fs =
(show l, buildDDescription' v u d m) : fs
mkDDField _ _ l@(RefBy) fs = (show l, fixme) : fs --FIXME: fill this in
mkDDField d _ l@(Source) fs = (show l, [Paragraph $ getSource d]) : fs
mkDDField d _ l@(Notes) fs = maybe fs (\ss -> (show l, map Paragraph ss) : fs) (d ^. getNotes)
mkDDField _ _ label _ = error $ "Label " ++ show label ++ " not supported " ++
"for data definitions"

-- | Create the description field (if necessary) using the given verbosity and
-- including or ignoring units for a model / general definition
Expand All @@ -127,6 +143,14 @@ buildDDescription Succinct u d _ = [Enumeration (Definitions $ (firstPair u d):[
buildDDescription Verbose u d m = [Enumeration (Definitions
(firstPair u d : descPairs u (vars (d^.equat) m)))]

-- | Create the description field (if necessary) using the given verbosity and
-- including or ignoring units for a data definition
buildDDescription' :: HasSymbolTable ctx => Verbosity -> InclUnits -> DataDefinition -> ctx ->
[Contents]
buildDDescription' Succinct u d _ = [Enumeration (Definitions $ (firstPair' u d):[])]
buildDDescription' Verbose u d m = [Enumeration (Definitions
(firstPair' u d : descPairs u (vars (d^.relat) m)))]

-- | Create the fields for a general definition from a 'GenDefn' chunk.
mkGDField :: HasSymbolTable ctx => GenDefn -> ctx -> Field -> ModRow -> ModRow
mkGDField g _ l@Label fs = (show l, (Paragraph $ at_start g):[]) : fs
Expand Down Expand Up @@ -173,6 +197,12 @@ firstPair :: InclUnits -> QDefinition -> ListPair
firstPair (IgnoreUnits) d = (P (eqSymb d), Flat (phrase d))
firstPair (IncludeUnits) d = (P (eqSymb d), Flat (phrase d +:+ sParen (unit'2Contents d)))

-- | Used for definitions. The first pair is the symbol of the quantity we are
-- defining.
firstPair' :: InclUnits -> DataDefinition -> ListPair
firstPair' (IgnoreUnits) d = (P (eqSymb d), Flat (phrase d))
firstPair' (IncludeUnits) d = (P (eqSymb d), Flat (phrase d +:+ sParen (unit'2Contents d)))

-- | Create the descriptions for each symbol in the relation/equation
descPairs :: (Quantity q) => InclUnits -> [q] -> [ListPair]
descPairs IgnoreUnits = map (\x -> (P (eqSymb x), Flat $ phrase x))
Expand Down
1 change: 0 additions & 1 deletion code/drasil-example/Drasil/GamePhysics/DataDefs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import qualified Data.Drasil.Quantities.Math as QM (orientation)
import qualified Data.Drasil.Quantities.Physics as QP (angularAccel,
angularDisplacement, angularVelocity, displacement, impulseS, linearAccel,
linearDisplacement, linearVelocity, position, restitutionCoef, time, velocity)
import Data.Drasil.Utils (mkDataDef)

----- Data Definitions -----

Expand Down
8 changes: 4 additions & 4 deletions code/drasil-example/Drasil/GlassBR/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import Drasil.GlassBR.Changes (likelyChanges_SRS, unlikelyChanges_SRS)
import Drasil.GlassBR.Concepts (aR, lShareFac, gLassBR, stdOffDist, glaSlab,
blastRisk, glass, glaPlane, glassBRProg, ptOfExplsn, acronyms)
import Drasil.GlassBR.DataDefs (dataDefns, gbQDefns, hFromt, strDisFac, nonFL,
dimLL, glaTyFac, tolStrDisFac, tolPre, risk)
dimLL, glaTyFac, tolStrDisFac, tolPre, risk, qDefns)
import Drasil.GlassBR.ModuleDefs (allMods)
import Drasil.GlassBR.References (rbrtsn2012)
import Drasil.GlassBR.Symbols (this_symbols)
Expand Down Expand Up @@ -125,7 +125,7 @@ mkSRS = RefSec (RefProg intro [TUnits, tsymb [TSPurpose, SymbOrder], TAandA]) :
[ Assumptions
, TMs ([Label] ++ stdFields) [t1IsSafe, t2IsSafe]
, GDs [] [] HideDerivation -- No Gen Defs for GlassBR
, DDs ([Label, Symbol, Units] ++ stdFields) dataDefns ShowDerivation
, DDs' ([Label, Symbol, Units] ++ stdFields) dataDefns ShowDerivation
, IMs ([Label, Input, Output, InConstraints, OutConstraints] ++ stdFields) [probOfBreak, calofCapacity, calofDemand, testIMFromQD] HideDerivation
, Constraints (EmptyS) (dataConstraintUncertainty)
(foldlSent [(makeRef (SRS.valsOfAuxCons SRS.missingP [])), S "gives", (plural value `ofThe` S "specification"),
Expand Down Expand Up @@ -161,7 +161,7 @@ glassSystInfo = SI {
_units = map unitWrapper [metre, second, kilogram] ++ map unitWrapper [pascal, newton],
_quants = this_symbols,
_concepts = [] :: [DefinedQuantityDict],
_definitions = dataDefns ++
_definitions = qDefns ++
(map (relToQD gbSymbMap) iModels {-[RelationConcept]-}) ++
(map (relToQD gbSymbMap) tModels {-[RelationConcept]-}) ++
[wtntWithEqn, sdWithEqn], -- wtntWithEqn is defined in Unitals but only appears
Expand Down Expand Up @@ -622,7 +622,7 @@ traceability_matrices_and_graphs_instaModel = ["IM1", "IM2", "IM3"]
traceability_matrices_and_graphs_instaModelRef = map (refFromType Theory) iModels

traceability_matrices_and_graphs_dataDef = ["DD1", "DD2", "DD3", "DD4", "DD5", "DD6", "DD7", "DD8"]
traceability_matrices_and_graphs_dataDefRef = map (refFromType Data) dataDefns
traceability_matrices_and_graphs_dataDefRef = map (refFromType Data') dataDefns

traceability_matrices_and_graphs_data = ["Data Constraints"]
traceability_matrices_and_graphs_dataRef = [makeRef (SRS.datCon SRS.missingP [])]
Expand Down
Loading

0 comments on commit 21b0c88

Please sign in to comment.