<commit_before>module Language.Drasil.Template.MIS (makeMIS) where

import Language.Drasil.Document
import Language.Drasil.Spec
import Language.Drasil.Chunk
import Language.Drasil.Chunk.Module
import Language.Drasil.Chunk.Method
import Language.Drasil.Template.Helpers

import Data.List (intersperse, concat)
import Control.Lens ((^.))

makeMIS :: [ModuleChunk] -> [Section]
makeMIS mcs = misIntro:map misModule mcs

misIntro :: Section
misIntro = Section (S $ "Introduction")
  [ Con $ Paragraph $
    S "The following document details the Module Interface Specifications " :+:
    S "for the implemented modules in a program that calculates . " :+:
    S "It is intended to ease navigation through the program for design " :+:
    S "and maintenance purposes.  Complementary documents include the " :+:
    S "System Requirement Specifications and Module Guide."
  ]

misModule :: ModuleChunk -> Section
misModule mc = Section (S $ "MIS for " ++ formatName mc)
  [ Sub $ misInterfaceSyntax mc,
    Sub $ misInterfaceSemantics mc ]

misInterfaceSyntax :: ModuleChunk -> Section
misInterfaceSyntax mc = Section (S $ "Interface Syntax")
  [ Sub $ Section (S $ "Exported Access Programs")
    [ Con $ misExportedAP mc ]
  ]

-- var types not implemented yet so just map to "real" for now
misExportedAP :: ModuleChunk -> Contents
misExportedAP mc = Table [S "Name", S "In", S "Out", S "Exceptions"]
  ( map ( \x -> (convertName (x ^. name)) :
                (S $ concat $ intersperse ", " $ map (\_ -> "real") (input x)) :
                (S $ concat $ intersperse ", " $ map (\_ -> "real") (output x)) :
                (S $ concat $ intersperse ", " $ map show (exc x)) :
                [] ) (method mc)
  ) (S $ "Access programs exported by the " ++ formatName mc) False


misInterfaceSemantics :: ModuleChunk -> Section
misInterfaceSemantics mc = Section (S $ "Interface Semantics")
  [ Sub $ Section (S $ "Access Program Semantics")
    (map (Sub . misAPSemantics) (method mc))
  ]

misAPSemantics :: MethodChunk -> Section
misAPSemantics mec = Section (convertName (mec ^. name))
  [ Con $ Enumeration $ Desc
    [(S "Input", Flat $ foldl1 (:+:) $
        intersperse (S ", ") $ map (\x -> P $ x ^. symbol) (input mec)),
     (S "Exceptions", Flat $ foldl1 (:+:) $
        intersperse (S ", ") $ map (S . show) (exc mec)),
     (S "Output", Flat $ foldl1 (:+:) $
             intersperse (S ", ") $ map (\x -> P $ x ^. symbol) (output mec))
    ]
  ]<commit_msg>Fix for issue #71<commit_after>module Language.Drasil.Template.MIS (makeMIS) where

import Language.Drasil.Document
import Language.Drasil.Spec
import Language.Drasil.Chunk
import Language.Drasil.Chunk.Module
import Language.Drasil.Chunk.Method
import Language.Drasil.Template.Helpers

import Data.List (intersperse, concat)
import Control.Lens ((^.))

makeMIS :: [ModuleChunk] -> [Section]
makeMIS mcs = misIntro:map misModule mcs

misIntro :: Section
misIntro = Section (S $ "Introduction")
  [ Con $ Paragraph $
    S "The following document details the Module Interface Specifications " :+:
    S "for the implemented modules in a program that calculates . " :+:
    S "It is intended to ease navigation through the program for design " :+:
    S "and maintenance purposes.  Complementary documents include the " :+:
    S "System Requirement Specifications and Module Guide."
  ]

misModule :: ModuleChunk -> Section
misModule mc = Section (S $ "MIS for " ++ formatName mc)
  [ Sub $ misInterfaceSyntax mc,
    Sub $ misInterfaceSemantics mc ]

misInterfaceSyntax :: ModuleChunk -> Section
misInterfaceSyntax mc = Section (S $ "Interface Syntax")
  [ Sub $ Section (S $ "Exported Access Programs")
    [ Con $ misExportedAP mc ]
  ]

-- var types not implemented yet so just map to "real" for now
misExportedAP :: ModuleChunk -> Contents
misExportedAP mc = Table [S "Name", S "In", S "Out", S "Exceptions"]
  ( map ( \x -> (convertName (x ^. name)) :
                (S $ concat $ intersperse ", " $ map (\_ -> "real") (input x)) :
                (S $ concat $ intersperse ", " $ map (\_ -> "real") (output x)) :
                (S $ concat $ intersperse ", " $ map show (exc x)) :
                [] ) (method mc)
  ) (S $ "Access programs exported by the " ++ formatName mc) False


misInterfaceSemantics :: ModuleChunk -> Section
misInterfaceSemantics mc = Section (S $ "Interface Semantics")
  [ Sub $ Section (S $ "Access Program Semantics")
    (map (Sub . misAPSemantics) (method mc))
  ]

misAPSemantics :: MethodChunk -> Section
misAPSemantics mec = Section (convertName (mec ^. name))
  [ Con $ Enumeration $ Desc
    [(S "Input", Flat $ foldl (:+:) (S "") $
        intersperse (S ", ") $ map (\x -> P $ x ^. symbol) (input mec)),
     (S "Exceptions", Flat $ foldl (:+:) (S "") $
        intersperse (S ", ") $ map (S . show) (exc mec)),
     (S "Output", Flat $ foldl (:+:) (S "") $
             intersperse (S ", ") $ map (\x -> P $ x ^. symbol) (output mec))
    ]
  ]
{'fraction_non_alphanumeric': 0.13821630347054076, 'fraction_numerical': 0.0010088781275221952, 'mean_word_length': 3.1308333333333334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4921406', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1539, 'n_words': 508}