CurryInfo: cass-4.1.0 / CASS.ServerFormats.formatResult

definition:
formatResult :: String -> OutputFormat -> Maybe String -> Bool -> Bool
             -> (Either (ProgInfo String) String) -> String
formatResult _ outForm _ _ _ (Right err) =
  case outForm of FormatXML      -> showXmlDoc (xml "error" [xtxt errMsg])
                  FormatJSON     -> ppJSON (JString errMsg)
                  FormatJSONTerm -> ppJSON (JString errMsg)
                  _              -> errMsg
 where errMsg = "ERROR in analysis: " ++ err
-- Format a single program entity result:
formatResult moduleName outForm (Just name) _ _ (Left pinfo) =
  case lookupProgInfo (moduleName,name) pinfo of
    Nothing    -> "ERROR " ++ name ++ " not found in " ++ moduleName
    Just value -> case outForm of
                    FormatXML      -> showXmlDoc (xml "result" [xtxt value])
                    FormatJSON     -> ppJSON (JString value)
                    FormatJSONTerm -> ppJSON (JString value)
                    _              -> value
-- Format the analysis results of a complete module:
formatResult moduleName outForm Nothing public generated (Left pinfo) =
  case outForm of
    FormatTerm     -> show entities ++ "\n"
    FormatXML      -> showXmlDoc $ xml "results" $ map entry2xml entities
    FormatJSON     -> entitiesAsJSON
    FormatJSONTerm -> entitiesAsJSON
    _              -> formatAsText moduleName entities
 where
  (pubents,privents) = progInfo2Lists pinfo

  entities = filter (\(qn,_) -> generated || isCurryID qn)
                    (if public then pubents
                               else sortBy (\ (qf1,_) (qf2,_) -> qf1 <= qf2)
                                           (pubents ++ privents))

  entry2xml ((mname,name),value) =
    xml "operation" [xml "module" [xtxt mname],
                     xml "name"   [xtxt name],
                     xml "result" [xtxt value]]

  entitiesAsJSON = ppJSON (JArray $ map entry2json entities) ++ "\n"

  entry2json ((mname,name),value) =
    JObject [("module", JString mname),
             ("name"  , JString name),
             ("result", JString value)]
demand:
argument 6
deterministic:
deterministic operation
documentation:
--- Format an analysis result in different formats.
--- The arguments are the module name, the output format,
--- `(Just n)` if not the complete module but the result for entity `n`
--- should only be shown, a flag which is true if only the interface
--- information should be shown, and a flag which is true if also
--- generated operations should be shown.
failfree:
<FAILING>
indeterministic:
referentially transparent operation
infix:
no fixity defined
iotype:
{(_,{FormatXML},_,_,_,{Right}) |-> _ || (_,{FormatJSON},_,_,_,{Right}) |-> _ || (_,{FormatJSONTerm},_,_,_,{Right}) |-> _ || (_,{FormatText},_,_,_,{Right}) |-> _ || (_,{FormatShort},_,_,_,{Right}) |-> _ || (_,{FormatTerm},_,_,_,{Right}) |-> _ || (_,_,{Just},_,_,{Left}) |-> _ || (_,{FormatXML},{Just},_,_,{Left}) |-> _ || (_,{FormatJSON},{Just},_,_,{Left}) |-> _ || (_,{FormatJSONTerm},{Just},_,_,{Left}) |-> _ || (_,{FormatText},{Just},_,_,{Left}) |-> _ || (_,{FormatShort},{Just},_,_,{Left}) |-> _ || (_,{FormatTerm},{Just},_,_,{Left}) |-> _ || (_,{FormatTerm},{Nothing},_,_,{Left}) |-> _ || (_,{FormatXML},{Nothing},_,_,{Left}) |-> _ || (_,{FormatJSON},{Nothing},_,_,{Left}) |-> _ || (_,{FormatJSONTerm},{Nothing},_,_,{Left}) |-> _ || (_,{FormatText},{Nothing},_,_,{Left}) |-> _ || (_,{FormatShort},{Nothing},_,_,{Left}) |-> _}
name:
formatResult
precedence:
no precedence defined
result-values:
_
signature:
String -> OutputFormat -> Prelude.Maybe String -> Prelude.Bool -> Prelude.Bool
-> Prelude.Either (Analysis.ProgInfo.ProgInfo String) String -> String
solution-complete:
operation might suspend on free variables
terminating:
possibly non-terminating
totally-defined:
possibly non-reducible on same data term