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)]
|
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}) |-> _}
|