]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/scl/SCL/ModuleRepository.scl
Added a function to read the module source text
[simantics/platform.git] / bundles / org.simantics.scl.compiler / scl / SCL / ModuleRepository.scl
1 module {
2     export = [possibleUnsafeSclValueByName, unsafeSclValueByName, sclModuleNames, moduleByName,
3               documentationOfSCLValue, sclValueRef, possibleModuleSourceText]
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     @JavaName getPossibleSourceText
40     possibleModuleSourceText_ :: ModuleSourceRepository -> String -> <Proc> Maybe String
41
42 importJava "org.simantics.scl.compiler.errors.Failable" where
43     data Failable a
44     
45     didSucceed :: Failable a -> Boolean
46     getResult :: Failable a -> Maybe a 
47
48 unsafeSclValueByName :: String -> <Proc> a
49 unsafeSclValueByName = unsafeSclValueByName_ MODULE_REPOSITORY
50
51 sclValueRef name = sclValueRef_ MODULE_REPOSITORY name
52
53 possibleUnsafeSclValueByName :: String -> <Proc> Maybe a
54 possibleUnsafeSclValueByName name = Just (unsafeSclValueByName name) `catch` \(_ :: Exception) -> Nothing
55
56 sclModuleNames :: <Proc> [String]
57 sclModuleNames = sclModuleNames_ (moduleSourceRepositoryOf MODULE_REPOSITORY)
58
59 moduleByName :: String -> <Proc> Maybe Module
60 moduleByName name = getResult failable
61   where
62     failable = moduleByName_ MODULE_REPOSITORY name
63     
64 possibleModuleSourceText :: String -> <Proc> Maybe String
65 possibleModuleSourceText name = possibleModuleSourceText_ (moduleSourceRepositoryOf MODULE_REPOSITORY) name