Verified Commit 37be2bff authored by Camil Staps's avatar Camil Staps 🚀

Rewrite documentation parsing for easier extensibility

parent 85237f51
......@@ -34,7 +34,7 @@ from Type import :: Type, :: TypeVar, :: TVAssignment, :: TypeDef,
from Cloogle import :: FunctionKind, :: SyntaxExample, :: CleanLangReportLocation
from Doc import :: Documentation
from Doc import :: FunctionDoc, :: TypeDoc, :: ClassDoc, :: ModuleDoc
/**
* A storage for function types, class definitions, type definitions, etc.
......@@ -58,24 +58,24 @@ from Doc import :: Documentation
, fe_generic_vars :: !Maybe [String] //* The names of the type variables of a generic function
// Using TypeVar causes import clashes in CloogleDBFactory
, fe_representation :: !Maybe String //* A string representation of the entry
, fe_documentation :: !Maybe Documentation //* Documentation on this entry
, fe_documentation :: !Maybe FunctionDoc //* Documentation on this entry
}
/**
* A TypeDef with meta-data
*/
:: TypeDefEntry
= { tde_typedef :: !TypeDef //* The TypeDef
, tde_doc :: !Maybe Documentation //* Documentation on the TypeDef (a TypeDoc)
= { tde_typedef :: !TypeDef //* The TypeDef
, tde_doc :: !Maybe TypeDoc //* Documentation on the TypeDef
}
/**
* Information about a Clean module
*/
:: ModuleEntry
= { me_is_core :: !Bool //* Whether this is a core module (e.g. the os* modules in ObjectIO and TCPIP)
, me_is_app :: !Bool //* Whether this module is not actually a library but an app
, me_documentation :: !Maybe Documentation //* Documentation on this module (a ModuleDoc)
= { me_is_core :: !Bool //* Whether this is a core module (e.g. the os* modules in ObjectIO and TCPIP)
, me_is_app :: !Bool //* Whether this module is not actually a library but an app
, me_documentation :: !Maybe ModuleDoc //* Documentation on this module
}
/**
......@@ -85,7 +85,7 @@ from Doc import :: Documentation
= { ce_vars :: ![String] //* The type variables of the class
// Using TypeVar causes import clashes in CloogleDBFactory
, ce_context :: !TypeContext //* A class context
, ce_documentation :: !Maybe Documentation //* Documentation on this class (a ClassDoc)
, ce_documentation :: !Maybe ClassDoc //* Documentation on this class
, ce_members :: ![(!Name, !FunctionEntry)] //* Class members: function name and type information
, ce_instances :: ![InstanceEntry] //* All instances of the class
, ce_derivations :: ![DeriveEntry] //* Derivations of generic meta-classes like iTask
......@@ -148,9 +148,9 @@ isBuiltin :: Location -> Bool
isCore :: Location CloogleDB -> Bool
isApp :: Location CloogleDB -> Bool
toTypeDefEntry :: TypeDef (Maybe Documentation) -> TypeDefEntry
toTypeDefEntry :: TypeDef (Maybe TypeDoc) -> TypeDefEntry
getTypeDef :: TypeDefEntry -> TypeDef
getTypeDefDoc :: TypeDefEntry -> Maybe Documentation
getTypeDefDoc :: TypeDefEntry -> Maybe TypeDoc
mergeTypeDefEntries :: TypeDefEntry TypeDefEntry -> TypeDefEntry
/**
......@@ -158,11 +158,11 @@ mergeTypeDefEntries :: TypeDefEntry TypeDefEntry -> TypeDefEntry
*
* @param The type variables of the class
* @param The class context
* @param The documentation (a ClassDoc)
* @param The documentation
* @param The names and types of the class members
* @result A Class record with those data
*/
toClass :: [String] TypeContext (Maybe Documentation) [(Name, FunctionEntry)] -> ClassEntry
toClass :: [String] TypeContext (Maybe ClassDoc) [(Name, FunctionEntry)] -> ClassEntry
functionCount :: CloogleDB -> Int
classCount :: CloogleDB -> Int
......
......@@ -60,17 +60,19 @@ printersperse ia a bs = intercalate (print False a) (map (print ia) bs)
(--) a b = print False a ++ print False b
derive gEq Maybe, TypeRestriction, Location, Type, Priority, FunctionEntry,
TypeDef, TypeDefRhs, RecordField, Constructor, Kind, Documentation,
TypeRhsDoc, ClassMemberDoc, InstanceEntry, DeriveEntry,
CleanLangReportLocation
TypeDef, TypeDefRhs, RecordField, Constructor, Kind, FunctionDoc, ClassDoc,
TypeDoc, ModuleDoc, ClassMemberDoc, ConstructorDoc, InstanceEntry,
DeriveEntry, CleanLangReportLocation
derive JSONEncode TypeRestriction, Location, Type, CloogleDB, Priority,
FunctionEntry, TypeDef, TypeDefRhs, RecordField, Constructor, Kind,
ModuleEntry, Documentation, TypeRhsDoc, ClassMemberDoc, TypeDefEntry,
ClassEntry, InstanceEntry, DeriveEntry, SyntaxEntry
ModuleEntry, FunctionDoc, ClassDoc, TypeDoc, ModuleDoc, ClassMemberDoc,
ConstructorDoc, TypeDefEntry, ClassEntry, InstanceEntry, DeriveEntry,
SyntaxEntry
derive JSONDecode TypeRestriction, Location, Type, CloogleDB, Priority,
FunctionEntry, TypeDef, TypeDefRhs, RecordField, Constructor, Kind,
ModuleEntry, Documentation, TypeRhsDoc, ClassMemberDoc, TypeDefEntry,
ClassEntry, InstanceEntry, DeriveEntry, SyntaxEntry
ModuleEntry, FunctionDoc, ClassDoc, TypeDoc, ModuleDoc, ClassMemberDoc,
ConstructorDoc, TypeDefEntry, ClassEntry, InstanceEntry, DeriveEntry,
SyntaxEntry
instance zero CloogleDB
where
......@@ -164,13 +166,13 @@ isApp l db = case getModule l db of
Nothing -> False
Just b -> b.me_is_app
toTypeDefEntry :: TypeDef (Maybe Documentation) -> TypeDefEntry
toTypeDefEntry :: TypeDef (Maybe TypeDoc) -> TypeDefEntry
toTypeDefEntry td doc = {tde_typedef=td, tde_doc=doc}
getTypeDef :: TypeDefEntry -> TypeDef
getTypeDef {tde_typedef} = tde_typedef
getTypeDefDoc :: TypeDefEntry -> Maybe Documentation
getTypeDefDoc :: TypeDefEntry -> Maybe TypeDoc
getTypeDefDoc {tde_doc} = tde_doc
mergeTypeDefEntries :: TypeDefEntry TypeDefEntry -> TypeDefEntry
......@@ -179,7 +181,7 @@ mergeTypeDefEntries a=:{tde_typedef={td_rhs=TDRAbstract Nothing}} b = case b.tde
rhs -> {a & tde_typedef.td_rhs=TDRAbstract (Just rhs)}
mergeTypeDefEntries a b = b
toClass :: [String] TypeContext (Maybe Documentation) [(Name, FunctionEntry)] -> ClassEntry
toClass :: [String] TypeContext (Maybe ClassDoc) [(Name, FunctionEntry)] -> ClassEntry
toClass vs cc doc mems
= { ce_vars = vs
, ce_context = cc
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -124,7 +124,7 @@ makeModuleResult mbName (Location lib mod fname dcl icl _, info)
, icl_line = icl
, distance = modLevenshtein (fromJust mbName) mod
, builtin = Nothing
, documentation = getDocDescription =<< info.me_documentation
, documentation = docDescription =<< info.me_documentation
, langrep_documentation = Nothing
}
, { module_is_core = info.me_is_core
......@@ -141,7 +141,7 @@ makeClassResult rec=:(Builtin _ langdoc, def) db
, modul = ""
, distance = -100
, builtin = Just True
, documentation = getDocDescription =<< def.ce_documentation
, documentation = docDescription =<< def.ce_documentation
, langrep_documentation = Just langdoc
}
, makeClassResultExtras rec db
......@@ -155,7 +155,7 @@ makeClassResult rec=:(Location lib mod fname line iclline cls, def) db
, modul = mod
, distance = -100
, builtin = Nothing
, documentation = getDocDescription =<< def.ce_documentation
, documentation = docDescription =<< def.ce_documentation
, langrep_documentation = Nothing
}
, makeClassResultExtras rec db
......@@ -191,16 +191,16 @@ makeTypeResult mbName location etd db
, distance
= if (isNothing mbName) -100 (levenshtein` (fromJust mbName) t)
, builtin = builtin
, documentation = getDocDescription =<< etd.tde_doc
, documentation = docDescription =<< etd.tde_doc
, langrep_documentation = langdoc
}
, { type = concat $ print False etd.tde_typedef
, type_instances = sortBy (\(a,_,_) (b,_,_) -> a < b)
[(c, map snd ie.ie_types, map loc ie.ie_locations) \\ (c,ie) <- getTypeInstances etd.tde_typedef.td_name db]
, type_derivations = [(if c "class " "" + g, map loc l) \\ (g,c,l) <- getTypeDerivations etd.tde_typedef.td_name db]
, type_field_doc = getFieldDoc =<< etd.tde_doc
, type_constructor_doc = map ((=<<) getDocDescription) <$> (getConstructorDoc =<< etd.tde_doc)
, type_representation_doc = getRepresentationDoc =<< etd.tde_doc
, type_field_doc = docFields =<< etd.tde_doc
, type_constructor_doc = map ((=<<) docDescription) <$> (docConstructors =<< etd.tde_doc)
, type_representation_doc = join (docRepresentation =<< etd.tde_doc)
}
)
where
......@@ -224,7 +224,7 @@ makeFunctionResult orgsearch orgsearchtype usedsynonyms mbCls (fl, fe) db
, modul = mod
, distance = distance unif (fromMaybe [] required_context)
, builtin = builtin
, documentation = getDocDescription =<< fe.fe_documentation
, documentation = docDescription =<< fe.fe_documentation
, langrep_documentation = langdoc
}
, { kind = fe.fe_kind
......@@ -244,10 +244,10 @@ makeFunctionResult orgsearch orgsearchtype usedsynonyms mbCls (fl, fe) db
const (sortBy (on (<) fst)
[(de.de_type_representation, map loc de.de_locations) \\ de <- derivs]) <$>
fe.fe_generic_vars
, param_doc = getParamDocs <$> fe.fe_documentation
, generic_var_doc = getVarDocs <$> fe.fe_documentation
, result_doc = getResultDocs <$> fe.fe_documentation
, type_doc = concat <$> print False <$> (getTypeDoc =<< fe.fe_documentation)
, param_doc = docParams <$> fe.fe_documentation
, generic_var_doc = docVars <$> fe.fe_documentation
, result_doc = docResults <$> fe.fe_documentation
, type_doc = concat <$> print False <$> (docType =<< fe.fe_documentation)
}
)
where
......
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