Verified Commit e7d89bff authored by Camil Staps's avatar Camil Staps 🚀

Add ABCInstructionResult

parent 1a13b248
......@@ -52,6 +52,7 @@ from Text.GenJSON import generic JSONEncode, generic JSONDecode, :: JSONNode
| ClassResult ClassResult //* A class definition
| ModuleResult ModuleResult //* A module
| SyntaxResult SyntaxResult //* A Clean language syntax element
| ABCInstructionResult ABCInstructionResult //* An ABC machine instruction
| ProblemResult ProblemResult //* A common problem (see https://github.com/clean-cloogle/common-problems)
/**
......@@ -200,6 +201,34 @@ from Text.GenJSON import generic JSONEncode, generic JSONDecode, :: JSONNode
, cleanjs_start :: Maybe String //* The state in which clean.js should start highlighting
}
/**
* Cloogle result about an ABC instruction.
*
* @representation A tuple of basic and instruction-specific data.
*/
:: ABCInstructionResult :== (BasicResult, ABCInstructionResultExtras)
/**
* Information about an ABC instruction.
*/
:: ABCInstructionResultExtras =
{ abc_instruction :: String //* The name of the instruction
, abc_arguments :: [ABCArgument] //* The arguments
}
/**
* An argument for an ABC instruction.
*/
:: ABCArgument = ABCArgument ABCArgumentType Bool //* The type and whether it is optional or not.
:: ABCArgumentType
= ABCTypeLabel
| ABCTypeBool
| ABCTypeChar
| ABCTypeInt
| ABCTypeReal
| ABCTypeString
/**
* Cloogle result about a common problem (see https://github.com/clean-cloogle/common-problems).
*/
......@@ -261,11 +290,13 @@ instance fromInt CloogleError
derive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,
FunctionResultExtras, TypeResultExtras, ClassResultExtras, FunctionKind,
ModuleResultExtras, SyntaxResultExtras, SyntaxExample,
CleanLangReportLocation, StrUnifier
ABCInstructionResultExtras, ABCArgument, CleanLangReportLocation,
StrUnifier
derive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,
FunctionResultExtras, TypeResultExtras, ClassResultExtras, FunctionKind,
ModuleResultExtras, SyntaxResultExtras, SyntaxExample,
CleanLangReportLocation, StrUnifier
ABCInstructionResultExtras, ABCArgument, CleanLangReportLocation,
StrUnifier
derive gEq FunctionKind
instance zero Request
......
implementation module Cloogle
import _SystemArray
import StdBool
from StdFunc import o
import StdChar
from StdFunc import flip, o
import StdInt
import StdOverloaded
......@@ -12,7 +14,8 @@ import Data.Functor
import Data.Map
import Data.Tuple
import Internet.HTTP
from Text import class Text(join,split,trim), instance Text String, instance + String
from Text import class Text(join,split,trim), instance Text String,
instance + String, <+
import Text.Encodings.UrlEncoding
import Text.GenJSON
......@@ -21,13 +24,37 @@ import Data.GenEq
derive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,
FunctionResultExtras, TypeResultExtras, ClassResultExtras, FunctionKind,
ModuleResultExtras, SyntaxResultExtras, SyntaxExample, ProblemResult,
CleanLangReportLocation, StrUnifier
ABCInstructionResultExtras, CleanLangReportLocation, StrUnifier
derive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,
FunctionResultExtras, TypeResultExtras, ClassResultExtras, FunctionKind,
ModuleResultExtras, SyntaxResultExtras, SyntaxExample, ProblemResult,
CleanLangReportLocation, StrUnifier
ABCInstructionResultExtras, CleanLangReportLocation, StrUnifier
derive gEq FunctionKind
JSONEncode{|ABCArgument|} _ (ABCArgument t r) = [JSONString (if r ("[" <+ type <+ "]") type)]
where
type = case t of
ABCTypeLabel -> "label"
ABCTypeBool -> "bool"
ABCTypeChar -> "char"
ABCTypeInt -> "int"
ABCTypeReal -> "real"
ABCTypeString -> "string"
JSONDecode{|ABCArgument|} _ [JSONString s:r]
| size s > 0 && s.[0] == '[' && s.[size s-1] == ']'
= (flip ABCArgument True <$> fromString (s % (1,size s-2)), r)
= (flip ABCArgument False <$> fromString s, r)
where
fromString s = case s of
"label" -> Just ABCTypeLabel
"bool" -> Just ABCTypeBool
"char" -> Just ABCTypeChar
"int" -> Just ABCTypeInt
"real" -> Just ABCTypeReal
"string" -> Just ABCTypeString
_ -> Nothing
instance toInt CloogleError
where
toInt NoResults = 127
......@@ -90,6 +117,12 @@ instance fromString (Maybe Request) where fromString s = fromJSON $ fromString s
instance < BasicResult where (<) r1 r2 = r1.distance < r2.distance
instance < Result
where
(<) (ABCInstructionResult _) _ = True
(<) (ProblemResult _) _ = True
(<) (SyntaxResult _) _ = True
(<) _ (ABCInstructionResult _) = False
(<) _ (ProblemResult _) = False
(<) _ (SyntaxResult _) = False
(<) r1 r2 = basic r1 < basic r2
where
basic :: Result -> BasicResult
......@@ -97,7 +130,6 @@ where
basic (TypeResult (br,_)) = br
basic (ClassResult (br,_)) = br
basic (ModuleResult (br,_)) = br
basic (SyntaxResult (br,_)) = br
instance == FunctionKind where == a b = a === b
......
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