Verified Commit aab46cfb authored by Camil Staps's avatar Camil Staps
Browse files

Add SyntaxResult for clean-cloogle/cloogle.org#130

parent 9774125c
......@@ -18,30 +18,30 @@ from GenEq import generic gEq
/**
* A Cloogle request
*/
:: Request
= { unify :: Maybe String //* Functions that unify with this type
, name :: Maybe String //* Entries that match this name
, className :: Maybe String //* Exactly this class
, typeName :: Maybe String //* Exactly this type
, modules :: Maybe [String] //* Modules to search in
, libraries :: Maybe [String] //* Libraries to search in
, include_builtins :: Maybe Bool //* Whether language builtins should be included
, include_core :: Maybe Bool //* Whether library core modules should be included
, include_apps :: Maybe Bool //* Whether app modules should be included
, page :: Maybe Int //* Pagination of the results
}
:: Request =
{ unify :: Maybe String //* Functions that unify with this type
, name :: Maybe String //* Entries that match this name
, className :: Maybe String //* Exactly this class
, typeName :: Maybe String //* Exactly this type
, modules :: Maybe [String] //* Modules to search in
, libraries :: Maybe [String] //* Libraries to search in
, include_builtins :: Maybe Bool //* Whether language builtins should be included
, include_core :: Maybe Bool //* Whether library core modules should be included
, include_apps :: Maybe Bool //* Whether app modules should be included
, page :: Maybe Int //* Pagination of the results
}
/**
* A Cloogle response
*/
:: Response
= { return :: Int //* A return code (use fromInt of CloogleError)
, data :: [Result] //* The actual results
, msg :: String //* A human-readable message describing the return code
, more_available :: Maybe Int //* How many more results are available in next pages
, suggestions :: Maybe [(Request, Int)]
//* Suggestions for related requests and how many results they have
}
:: Response =
{ return :: Int //* A return code (use fromInt of CloogleError)
, data :: [Result] //* The actual results
, msg :: String //* A human-readable message describing the return code
, more_available :: Maybe Int //* How many more results are available in next pages
, suggestions :: Maybe [(Request, Int)]
//* Suggestions for related requests and how many results they have
}
/**
* A single Cloogle result
......@@ -51,20 +51,21 @@ from GenEq import generic gEq
| TypeResult TypeResult //* A type definition
| ClassResult ClassResult //* A class definition
| ModuleResult ModuleResult //* A module
| SyntaxResult SyntaxResult //* A Clean language syntax element
/**
* Basic data that is included in any Cloogle result
*/
:: BasicResult
= { library :: String //* The library the entry was found in
, filename :: String //* The basename of the definition module
, modul :: String //* The full (hierarchical) module name
, dcl_line :: Maybe Int //* The line in the definition module of this entry
, icl_line :: Maybe Int //* The line in the implementation module of this entry
, distance :: Int //* A distancy measure, lower is more relevant
, builtin :: Maybe Bool //* Whether this is a builtin function
, documentation :: Maybe String //* The CleanDoc description for this result
}
:: BasicResult =
{ library :: String //* The library the entry was found in
, filename :: String //* The basename of the definition module
, modul :: String //* The full (hierarchical) module name
, dcl_line :: Maybe Int //* The line in the definition module of this entry
, icl_line :: Maybe Int //* The line in the implementation module of this entry
, distance :: Int //* A distancy measure, lower is more relevant
, builtin :: Maybe Bool //* Whether this is a builtin function
, documentation :: Maybe String //* The CleanDoc description for this result
}
/**
* Cloogle result about a function, generic, class member, constructor or
......@@ -86,21 +87,21 @@ from GenEq import generic gEq
/**
* Function-specific Cloogle result data
*/
:: FunctionResultExtras
= { func :: String //* A string representation of the type
, kind :: FunctionKind //* The kind of function
, unifier :: Maybe StrUnifier //* A unifier, if the request included a type
, required_context :: Maybe [(String, [LocationResult])] //* Instances or derivations that are needed (if the request included a type)
, cls :: Maybe ShortClassResult //* The class, if this is a class member
, constructor_of :: Maybe String //* The type that this is a constructor of
, recordfield_of :: Maybe String //* The type that this is a record field of
, generic_derivations :: Maybe [(String, [LocationResult])]
//* Derivations, if this is a generic function, and their locations
, param_doc :: Maybe [String] //* Documentation of the parameters
, generic_var_doc :: Maybe [String] //* Documentation of the generic type variables
, result_doc :: Maybe String //* Documentation of the result
, type_doc :: Maybe String //* Documentation of the type (for macros)
}
:: FunctionResultExtras =
{ func :: String //* A string representation of the type
, kind :: FunctionKind //* The kind of function
, unifier :: Maybe StrUnifier //* A unifier, if the request included a type
, required_context :: Maybe [(String, [LocationResult])] //* Instances or derivations that are needed (if the request included a type)
, cls :: Maybe ShortClassResult //* The class, if this is a class member
, constructor_of :: Maybe String //* The type that this is a constructor of
, recordfield_of :: Maybe String //* The type that this is a record field of
, generic_derivations :: Maybe [(String, [LocationResult])]
//* Derivations, if this is a generic function, and their locations
, param_doc :: Maybe [String] //* Documentation of the parameters
, generic_var_doc :: Maybe [String] //* Documentation of the generic type variables
, result_doc :: Maybe String //* Documentation of the result
, type_doc :: Maybe String //* Documentation of the type (for macros)
}
/**
* Cloogle result about a type definition
......@@ -112,20 +113,20 @@ from GenEq import generic gEq
/**
* Type-specific Cloogle result data
*/
:: TypeResultExtras
= { type :: String
//* A string representation of the definition
, type_instances :: [(String, [String], [LocationResult])]
//* Instances of the type: the class, the class parameters and the locations of the instance
, type_derivations :: [(String, [LocationResult])]
//* Generic derivations of the type: the generic and the locations of the derivation
, type_field_doc :: Maybe [Maybe String]
//* Documentation of the record fields
, type_constructor_doc :: Maybe [Maybe String]
//* Documentation of the constructors
, type_representation_doc :: Maybe String
//* Documentation of the synonym type representation
}
:: TypeResultExtras =
{ type :: String
//* A string representation of the definition
, type_instances :: [(String, [String], [LocationResult])]
//* Instances of the type: the class, the class parameters and the locations of the instance
, type_derivations :: [(String, [LocationResult])]
//* Generic derivations of the type: the generic and the locations of the derivation
, type_field_doc :: Maybe [Maybe String]
//* Documentation of the record fields
, type_constructor_doc :: Maybe [Maybe String]
//* Documentation of the constructors
, type_representation_doc :: Maybe String
//* Documentation of the synonym type representation
}
/**
* Cloogle result about a class definition
......@@ -137,46 +138,72 @@ from GenEq import generic gEq
/**
* Class-specific Cloogle result data
*/
:: ClassResultExtras
= { class_name :: String //* The name of the class
, class_heading :: String //* The class name and variables
, class_funs :: [String] //* The class members (may contain newlines if there are macros)
, class_instances :: [([String], [LocationResult])]
//* Instances of the class: the types and the locations of the instances
, class_derivations :: [(String, [LocationResult])]
//* Derivations of meta-classes like iTask
}
:: ClassResultExtras =
{ class_name :: String //* The name of the class
, class_heading :: String //* The class name and variables
, class_funs :: [String] //* The class members (may contain newlines if there are macros)
, class_instances :: [([String], [LocationResult])]
//* Instances of the class: the types and the locations of the instances
, class_derivations :: [(String, [LocationResult])]
//* Derivations of meta-classes like iTask
}
/**
* Cloogle result about a macro
* Cloogle result about a module
*
* @representation A tuple of basic and macro-specific data
* @representation A tuple of basic and module-specific data
*/
:: MacroResult :== (BasicResult, MacroResultExtras)
:: ModuleResult :== (BasicResult, ModuleResultExtras)
/**
* Macro-specific Cloogle result data
* Module-specific Cloogle result data
*/
:: MacroResultExtras
= { macro_name :: String //* The name
, macro_representation :: String //* A string representation
, macro_param_doc :: Maybe [String] //* Documentation of the parameters
, macro_result_doc :: Maybe String //* Documentation of the result
}
:: ModuleResultExtras =
{ module_is_core :: Bool //* Whether this module is part of a library core
}
/**
* Cloogle result about a module
* Cloogle result about a Clean language construct
*
* @representation A tuple of basic and module-specific data
* @representation A tuple of basic and construct-specific data
*/
:: ModuleResult :== (BasicResult, ModuleResultExtras)
:: SyntaxResult :== (BasicResult, SyntaxResultExtras)
/**
* Module-specific Cloogle result data
* Syntax contruct-specific Cloogle result data
*/
:: SyntaxResultExtras =
{ syntax_title :: String //* The name of the construct
, syntax_code :: [String] //* Strings describing the construct, as short as possible
, syntax_description :: String //* A description of the construct
, syntax_doc_location :: [SyntaxDocLocation] //* Where to find documentation on the construct
, syntax_examples :: [SyntaxExample] //* Some code examples (should include comments)
}
/**
* An example of Clean syntax
*/
:: SyntaxExample =
{ example :: String //* The actual code
, cleanjs_type :: String //* The type of thing clean.js will want to see this as
, cleanjs_start :: Maybe String //* The state in which clean.js should start highlighting
}
/**
* A location of syntax documentation
*/
:: SyntaxDocLocation
= CleanLangReport CleanLangReportLocation
/**
* A location in a Clean language report
*/
:: ModuleResultExtras
= { module_is_core :: Bool //* Whether this module is part of a library core
}
:: CleanLangReportLocation =
{ clr_version :: String //* The version of the report
, clr_section :: String //* The section in the report
, clr_file :: String //* The HTML file that section belongs to
, clr_heading :: String //* A heading in the HTML file
}
/**
* A location in a Clean library
......@@ -189,19 +216,19 @@ from GenEq import generic gEq
/**
* A type unifier, represented with strings
*/
:: StrUnifier
= { left_to_right :: [(String,String)] //* Transformations from request to response
, right_to_left :: [(String,String)] //* Transformations from response to request
, used_synonyms :: [(String,String)] //* Synonyms that were used during unification
}
:: StrUnifier =
{ left_to_right :: [(String,String)] //* Transformations from request to response
, right_to_left :: [(String,String)] //* Transformations from response to request
, used_synonyms :: [(String,String)] //* Synonyms that were used during unification
}
/**
* Basic data about a class definition
*/
:: ShortClassResult
= { cls_name :: String //* The name
, cls_vars :: [String] //* The type variables
}
:: ShortClassResult =
{ cls_name :: String //* The name
, cls_vars :: [String] //* The type variables
}
/**
* A Cloogle Error
......@@ -226,10 +253,12 @@ instance fromInt CloogleError
derive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,
FunctionResultExtras, TypeResultExtras, ClassResultExtras, FunctionKind,
MacroResultExtras, ModuleResultExtras, StrUnifier
ModuleResultExtras, SyntaxResultExtras, SyntaxExample, SyntaxDocLocation,
CleanLangReportLocation, StrUnifier
derive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,
FunctionResultExtras, TypeResultExtras, ClassResultExtras, FunctionKind,
MacroResultExtras, ModuleResultExtras, StrUnifier
ModuleResultExtras, SyntaxResultExtras, SyntaxExample, SyntaxDocLocation,
CleanLangReportLocation, StrUnifier
derive gEq FunctionKind
instance zero Request
......
......@@ -19,10 +19,12 @@ import GenEq
derive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,
FunctionResultExtras, TypeResultExtras, ClassResultExtras, FunctionKind,
MacroResultExtras, ModuleResultExtras, StrUnifier
ModuleResultExtras, SyntaxResultExtras, SyntaxExample, SyntaxDocLocation,
CleanLangReportLocation, StrUnifier
derive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,
FunctionResultExtras, TypeResultExtras, ClassResultExtras, FunctionKind,
MacroResultExtras, ModuleResultExtras, StrUnifier
ModuleResultExtras, SyntaxResultExtras, SyntaxExample, SyntaxDocLocation,
CleanLangReportLocation, StrUnifier
derive gEq FunctionKind
instance toInt CloogleError
......@@ -84,6 +86,7 @@ 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