]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/scl/Simantics/SCL.scl
Improved Simantics/SCL module SCL module/script functionality
[simantics/platform.git] / bundles / org.simantics.modeling / scl / Simantics / SCL.scl
index 7298004aa6cf1241ceb35f467a2a352cc48a4046..d636ca8eff2a1c99574ec15125c5691f7ab0f852 100644 (file)
-include "Simantics/DB"\r
-include "Simantics/Variables"\r
-include "Simantics/Ontologies"\r
-\r
-include "http://www.simantics.org/Modeling-1.2/SCLQuery" as SCLQuery\r
-\r
-importJava "org.simantics.scl.compiler.errors.CompilationError" where\r
-    data CompilationError\r
-\r
-importJava "org.simantics.scl.ui.editor.TextAndErrors" where\r
-    data TextAndErrors\r
-    createTextAndErrors :: String -> [CompilationError] -> TextAndErrors\r
-\r
-createSCLModuleAction :: Resource -> <Proc> ()\r
-createSCLModuleAction res = do\r
-  syncWrite (\() -> createSCLModuleDefault res)\r
-  ()\r
-\r
-createPGraphAction :: Resource -> <Proc> ()\r
-createPGraphAction res = do\r
-  syncWrite (\() -> createPGraphDefault res)\r
-  ()\r
-\r
-createSCLValueIndependent :: Resource -> String -> <WriteGraph> Resource\r
-createSCLValueIndependent valueType expression = do\r
-    value = newResource ()\r
-    claim value L0.InstanceOf valueType\r
-    claimRelatedValue value L0.SCLValue.expression expression\r
-    value\r
-\r
-createSCLValue :: Resource -> Resource -> Resource -> String -> <WriteGraph> Resource\r
-createSCLValue container predicate valueType expression = do\r
-    value = createSCLValueIndependent valueType expression\r
-    claim container predicate value\r
-    value\r
-\r
-setExpression :: Variable -> String -> <WriteGraph> ()\r
-setExpression self expression = do\r
-    res = represents self\r
-    claimRelatedValue res L0.SCLValue.expression expression\r
-\r
-importJava "org.simantics.modeling.ModelingUtils" where\r
-    createSCLModuleDefault :: Resource -> <WriteGraph> ()\r
-    createPGraphDefault :: Resource -> <WriteGraph> ()\r
-    createSCLModule :: Resource -> String -> <WriteGraph> ()\r
-\r
-effect SCL \r
-    "scl" \r
-    "org.simantics.scl.compiler.commands.CommandSession"\r
-\r
-importJava "org.simantics.modeling.scl.SCLRealm" where\r
-    data SCLRealm\r
-    syncExec :: SCLRealm -> (<SCL, Proc> a) -> <Proc> a\r
-    @JavaName refreshVariablesSync\r
-    refreshVariables :: SCLRealm -> <Proc> ()\r
-    \r
-readSCLRealm :: Resource -> <ReadGraph,Proc> SCLRealm\r
-readSCLRealm r = let\r
-    id = relatedValue r L0.HasName\r
-  in match sclRealmById id with\r
-    Just realm -> realm\r
-    Nothing -> getOrCreateSCLRealm id\r
-\r
-importJava "org.simantics.modeling.scl.SCLSessionManager" where\r
-    getOrCreateSCLRealm :: String -> <Proc> SCLRealm\r
-    sclRealmById :: String -> <Proc> Maybe SCLRealm\r
-    \r
-importJava "org.simantics.scl.compiler.top.CommandResponse" where\r
-    data CommandResponse = \r
-        @FieldNames [message, error]\r
-        CommandResponse String Boolean\r
-\r
-isSuccessful :: CommandResponse -> Boolean\r
-isSuccessful (CommandResponse _ error) = not error\r
-\r
-instance Show CommandResponse where\r
-    show (CommandResponse message _) = message\r
-\r
-importJava "org.simantics.scl.compiler.commands.CommandSession" where\r
-    execute :: String -> <SCL, Proc> ()\r
-    \r
-    @JavaName getVariableValue\r
-    variableValue :: String -> <SCL> a\r
+include "Simantics/DB"
+include "Simantics/Variables"
+include "Simantics/Ontologies"
+
+include "http://www.simantics.org/Modeling-1.2/SCLQuery" as SCLQuery
+
+importJava "org.simantics.scl.compiler.errors.CompilationError" where
+    data CompilationError
+
+importJava "org.simantics.scl.ui.editor.TextAndErrors" where
+    data TextAndErrors
+    createTextAndErrors :: String -> [CompilationError] -> TextAndErrors
+
+createSCLModuleAction :: Resource -> <Proc> ()
+createSCLModuleAction res = ignore $ syncWrite (\() -> createSCLModuleDefault res)
+
+createSCLScriptAction :: Resource -> <Proc> ()
+createSCLScriptAction res = ignore $ syncWrite (\() -> createSCLScriptDefault res)
+
+createPGraphAction :: Resource -> <Proc> ()
+createPGraphAction res = ignore $ syncWrite (\() -> createPGraphDefault res)
+
+createSCLValueIndependent :: Resource -> String -> <WriteGraph> Resource
+createSCLValueIndependent valueType expression = do
+    value = newResource ()
+    claim value L0.InstanceOf valueType
+    claimRelatedValue value L0.SCLValue.expression expression
+    value
+
+createSCLValue :: Resource -> Resource -> Resource -> String -> <WriteGraph> Resource
+createSCLValue container predicate valueType expression = do
+    value = createSCLValueIndependent valueType expression
+    claim container predicate value
+    value
+
+setExpression :: Variable -> String -> <WriteGraph> ()
+setExpression self expression = do
+    res = represents self
+    claimRelatedValue res L0.SCLValue.expression expression
+
+importJava "org.simantics.modeling.ModelingUtils" where
+    createSCLModuleDefault :: Resource -> <WriteGraph> ()
+    createSCLScriptDefault :: Resource -> <WriteGraph> ()
+    createPGraphDefault :: Resource -> <WriteGraph> ()
+    "Use [createSCLModuleR](#createSCLModuleR) instead."
+    @deprecated
+    createSCLModule :: Resource -> String -> <WriteGraph> ()
+    "Use [createSCLScriptR](#createSCLScriptR) instead."
+    @deprecated
+    createSCLScript :: Resource -> String -> <WriteGraph> ()
+    "Use [createPGraphR](#createPGraphR) instead."
+    @deprecated
+    createPGraph :: Resource -> String -> <WriteGraph> ()
+    """
+    `createSCLModuleR container name` creates a new empty SCL module under
+    the specified `container` with the specified `name` and returns the created
+    module's Resource.
+    """
+    @JavaName createSCLModule
+    createSCLModuleR :: Resource -> String -> <WriteGraph> Resource
+    """
+    `createSCLScriptR container name` creates a new empty SCL script under
+    the specified `container` with the specified `name` and returns the created
+    script's Resource.
+    """
+    @JavaName createSCLScript
+    createSCLScriptR :: Resource -> String -> <WriteGraph> Resource
+    """
+    `createPGraphR container name` creates a new empty partial graph
+    ontology definition (PGraph) under the specified `container` with
+    the specified `name` and returns the created ontology definition's
+    Resource.
+    """
+    @JavaName createPGraph
+    createPGraphR :: Resource -> String -> <WriteGraph> Resource
+    "`setSCLModuleDefinition module definition` sets the textual `definition` of the specified SCL `module`."
+    setSCLModuleDefinition :: Resource -> String -> <WriteGraph> Resource
+    "`setSCLScriptDefinition module definition` sets the textual `definition` of the specified SCL `module`."
+    setSCLScriptDefinition :: Resource -> String -> <WriteGraph> Resource
+    setPGraphDefinition :: Resource -> String -> <WriteGraph> Resource
+
+"""
+`createSCLModuleWithDefinition container name definition` creates a new SCL module under
+the specified `container` with the specified `name` and `definition` and returns
+the created module's Resource.
+"""
+createSCLModuleWithDefinition :: Resource -> String -> String -> <WriteGraph> Resource
+createSCLModuleWithDefinition container name definition = setSCLModuleDefinition (createSCLModuleR container name) definition
+
+"""
+`createSCLScriptWithDefinition container name definition` creates a new SCL script under
+the specified `container` with the specified `name` and `definition` and returns
+the created script's Resource.
+"""
+createSCLScriptWithDefinition :: Resource -> String -> String -> <WriteGraph> Resource
+createSCLScriptWithDefinition container name definition = setSCLScriptDefinition (createSCLScriptR container name) definition
+
+effect SCL 
+    "scl" 
+    "org.simantics.scl.compiler.commands.CommandSession"
+
+importJava "org.simantics.modeling.scl.SCLRealm" where
+    data SCLRealm
+    syncExec :: SCLRealm -> (<SCL, Proc> a) -> <Proc> a
+    @JavaName refreshVariablesSync
+    refreshVariables :: SCLRealm -> <Proc> ()
+    
+readSCLRealm :: Resource -> <ReadGraph,Proc> SCLRealm
+readSCLRealm r = let
+    id = relatedValue r L0.HasName
+  in match sclRealmById id with
+    Just realm -> realm
+    Nothing -> getOrCreateSCLRealm id
+
+importJava "org.simantics.modeling.scl.SCLSessionManager" where
+    getOrCreateSCLRealm :: String -> <Proc> SCLRealm
+    sclRealmById :: String -> <Proc> Maybe SCLRealm
+    
+importJava "org.simantics.scl.compiler.top.CommandResponse" where
+    data CommandResponse = 
+        @FieldNames [message, error]
+        CommandResponse String Boolean
+
+isSuccessful :: CommandResponse -> Boolean
+isSuccessful (CommandResponse _ error) = not error
+
+instance Show CommandResponse where
+    show (CommandResponse message _) = message
+
+importJava "org.simantics.scl.compiler.commands.CommandSession" where
+    execute :: String -> <SCL, Proc> ()
+    
+    @JavaName getVariableValue
+    variableValue :: String -> <SCL> a
     setVariable :: String -> Type -> a -> <SCL> ()
\ No newline at end of file