Verified Commit 3a3be791 authored by Camil Staps's avatar Camil Staps 🚀

Use new maybe type

parent 39ff82e2
......@@ -10,7 +10,6 @@ from StdOverloaded import class zero, class fromString, class toString,
from Data.Error import :: MaybeError, :: MaybeErrorString
from Data.GenEq import generic gEq
from Data.Maybe import :: Maybe
from Text.GenJSON import generic JSONEncode, generic JSONDecode, :: JSONNode
/**
......
......@@ -33,8 +33,8 @@ derive gEq FunctionKind
JSONEncode{|ABCArgument|} _ arg = [JSONString (toString arg)]
JSONDecode{|ABCArgument|} _ [JSONString s:r] = (Just (fromString s), r)
JSONDecode{|ABCArgument|} _ json = (Nothing, json)
JSONDecode{|ABCArgument|} _ [JSONString s:r] = (?Just (fromString s), r)
JSONDecode{|ABCArgument|} _ json = (?None, json)
instance toInt CloogleError
where
......@@ -109,18 +109,18 @@ where
instance zero Request
where
zero =
{ unify = Nothing
, name = Nothing
, exactName = Nothing
, className = Nothing
, typeName = Nothing
, using = Nothing
, modules = Nothing
, libraries = Nothing
, include_builtins = Nothing
, include_core = Nothing
, include_apps = Nothing
, page = Nothing
{ unify = ?None
, name = ?None
, exactName = ?None
, className = ?None
, typeName = ?None
, using = ?None
, modules = ?None
, libraries = ?None
, include_builtins = ?None
, include_core = ?None
, include_apps = ?None
, page = ?None
}
instance zero Response
......@@ -129,9 +129,9 @@ where
{ return = 0
, msg = "Success"
, data = []
, more_available = Nothing
, suggestions = Nothing
, warnings = Nothing
, more_available = ?None
, suggestions = ?None
, warnings = ?None
}
instance toString Request where toString r = toString $ toJSON r
......@@ -162,27 +162,27 @@ where
instance == FunctionKind where (==) a b = a === b
getBasicResult :: !Result -> ?BasicResult
getBasicResult (FunctionResult (br,_)) = Just br
getBasicResult (TypeResult (br,_)) = Just br
getBasicResult (ClassResult (br,_)) = Just br
getBasicResult (ModuleResult (br,_)) = Just br
getBasicResult (SyntaxResult (br,_)) = Just br
getBasicResult (ABCInstructionResult (br,_)) = Just br
getBasicResult (ProblemResult _) = Nothing
getBasicResult (FunctionResult (br,_)) = ?Just br
getBasicResult (TypeResult (br,_)) = ?Just br
getBasicResult (ClassResult (br,_)) = ?Just br
getBasicResult (ModuleResult (br,_)) = ?Just br
getBasicResult (SyntaxResult (br,_)) = ?Just br
getBasicResult (ABCInstructionResult (br,_)) = ?Just br
getBasicResult (ProblemResult _) = ?None
parseSingleLineRequest :: !String -> MaybeErrorString Request
parseSingleLineRequest s = case split "::" s of
["",type] -> Ok {zero & unify=Just $ trim type}
[name,type] -> Ok {zero & name=Just $ trim name, unify=Just $ trim type}
[name] -> Ok {Request | zero & name=Just $ trim name}
["",type] -> Ok {zero & unify= ?Just $ trim type}
[name,type] -> Ok {zero & name= ?Just $ trim name, unify= ?Just $ trim type}
[name] -> Ok {Request | zero & name= ?Just $ trim name}
_ -> Error "Multiple ::s found"
toSingleLine :: !Request -> ?String
toSingleLine req
| isJust req.typeName && isJust req.className = Nothing
| isJust req.typeName && isJust req.className = ?None
| isJust req.typeName = req.typeName
| isJust req.className = req.className
| isJust req.unify = case req.Request.name of
Nothing -> Just $ ":: " + fromJust req.unify
Just n -> Just $ n + " :: " + fromJust req.unify
?None -> ?Just $ ":: " + fromJust req.unify
?Just n -> ?Just $ n + " :: " + fromJust req.unify
| otherwise = req.Request.name
......@@ -40,5 +40,5 @@ request req w = appFst ((=<<) parseResponse) $ doHTTPRequest (toHTTPRequest req)
where
parseResponse :: HTTPResponse -> MaybeErrorString Response
parseResponse res = case fromJSON $ fromString res.rsp_data of
Nothing -> Error "Invalid JSON"
Just r -> Ok r
?None -> Error "Invalid JSON"
?Just r -> Ok r
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment