]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/scl/SCL/ModuleRepository.scl
(refs #7811) Some new functions for SCL reflection
[simantics/platform.git] / bundles / org.simantics.scl.compiler / scl / SCL / ModuleRepository.scl
1 module {
2     export = [possibleUnsafeSclValueByName, unsafeSclValueByName, sclModuleNames, moduleByName,
3               documentationOfSCLValue, sclValueRef]
4 }
5
6 include "./CurrentModuleRepository"
7 include "./Module"
8
9 importJava "org.simantics.scl.compiler.elaboration.modules.SCLValue" where
10     data SCLValue
11     
12     @JavaName getDocumentation
13     documentationOfSCLValue_ :: SCLValue -> <Proc> Maybe String
14
15 documentationOfSCLValue value = fromMaybe "" (documentationOfSCLValue_ value)
16
17 importJava "org.simantics.scl.compiler.module.repository.ModuleRepository" where
18     // data ModuleRepository
19     // defined in CurrentModuleRepository
20
21     @JavaName getValue
22     unsafeSclValueByName_ :: ModuleRepository -> String -> <Proc> a
23     
24     @JavaName getValueRef
25     sclValueRef_ :: ModuleRepository -> String -> <Proc> Maybe SCLValue
26     
27     @JavaName getSourceRepository
28     moduleSourceRepositoryOf :: ModuleRepository -> ModuleSourceRepository
29     
30     @JavaName getModule
31     moduleByName_ :: ModuleRepository -> String -> <Proc> Failable Module 
32     
33 importJava "org.simantics.scl.compiler.source.repository.ModuleSourceRepository" where
34     data ModuleSourceRepository
35     
36     @JavaName getModuleNames
37     sclModuleNames_ :: ModuleSourceRepository -> [String]
38
39 importJava "org.simantics.scl.compiler.errors.Failable" where
40     data Failable a
41     
42     didSucceed :: Failable a -> Boolean
43     getResult :: Failable a -> Maybe a 
44
45 unsafeSclValueByName :: String -> <Proc> a
46 unsafeSclValueByName = unsafeSclValueByName_ MODULE_REPOSITORY
47
48 sclValueRef name = sclValueRef_ MODULE_REPOSITORY name
49
50 possibleUnsafeSclValueByName :: String -> <Proc> Maybe a
51 possibleUnsafeSclValueByName name = Just (unsafeSclValueByName name) `catch` \(_ :: Exception) -> Nothing
52
53 sclModuleNames :: <Proc> [String]
54 sclModuleNames = sclModuleNames_ (moduleSourceRepositoryOf MODULE_REPOSITORY)
55
56 moduleByName :: String -> <Proc> Maybe Module
57 moduleByName name = getResult failable
58   where
59     failable = moduleByName_ MODULE_REPOSITORY name