gisele 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/Gemfile +2 -3
  2. data/Gemfile.lock +15 -7
  3. data/bin/tast2fsp +53 -0
  4. data/examples/dqaad/dqaad.gif +0 -0
  5. data/examples/dqaad/dqaad.gis +31 -0
  6. data/examples/meeting-scheduler/MeetingScheduling.dot +46 -0
  7. data/examples/meeting-scheduler/MeetingScheduling.gif +0 -0
  8. data/examples/meeting-scheduler/MeetingScheduling.gis +1 -1
  9. data/examples/rectal-cancer-pathway/RectalCancerPathway.dot +55 -0
  10. data/examples/rectal-cancer-pathway/RectalCancerPathway.gif +0 -0
  11. data/examples/union/breast.gis +19 -0
  12. data/examples/union/breast/deterministic.dot +33 -0
  13. data/examples/union/breast/deterministic.gif +0 -0
  14. data/examples/union/breast/glts.dot +53 -0
  15. data/examples/union/breast/glts.gif +0 -0
  16. data/examples/union/breast/minimal.dot +31 -0
  17. data/examples/union/breast/minimal.gif +0 -0
  18. data/examples/union/breast/wf.dot +21 -0
  19. data/examples/union/breast/wf.gif +0 -0
  20. data/examples/union/dot.rb +6 -0
  21. data/examples/union/merged.dot +42 -0
  22. data/examples/union/merged.gif +0 -0
  23. data/examples/union/minim.dot +41 -0
  24. data/examples/union/minim.gif +0 -0
  25. data/examples/union/rectal.gis +20 -0
  26. data/examples/union/rectal/deterministic.dot +37 -0
  27. data/examples/union/rectal/deterministic.gif +0 -0
  28. data/examples/union/rectal/glts.dot +59 -0
  29. data/examples/union/rectal/glts.gif +0 -0
  30. data/examples/union/rectal/minimal.dot +35 -0
  31. data/examples/union/rectal/minimal.gif +0 -0
  32. data/examples/union/rectal/wf.dot +23 -0
  33. data/examples/union/rectal/wf.gif +0 -0
  34. data/examples/union/union.gis +48 -0
  35. data/examples/union/union.rb +39 -0
  36. data/examples/while/while-deteministic.gif +0 -0
  37. data/examples/while/while.dot +30 -0
  38. data/examples/while/while.gif +0 -0
  39. data/examples/while/while.gis +10 -0
  40. data/gisele.gemspec +2 -3
  41. data/gisele.noespec +3 -4
  42. data/lib/gisele.rb +0 -1
  43. data/lib/gisele/command.rb +30 -8
  44. data/lib/gisele/errors.rb +4 -0
  45. data/lib/gisele/loader.rb +1 -2
  46. data/lib/gisele/version.rb +2 -2
  47. data/spec/command/main/gisele_glts.stdout +89 -83
  48. data/spec/command/main/gisele_help.stdout +3 -0
  49. data/spec/command/main/gisele_no_sugar.stdout +34 -1
  50. data/spec/command/main/gisele_version.stdout +1 -1
  51. data/spec/fixtures/tasks/complete.gis +5 -1
  52. metadata +88 -43
  53. data/examples/merge/BreastCancer.dot +0 -30
  54. data/examples/merge/BreastCancer.gif +0 -0
  55. data/examples/merge/BreastCancer.gis +0 -17
  56. data/examples/merge/Merge.dot +0 -46
  57. data/examples/merge/Merge.gif +0 -0
  58. data/examples/merge/RectalCancer.dot +0 -22
  59. data/examples/merge/RectalCancer.gif +0 -0
  60. data/examples/merge/RectalCancer.gis +0 -15
  61. data/lib/gisele/compiling.rb +0 -2
  62. data/lib/gisele/compiling/to_glts.rb +0 -125
  63. data/lib/gisele/compiling/to_graph.rb +0 -160
  64. data/lib/gisele/compiling/to_graph.yml +0 -20
  65. data/spec/unit/compiling/test_to_glts.rb +0 -20
  66. data/spec/unit/compiling/test_to_graph.rb +0 -19
@@ -1,30 +0,0 @@
1
- digraph G {
2
- graph [rankdir="LR"];
3
- 10 [color="black" fillcolor="green" shape="circle" style="filled"];
4
- 16 [color="black" fillcolor="white" shape="circle" style="filled"];
5
- 15 [color="black" fillcolor="white" shape="circle" style="filled"];
6
- 19 [color="black" fillcolor="white" shape="circle" style="filled"];
7
- 18 [color="black" fillcolor="white" shape="circle" style="filled"];
8
- 112 [color="black" fillcolor="white" shape="circle" style="filled"];
9
- 115 [color="black" fillcolor="white" shape="circle" style="filled"];
10
- 118 [color="black" fillcolor="white" shape="circle" style="filled"];
11
- 117 [color="black" fillcolor="white" shape="circle" style="filled"];
12
- 123 [color="black" fillcolor="white" shape="circle" style="filled"];
13
- 126 [color="black" fillcolor="white" shape="circle" style="filled"];
14
- 132 [color="black" fillcolor="white" shape="circle" style="filled"];
15
- 129 [color="black" fillcolor="white" shape="circle" style="filled"];
16
- 10 -> 16 [label="Diagnosis:start"];
17
- 16 -> 15 [label="Diagnosis:end"];
18
- 15 -> 19 [label="Psy:start"];
19
- 19 -> 18 [label="Psy:end"];
20
- 18 -> 112 [label="Staff:start"];
21
- 112 -> 115 [label="Staff:end"];
22
- 115 -> 118 [label="[t] / Radio:start"];
23
- 118 -> 117 [label="Radio:end"];
24
- 123 -> 126 [label="Chimio:end"];
25
- 129 -> 117 [label="Consultation:end"];
26
- 126 -> 129 [label="[not(ok)] / Consultation:start"];
27
- 132 -> 117 [label="Radio:end"];
28
- 126 -> 132 [label="[ok] / Radio:start"];
29
- 115 -> 123 [label="[not(t)] / Chimio:start"];
30
- }
@@ -1,17 +0,0 @@
1
- task BreastCancer
2
- seq
3
- Diagnosis
4
- Psy
5
- Staff
6
- if t
7
- Radio
8
- else
9
- Chimio
10
- if not(ok)
11
- Consultation
12
- else
13
- Radio
14
- end
15
- end
16
- end
17
- end
@@ -1,46 +0,0 @@
1
- digraph G {
2
- graph [rankdir="LR"];
3
-
4
- 20 [color="black" fillcolor="orange" shape="circle" style="filled"];
5
- 26 [color="black" fillcolor="orange" shape="circle" style="filled"];
6
- 25 [color="black" fillcolor="orange" shape="circle" style="filled"];
7
-
8
- 19 [color="black" fillcolor="yellow" shape="circle" style="filled"];
9
- 18 [color="black" fillcolor="yellow" shape="circle" style="filled"];
10
- 112 [color="black" fillcolor="yellow" shape="circle" style="filled"];
11
- 115 [color="black" fillcolor="yellow" shape="circle" style="filled"];
12
- 118 [color="black" fillcolor="yellow" shape="circle" style="filled"];
13
- 117 [color="black" fillcolor="yellow" shape="circle" style="filled"];
14
- 123 [color="black" fillcolor="yellow" shape="circle" style="filled"];
15
- 126 [color="black" fillcolor="yellow" shape="circle" style="filled"];
16
- 129 [color="black" fillcolor="yellow" shape="circle" style="filled"];
17
-
18
- 29 [color="black" fillcolor="red" shape="circle" style="filled"];
19
- 212 [color="black" fillcolor="red" shape="circle" style="filled"];
20
- 217 [color="black" fillcolor="red" shape="circle" style="filled"];
21
- 220 [color="black" fillcolor="red" shape="circle" style="filled"];
22
-
23
- 117 [color="black" fillcolor="orange" shape="circle" style="filled"];
24
-
25
- 20 -> 26 [label="Diagnosis:start"];
26
- 26 -> 25 [label="Diagnosis:end"];
27
- 25 -> 19 [label="[wf1] / Psy:start"];
28
- 19 -> 18 [label="Psy:end"];
29
- 18 -> 112 [label="Staff:start"];
30
- 112 -> 115 [label="Staff:end"];
31
- 115 -> 118 [label="[t] / Radio:start"];
32
- 118 -> 117 [label="Radio:end"];
33
- 123 -> 126 [label="Chimio:end"];
34
- 129 -> 117 [label="Consultation:end"];
35
- 126 -> 129 [label="[not(ok)] / Consultation:start"];
36
- 126 -> 118 [label="[ok] / Radio:start"];
37
- 115 -> 123 [label="[not(t)] / Chimio:start"];
38
-
39
- 25 -> 29 [label="[wf2] / Staff:start"];
40
- 29 -> 212 [label="Staff:end"];
41
- 217 -> 220 [label="Chimio:end"];
42
- 220 -> 29 [label="[not(ok)] / Staff:start"];
43
- 212 -> 217 [label="[not(t and m)] / Chimio:start"];
44
- 212 -> 118 [label="[t and m] / Radio:start"]
45
- 220 -> 118 [label="[ok] / Radio:start"]
46
- }
Binary file
@@ -1,22 +0,0 @@
1
- digraph G {
2
- graph [rankdir="LR"];
3
- 20 [color="black" fillcolor="green" shape="circle" style="filled"];
4
- 26 [color="black" fillcolor="white" shape="circle" style="filled"];
5
- 25 [color="black" fillcolor="white" shape="circle" style="filled"];
6
- 29 [color="black" fillcolor="white" shape="circle" style="filled"];
7
- 212 [color="black" fillcolor="white" shape="circle" style="filled"];
8
- 217 [color="black" fillcolor="white" shape="circle" style="filled"];
9
- 220 [color="black" fillcolor="white" shape="circle" style="filled"];
10
- 226 [color="black" fillcolor="white" shape="circle" style="filled"];
11
- 225 [color="black" fillcolor="white" shape="circle" style="filled"];
12
- 20 -> 26 [label="Diagnosis:start"];
13
- 26 -> 25 [label="Diagnosis:end"];
14
- 25 -> 29 [label="Staff:start"];
15
- 29 -> 212 [label="Staff:end"];
16
- 217 -> 220 [label="Chimio:end"];
17
- 220 -> 29 [label="[not(ok)] / Staff:start"];
18
- 212 -> 217 [label="[not(t and m)] / Chimio:start"];
19
- 226 -> 225 [label="Radio:end"];
20
- 212 -> 226 [label="[t and m] / Radio:start"]
21
- 220 -> 226 [label="[ok] / Radio:start"]
22
- }
@@ -1,15 +0,0 @@
1
- task RectalCancer
2
-
3
- seq
4
- Diagnosis
5
- Staff
6
- if not(t and m)
7
- Chimio
8
- while not(ok)
9
- Chimio
10
- end
11
- end
12
- Radio
13
- end
14
-
15
- end
@@ -1,2 +0,0 @@
1
- require_relative 'compiling/to_graph'
2
- require_relative 'compiling/to_glts'
@@ -1,125 +0,0 @@
1
- module Gisele
2
- module Compiling
3
- class ToGlts < Sexpr::Rewriter
4
- grammar Language
5
-
6
- DOT_REWRITER = lambda{|elm,kind|
7
- case kind
8
- when :automaton
9
- {:rankdir => "LR"}
10
- when :state
11
- {:shape => "circle",
12
- :style => "filled",
13
- :color => "black",
14
- :fillcolor => (elm.initial? ? "green" : "white")}
15
- when :edge
16
- label = elm[:guard] ? "[#{elm[:guard].label}]" : elm[:symbol]
17
- {:label => label || ''}
18
- end
19
- }
20
-
21
- # if/elsif/else -> guarded commands
22
- use Language::IfToCase
23
-
24
- def on_unit_def(sexpr)
25
- sexpr.
26
- sexpr_body.
27
- select{|n| n.first == :task_def}.
28
- map{|taskdef| apply(taskdef) }
29
- end
30
-
31
- def on_task_def(sexpr)
32
- @glts = Stamina::Automaton.new
33
-
34
- entry = add_state(sexpr, :initial => true)
35
- exit = add_state(sexpr)
36
- c_entry, c_exit = apply(sexpr.last)
37
- connect(entry, c_entry)
38
- connect(c_exit, exit)
39
-
40
- @glts
41
- end
42
-
43
- def on_seq_st(sexpr)
44
- mine = entry_and_exit(sexpr)
45
- current = mine.first
46
- sexpr.sexpr_body.each do |child|
47
- c_entry, c_exit = apply(child)
48
- connect(current, c_entry)
49
- current = c_exit
50
- end
51
- connect(current, mine.last)
52
- mine
53
- end
54
- alias :on_par_st :on_seq_st
55
-
56
- def on_case_st(sexpr)
57
- cond, *clauses = sexpr.sexpr_body
58
-
59
- entry, exit = entry_and_exit(sexpr)
60
-
61
- diamond = add_state(sexpr)
62
- connect(entry, diamond)
63
-
64
- clauses.each do |clause|
65
- c_entry, c_exit = apply(clause.last)
66
- connect(diamond, c_entry, clause[1])
67
- connect(c_exit, exit)
68
- end
69
-
70
- [entry, exit]
71
- end
72
-
73
- def on_while_st(sexpr)
74
- cond, dost, = sexpr.sexpr_body
75
-
76
- entry, exit = entry_and_exit(sexpr)
77
-
78
- diamond = add_state(sexpr)
79
- connect(entry, diamond)
80
-
81
- c_entry, c_exit = apply(sexpr.last)
82
-
83
- connect(diamond, exit, cond.negate)
84
- connect(diamond, c_entry, cond)
85
- connect(c_exit, diamond)
86
-
87
- [entry, exit]
88
- end
89
-
90
- def on_task_call_st(sexpr)
91
- entry, exit = entry_and_exit(sexpr)
92
- middle = add_state(sexpr)
93
- connect(entry, middle, transition(sexpr, "start"))
94
- connect(middle, exit, transition(sexpr, "end"))
95
- [entry, exit]
96
- end
97
-
98
- private
99
-
100
- def entry_and_exit(sexpr)
101
- @glts.add_n_states(2)
102
- end
103
-
104
- def add_state(sexpr, attrs = nil)
105
- @glts.add_state(attrs || {})
106
- end
107
-
108
- def connect(source, target, attrs = {:symbol => nil})
109
- attrs = transition(attrs) unless Hash===attrs
110
- @glts.connect(source, target, attrs)
111
- end
112
-
113
- def transition(sexpr, kind = nil)
114
- raise UnexpectedNodeError, "Node expected, got #{sexpr}" unless Sexpr===sexpr
115
- case sexpr.first
116
- when :task_call_st then {:symbol => "#{sexpr.label}:#{kind}"}
117
- when :bool_expr then {:symbol => "[guard]", :guard => sexpr}
118
- else
119
- raise UnexpectedNodeError, "Unexpected event kind #{sexpr.inspect}"
120
- end
121
- end
122
-
123
- end # class ToGlts
124
- end # module Compiling
125
- end # module Gisele
@@ -1,160 +0,0 @@
1
- module Gisele
2
- module Compiling
3
- class ToGraph < Sexpr::Rewriter
4
- grammar Language
5
-
6
- # We do not support the elsif syntactic sugar here; rewrite it as 'else if'.
7
- use Language::ElsifFlattener
8
-
9
- # This is a marker for the graph nodes we can remove later.
10
- module Connector; end
11
-
12
- def on_unit_def(sexpr)
13
- sexpr.
14
- sexpr_body.
15
- select{|n| n.first == :task_def}.
16
- map{|taskdef| apply(taskdef) }
17
- end
18
-
19
- def on_task_def(sexpr)
20
- @graph = Yargi::Digraph.new
21
-
22
- entry, exit = add_vertex(sexpr), add_vertex(sexpr)
23
- c_entry, c_exit = apply(sexpr.last)
24
- connect(entry, c_entry)
25
- connect(c_exit, exit)
26
-
27
- @graph.vertices(Connector).each do |vertex|
28
- next unless vertex.out_edges.size == 1
29
- target = vertex.out_edges.first.target
30
- @graph.reconnect(vertex.in_edges, nil, target)
31
- @graph.remove_vertex(vertex)
32
- end
33
-
34
- @graph
35
- end
36
-
37
- def on_seq_st(sexpr)
38
- mine = entry_and_exit(sexpr)
39
- current = mine.first
40
- sexpr.sexpr_body.each do |child|
41
- c_entry, c_exit = apply(child)
42
- connect(current, c_entry)
43
- current = c_exit
44
- end
45
- connect(current, mine.last)
46
- mine
47
- end
48
-
49
- def on_par_st(sexpr)
50
- entry, exit = add_vertex(sexpr), add_vertex(sexpr)
51
- sexpr.sexpr_body.each do |child|
52
- c_entry, c_exit = apply(child)
53
- connect(entry, c_entry)
54
- connect(c_exit, exit)
55
- end
56
- [entry, exit]
57
- end
58
-
59
- def on_if_st(sexpr)
60
- cond, then_clause, else_clause, = sexpr.sexpr_body
61
-
62
- entry, exit = entry_and_exit(sexpr)
63
-
64
- diamond = add_vertex(sexpr)
65
- connect(entry, diamond)
66
-
67
- c_entry, c_exit = apply(then_clause)
68
- connect(diamond, c_entry, true_ast_sexpr)
69
- connect(c_exit, exit)
70
-
71
- if else_clause
72
- c_entry, c_exit = apply(else_clause.last)
73
- connect(diamond, c_entry, false_ast_sexpr)
74
- connect(c_exit, exit)
75
- else
76
- connect(diamond, exit, false_ast_sexpr)
77
- end
78
-
79
- [entry, exit]
80
- end
81
-
82
- def on_case_st(sexpr)
83
- cond, *clauses = sexpr.sexpr_body
84
-
85
- entry, exit = entry_and_exit(sexpr)
86
-
87
- diamond = add_vertex(sexpr)
88
- connect(entry, diamond)
89
-
90
- clauses.each do |clause|
91
- c_entry, c_exit = apply(clause.last)
92
- connect(diamond, c_entry, clause)
93
- connect(c_exit, exit)
94
- end
95
-
96
- [entry, exit]
97
- end
98
-
99
-
100
- def on_while_st(sexpr)
101
- cond, dost, = sexpr.sexpr_body
102
-
103
- entry, exit = entry_and_exit(sexpr)
104
-
105
- diamond = add_vertex(sexpr)
106
- connect(entry, diamond)
107
-
108
- c_entry, c_exit = apply(sexpr.last)
109
-
110
- connect(diamond, exit, false_ast_sexpr)
111
- connect(diamond, c_entry, true_ast_sexpr)
112
- connect(c_exit, diamond)
113
-
114
- [entry, exit]
115
- end
116
-
117
- def on_task_call_st(sexpr)
118
- entry, exit = entry_and_exit(sexpr)
119
- task = add_vertex(sexpr)
120
- connect(entry, task)
121
- connect(task, exit)
122
- [entry, exit]
123
- end
124
-
125
- private
126
-
127
- def add_vertex(sexpr)
128
- @graph.add_vertex(dot_attributes(sexpr))
129
- end
130
-
131
- def entry_and_exit(sexpr, tag = Connector)
132
- @graph.add_n_vertices(2, tag)
133
- end
134
-
135
- def connect(source, target, sexpr = nil)
136
- @graph.connect(source, target, dot_attributes(sexpr))
137
- end
138
-
139
- def false_ast_sexpr
140
- sexpr(parse("false", :root => :bool_expr))
141
- end
142
-
143
- def true_ast_sexpr
144
- sexpr(parse("true", :root => :bool_expr))
145
- end
146
-
147
- DOT_ATTRIBUTES = YAML.load_file(Path.dir/"to_graph.yml")
148
- def dot_attributes(sexpr)
149
- if Sexpr===sexpr
150
- attrs = DOT_ATTRIBUTES["graphviz"][sexpr.first.to_s] || {}
151
- attrs = attrs.merge(:label => sexpr.label) if sexpr.respond_to?(:label)
152
- attrs
153
- else
154
- {} # sometimes, sexpr is simply nil
155
- end
156
- end
157
-
158
- end # class ToGraph
159
- end # module Compiling
160
- end # module Gisele
@@ -1,20 +0,0 @@
1
- graphviz:
2
- task_def:
3
- shape: circle
4
- style: filled
5
- fillcolor: black
6
- fixed: true
7
- width: 0.1
8
- task_call_st:
9
- shape: box
10
- while_st:
11
- shape: diamond
12
- if_st:
13
- shape: diamond
14
- case_st:
15
- shape: diamond
16
- par_st:
17
- shape: box
18
- height: 0.1
19
- style: filled
20
- fillcolor: black