Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ProB 2 Jupyter Kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
stups
ProB 2 Jupyter Kernel
Commits
4000c4e9
Commit
4000c4e9
authored
May 7, 2018
by
dgelessus
Browse files
Options
Downloads
Patches
Plain Diff
Add cell command to load a B machine from the notebook
parent
f6c5903d
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/de/prob2/jupyter/ProBKernel.java
+12
-1
12 additions, 1 deletion
src/main/java/de/prob2/jupyter/ProBKernel.java
src/main/java/de/prob2/jupyter/commands/LoadCellCommand.java
+52
-0
52 additions, 0 deletions
src/main/java/de/prob2/jupyter/commands/LoadCellCommand.java
with
64 additions
and
1 deletion
src/main/java/de/prob2/jupyter/ProBKernel.java
+
12
−
1
View file @
4000c4e9
...
...
@@ -10,6 +10,7 @@ import java.util.regex.Matcher;
import
java.util.regex.Pattern
;
import
com.google.inject.Inject
;
import
com.google.inject.Injector
;
import
de.prob.animator.domainobjects.AbstractEvalResult
;
import
de.prob.animator.domainobjects.FormulaExpand
;
...
...
@@ -21,6 +22,7 @@ import de.prob2.jupyter.commands.CommandExecutionException;
import
de.prob2.jupyter.commands.EchoCellCommand
;
import
de.prob2.jupyter.commands.HelpCommand
;
import
de.prob2.jupyter.commands.LineCommand
;
import
de.prob2.jupyter.commands.LoadCellCommand
;
import
de.prob2.jupyter.commands.NoSuchCommandException
;
import
io.github.spencerpark.jupyter.kernel.BaseKernel
;
...
...
@@ -38,7 +40,7 @@ public final class ProBKernel extends BaseKernel {
private
@NotNull
Trace
trace
;
@Inject
private
ProBKernel
(
final
@NotNull
ClassicalBFactory
classicalBFactory
)
{
private
ProBKernel
(
final
@NotNull
Injector
injector
,
final
@NotNull
ClassicalBFactory
classicalBFactory
)
{
super
();
this
.
lineCommands
=
new
HashMap
<>();
...
...
@@ -48,6 +50,7 @@ public final class ProBKernel extends BaseKernel {
this
.
cellCommands
=
new
HashMap
<>();
this
.
cellCommands
.
put
(
"::echo"
,
new
EchoCellCommand
());
this
.
cellCommands
.
put
(
"::load"
,
injector
.
getInstance
(
LoadCellCommand
.
class
));
this
.
trace
=
new
Trace
(
classicalBFactory
.
create
(
"MACHINE repl END"
).
load
());
}
...
...
@@ -60,6 +63,14 @@ public final class ProBKernel extends BaseKernel {
return
Collections
.
unmodifiableMap
(
this
.
lineCommands
);
}
public
@NotNull
Trace
getTrace
()
{
return
this
.
trace
;
}
public
void
setTrace
(
final
@NotNull
Trace
trace
)
{
this
.
trace
=
trace
;
}
@Override
public
@NotNull
String
getBanner
()
{
return
"ProB Interactive Expression and Predicate Evaluator (on Jupyter)\nType \":help\" for more information."
;
...
...
This diff is collapsed.
Click to expand it.
src/main/java/de/prob2/jupyter/commands/LoadCellCommand.java
0 → 100644
+
52
−
0
View file @
4000c4e9
package
de.prob2.jupyter.commands
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
com.google.inject.Inject
;
import
de.prob.scripting.ClassicalBFactory
;
import
de.prob.statespace.Trace
;
import
de.prob2.jupyter.ProBKernel
;
import
io.github.spencerpark.jupyter.messages.DisplayData
;
import
org.jetbrains.annotations.NotNull
;
public
final
class
LoadCellCommand
implements
CellCommand
{
private
final
@NotNull
ClassicalBFactory
classicalBFactory
;
@Inject
private
LoadCellCommand
(
final
@NotNull
ClassicalBFactory
classicalBFactory
)
{
super
();
this
.
classicalBFactory
=
classicalBFactory
;
}
@Override
public
@NotNull
String
getSyntax
()
{
return
"::load\nMACHINE\n...\nEND"
;
}
@Override
public
@NotNull
String
getShortHelp
()
{
return
"Load the machine source code from the body."
;
}
@Override
public
@NotNull
DisplayData
run
(
final
@NotNull
ProBKernel
kernel
,
final
@NotNull
String
name
,
final
@NotNull
List
<
@NotNull
String
>
args
,
final
@NotNull
String
body
)
{
final
Map
<
String
,
String
>
preferences
=
new
HashMap
<>();
for
(
final
String
arg
:
args
)
{
final
String
[]
split
=
arg
.
split
(
"="
,
2
);
if
(
split
.
length
==
1
)
{
throw
new
CommandExecutionException
(
name
,
"Missing value for preference "
+
split
[
0
]);
}
preferences
.
put
(
split
[
0
],
split
[
1
]);
}
kernel
.
setTrace
(
new
Trace
(
this
.
classicalBFactory
.
create
(
body
).
load
(
preferences
)));
return
new
DisplayData
(
"Loaded machine: "
+
kernel
.
getTrace
().
getModel
());
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment