Verified Commit 85fb929d authored by Camil Staps's avatar Camil Staps 🚀

Move imports from compiler to separate module to avoid name clashes; accept...

Move imports from compiler to separate module to avoid name clashes; accept special characters in tested function/class names; add class and type name to instance properties for disambiguation (#10)
parent d70d9ead
Pipeline #35359 passed with stage
in 4 minutes and 36 seconds
definition module cocl_helper
from Clean.Doc import
:: FunctionDoc,
:: InstanceDoc,
:: TypeDoc
from Clean.Parse.Comments import
:: CollectedComments
from syntax import
:: ParsedDefinition
get_checkable_definitions :: !CollectedComments ![ParsedDefinition] ->
( ![(String, FunctionDoc)]
, ![(String, InstanceDoc)]
, ![(String, TypeDoc)]
)
implementation module cocl_helper
import StdEnv
from Clean.Doc import
:: FunctionDoc,
:: InstanceDoc,
:: TypeDoc,
:: DocBlock,
:: ParseError,
:: ParseWarning,
parseDoc,
traceParseWarnings, traceParseError,
generic docBlockToDoc
import Clean.Parse.Comments
import Clean.PrettyPrint
import Data.Either
import Data.List
import Data.Maybe
from Text import class Text(concat), instance Text String
from syntax import
:: FunKind,
:: FunSpecials,
:: Ident{id_name},
:: IdentOrQualifiedIdent(..),
:: Optional,
:: ParsedDefinition(PD_Function,PD_Instance,PD_Instances,PD_Type,PD_TypeSpec),
:: ParsedExpr,
:: ParsedInstance{pi_class,pi_types},
:: ParsedInstanceAndMembers{pim_pi},
:: ParsedTypeDef,
:: Position,
:: Priority,
:: Rhs,
:: RhsDefsOfType,
:: SymbolType,
:: Type,
:: TypeDef{td_ident}
get_checkable_definitions :: !CollectedComments ![ParsedDefinition] ->
( ![(String, FunctionDoc)]
, ![(String, InstanceDoc)]
, ![(String, TypeDoc)]
)
get_checkable_definitions documentation defs =
( // Functions:
[(id.id_name,doc) \\
(pd,id) <-
[(pd,id) \\ pd=:(PD_Function pos id _ _ _ _) <- defs] ++
[(pd,id) \\ pd=:(PD_TypeSpec pos id _ _ _) <- defs],
Just docstring <- [getComment pd documentation],
doc <- parseDocWithWarnings docstring]
, // Instances:
[(name,doc) \\
(pd,pim_pi) <-
[(pd,pim_pi) \\ pd=:(PD_Instance {pim_pi}) <- defs] ++
[(pd,pim_pi) \\ pd=:(PD_Instances piams) <- defs, {pim_pi} <- piams],
let name = concat ["instance ",ident_name pim_pi.pi_class," ":intersperse " " (map cppp pim_pi.pi_types)]
, Just docstring <- [getComment pd documentation],
doc <- parseDocWithWarnings docstring]
, // Type definitions:
[(id.id_name,doc) \\
pd=:(PD_Type {td_ident=id}) <- defs,
Just docstring <- [getComment pd documentation],
doc <- parseDocWithWarnings docstring]
)
where
parseDocWithWarnings s = case parseDoc s of
Left e -> traceParseError e []
Right (r,ws) -> traceParseWarnings ws [r]
ident_name ident_or_qualified_ident = case ident_or_qualified_ident of
Ident id -> id.id_name
QualifiedIdent _ name -> name
Subproject commit a07b9204a6c0bc338355df3c9af88dbbf76ea517
Subproject commit b2e9e7f79baaa072e811d3568fa2931aa30ccd9e
......@@ -39,22 +39,10 @@ from Clean.Types.Util import instance toString Type, instance == Type,
assign, assignAll
from syntax import
:: FunKind,
:: FunSpecials,
:: Ident{id_name},
:: Module{mod_defs,mod_ident},
:: Optional,
:: ParsedDefinition(PD_Function,PD_Instance,PD_Instances,PD_Type,PD_TypeSpec),
:: ParsedExpr,
:: ParsedInstance{pi_ident},
:: ParsedInstanceAndMembers{pim_pi},
:: ParsedTypeDef,
:: Position,
:: Priority,
:: Rhs,
:: RhsDefsOfType,
:: SymbolType,
:: TypeDef{td_ident}
:: Module{mod_defs,mod_ident}
import cocl_helper
:: Options =
{ directory :: !FilePath
......@@ -232,6 +220,7 @@ handleModule opts fp w
Ok (dcl,_) -> (dcl, dcl.mod_defs, case comments of
Error _ -> emptyCollectedComments
Ok comments -> collectComments comments dcl)
# (fundefs,instancedefs,typedefs) = get_checkable_definitions documentation dcldefs
# moddoc = case parseDoc <$> getComment mod documentation of
Just (Right (doc,_)) -> Just doc
_ -> Nothing
......@@ -243,25 +232,7 @@ handleModule opts fp w
opts.print_options
opts.test_options
moddoc
// Functions:
[(id.id_name,doc) \\
(pd,id) <-
[(pd,id) \\ pd=:(PD_Function pos id _ _ _ _) <- dcldefs] ++
[(pd,id) \\ pd=:(PD_TypeSpec pos id _ _ _) <- dcldefs],
Just docstring <- [getComment pd documentation],
doc <- parseDocWithWarnings docstring]
// Instances:
[(id.id_name,doc) \\
(pd,id) <-
[(pd,id) \\ pd=:(PD_Instance {pim_pi=pim_pi=:{pi_ident=id}}) <- dcldefs] ++
[(pd,id) \\ pd=:(PD_Instances piams) <- dcldefs, {pim_pi=pim_pi=:{pi_ident=id}} <- piams],
Just docstring <- [getComment pd documentation],
doc <- parseDocWithWarnings docstring]
// Type definitions:
[(id.id_name,doc) \\
pd=:(PD_Type {td_ident=id}) <- dcldefs,
Just docstring <- [getComment pd documentation],
doc <- parseDocWithWarnings docstring]
fundefs instancedefs typedefs
// Write properties
| nprops == 0 = w
# w = output INFO
......@@ -306,10 +277,6 @@ where
interleave _ [] = []
interleave g [x:xs] = [g,x:interleave g xs]
parseDocWithWarnings s = case parseDoc s of
Left e -> traceParseError e []
Right (r,ws) -> traceParseWarnings ws [r]
generatePropertyModule :: !String !String ![String] ![String] !(Maybe ModuleDoc)
![(String, FunctionDoc)]
![(String, InstanceDoc)]
......@@ -442,8 +409,8 @@ where
]
}
where
tname = fname +++ "_" +++ name``
name`` = fixname name`
tname = concat ["p",fixname fname,"_",fixname name,"_",toString i]
name`` = "p" +++ fixname name`
name` = if (i == 1) name (name +++ "_" +++ toString i)
type` = fromJust $ assignAll vis $ Func (map snd ts) (Type "Property" []) (TypeContext [])
......@@ -482,4 +449,15 @@ where
-> "\\" +++ join " " ga.ga_names +++ "->("
fixname :: String -> String
fixname s = {if (isAlphanum c) c '_' \\ c <-: s}
fixname s = fix (size s-1) (createArray (size s*2) '\0')
where
fix :: !Int !*String -> .String
fix i arr
| i<0
= arr
# ci = toInt s.[i]
# arr = {arr & [i*2]=hex (ci >> 4), [i*2+1]=hex (ci bitand 0xf)}
= fix (i-1) arr
hex :: !Int -> Char
hex i = "0123456789abcdef".[i]
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