gisele 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +73 -44
- data/Gemfile.lock +1 -0
- data/examples/meeting-scheduler/MeetingScheduling.gis +23 -23
- data/examples/rectal-cancer-pathway/RectalCancerPathway.gis +64 -0
- data/gisele.noespec +1 -1
- data/lib/gisele/command.rb +6 -4
- data/lib/gisele/language/ast/case_st.rb +14 -0
- data/lib/gisele/language/ast/else_clause.rb +14 -0
- data/lib/gisele/language/ast/node.rb +3 -1
- data/lib/gisele/language/ast/{unit.rb → unit_def.rb} +2 -2
- data/lib/gisele/language/dot.yml +1 -1
- data/lib/gisele/language/elsif_flattener.rb +35 -0
- data/lib/gisele/language/if_to_case.rb +63 -0
- data/lib/gisele/language/rewriter/helper.rb +41 -0
- data/lib/gisele/language/rewriter/scoping.rb +34 -0
- data/lib/gisele/language/rewriter/work_on_nodes.rb +30 -0
- data/lib/gisele/language/rewriter.rb +60 -0
- data/lib/gisele/language/sugar_removal.rb +2 -64
- data/lib/gisele/language/syntax/case_st.rb +19 -0
- data/lib/gisele/language/syntax/grammar.citrus +61 -28
- data/lib/gisele/language/syntax/node.rb +3 -3
- data/lib/gisele/language/syntax/task_def.rb +5 -4
- data/lib/gisele/language/syntax/{unit.rb → unit_def.rb} +3 -3
- data/lib/gisele/language/syntax/when_clause.rb +16 -0
- data/lib/gisele/language/to_graph.rb +43 -16
- data/lib/gisele/language.rb +25 -1
- data/lib/gisele/version.rb +1 -1
- data/spec/command/main/gisele_ast_ruby.stdout +29 -35
- data/spec/command/main/gisele_graph.stdout +24 -14
- data/spec/command/main/gisele_help.stdout +1 -1
- data/spec/command/main/gisele_no_sugar.cmd +1 -1
- data/spec/command/main/gisele_no_sugar.stdout +119 -25
- data/spec/command/main/gisele_version.stdout +1 -1
- data/spec/fixtures/tasks/complete.gis +24 -2
- data/spec/fixtures/tasks/simple.ast +29 -35
- data/spec/fixtures/tasks/simple.gis +7 -2
- data/spec/spec_helper.rb +10 -0
- data/spec/unit/language/ast/test_node.rb +10 -11
- data/spec/unit/language/rewriter/test_helper.rb +87 -0
- data/spec/unit/language/rewriter/test_scoping.rb +46 -0
- data/spec/unit/language/rewriter/test_work_on_nodes.rb +45 -0
- data/spec/unit/language/syntax/grammar/test_bool_expr.rb +34 -0
- data/spec/unit/language/syntax/grammar/test_boolean_literal.rb +17 -0
- data/spec/unit/language/syntax/grammar/test_case_st.rb +60 -0
- data/spec/unit/language/syntax/grammar/test_event.rb +18 -0
- data/spec/unit/language/syntax/grammar/test_event_name.rb +21 -0
- data/spec/unit/language/syntax/grammar/test_event_set.rb +27 -0
- data/spec/unit/language/syntax/grammar/test_fluent_def.rb +21 -0
- data/spec/unit/language/syntax/grammar/test_if_st.rb +21 -0
- data/spec/unit/language/syntax/grammar/test_par_st.rb +11 -0
- data/spec/unit/language/syntax/grammar/test_process_statement.rb +19 -0
- data/spec/unit/language/syntax/grammar/test_seq_st.rb +11 -0
- data/spec/unit/language/syntax/grammar/test_spaces.rb +19 -0
- data/spec/unit/language/syntax/grammar/test_spacing.rb +18 -0
- data/spec/unit/language/syntax/grammar/test_task_def.rb +35 -0
- data/spec/unit/language/syntax/grammar/test_task_name.rb +19 -0
- data/spec/unit/language/syntax/grammar/test_task_start_or_end.rb +17 -0
- data/spec/unit/language/syntax/grammar/test_trackvar_def.rb +21 -0
- data/spec/unit/language/syntax/grammar/test_unit_def.rb +29 -0
- data/spec/unit/language/syntax/grammar/test_variable_name.rb +30 -0
- data/spec/unit/language/syntax/grammar/test_when_clause.rb +21 -0
- data/spec/unit/language/syntax/grammar/test_while_st.rb +11 -0
- data/spec/unit/language/syntax/to_ast/test_bool_expr.rb +28 -0
- data/spec/unit/language/syntax/to_ast/test_case_st.rb +47 -0
- data/spec/unit/language/syntax/to_ast/test_else_clause.rb +13 -0
- data/spec/unit/language/syntax/to_ast/test_elsif_clause.rb +15 -0
- data/spec/unit/language/syntax/to_ast/test_event_set.rb +24 -0
- data/spec/unit/language/syntax/to_ast/test_fluent_def.rb +26 -0
- data/spec/unit/language/syntax/to_ast/test_if_st.rb +39 -0
- data/spec/unit/language/syntax/to_ast/test_par_st.rb +12 -0
- data/spec/unit/language/syntax/to_ast/test_seq_st.rb +12 -0
- data/spec/unit/language/syntax/to_ast/test_task_call_st.rb +10 -0
- data/spec/unit/language/syntax/to_ast/test_task_def.rb +44 -0
- data/spec/unit/language/syntax/to_ast/test_trackvar_def.rb +26 -0
- data/spec/unit/language/syntax/to_ast/test_unit_def.rb +28 -0
- data/spec/unit/language/syntax/to_ast/test_var_ref.rb +12 -0
- data/spec/unit/language/syntax/to_ast/test_when_clause.rb +15 -0
- data/spec/unit/language/syntax/to_ast/test_while_st.rb +24 -0
- data/spec/unit/language/test_ast.rb +4 -4
- data/spec/unit/language/test_elsif_flattener.rb +90 -0
- data/spec/unit/language/test_if_to_case.rb +107 -0
- data/spec/unit/language/{test_transformer.rb → test_rewriter.rb} +24 -11
- data/spec/unit/language/test_syntax.rb +1 -1
- data/spec/unit/language/test_to_graph.rb +9 -2
- metadata +120 -34
- data/lib/gisele/language/syntax/task_refinement.rb +0 -15
- data/lib/gisele/language/syntax/task_signature.rb +0 -15
- data/lib/gisele/language/transformer.rb +0 -38
- data/spec/unit/language/sugar_removal/test_if_to_guarded_commands.rb +0 -110
- data/spec/unit/language/syntax/test_grammar.rb +0 -317
- data/spec/unit/language/syntax/test_to_ast.rb +0 -257
@@ -1,317 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
module Gisele::Language::Syntax
|
3
|
-
describe Grammar do
|
4
|
-
|
5
|
-
let(:grammar){ Gisele::Language::Syntax::Grammar }
|
6
|
-
|
7
|
-
def parse(text, rule, consume = true)
|
8
|
-
grammar.parse(text, :root => rule, :consume => consume)
|
9
|
-
end
|
10
|
-
|
11
|
-
### Spacing
|
12
|
-
|
13
|
-
describe 'the spaces rule' do
|
14
|
-
|
15
|
-
it 'parses all kind of spaces' do
|
16
|
-
parse(' ', :spaces).should eq(' ')
|
17
|
-
parse("\t", :spaces).should eq("\t")
|
18
|
-
parse("\n", :spaces).should eq("\n")
|
19
|
-
parse(" \t\n", :spaces).should eq(" \t\n")
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'enforces mandatory spacing' do
|
23
|
-
lambda{ parse('', :spaces) }.should raise_error(Citrus::ParseError)
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
describe 'the spacing rule' do
|
29
|
-
|
30
|
-
it 'parses all kind of spaces' do
|
31
|
-
parse(' ', :spacing).should eq(' ')
|
32
|
-
parse("\t", :spacing).should eq("\t")
|
33
|
-
parse("\n", :spacing).should eq("\n")
|
34
|
-
parse(" \t\n", :spacing).should eq(" \t\n")
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'does not enforces mandatory spacing' do
|
38
|
-
parse('', :spacing).should eq('')
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
### Literals
|
44
|
-
|
45
|
-
describe 'the boolean_literal rule' do
|
46
|
-
|
47
|
-
it 'parses booleans' do
|
48
|
-
parse('true', :boolean_literal).should eq('true')
|
49
|
-
parse('false', :boolean_literal).should eq('false')
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'does not parses integers' do
|
53
|
-
lambda{ parse('0', :boolean_literal) }.should raise_error(Citrus::ParseError)
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
### Names
|
59
|
-
|
60
|
-
describe 'the task_name rule' do
|
61
|
-
|
62
|
-
it 'parses correct task names' do
|
63
|
-
parse('A', :task_name).should eq('A')
|
64
|
-
parse('Diagnosis', :task_name).should eq('Diagnosis')
|
65
|
-
parse('TaskName', :task_name).should eq('TaskName')
|
66
|
-
parse('Task_Name', :task_name).should eq('Task_Name')
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'raises on invalid task names' do
|
70
|
-
lambda{ parse('not_a_task_name', :task_name) }.should raise_error(Citrus::ParseError)
|
71
|
-
end
|
72
|
-
|
73
|
-
end # task_name
|
74
|
-
|
75
|
-
describe 'the variable_name rule' do
|
76
|
-
|
77
|
-
it 'parses correct variable names' do
|
78
|
-
parse('a', :variable_name).should eq('a')
|
79
|
-
parse('diagnosis', :variable_name).should eq('diagnosis')
|
80
|
-
parse('varName', :variable_name).should eq('varName')
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'raises on invalid variable names' do
|
84
|
-
lambda{ parse('NotAVarName', :variable_name) }.should raise_error(Citrus::ParseError)
|
85
|
-
end
|
86
|
-
|
87
|
-
end # variable_name
|
88
|
-
|
89
|
-
describe 'the event_name rule' do
|
90
|
-
|
91
|
-
it 'parses correct event names' do
|
92
|
-
parse('a', :event_name).should eq('a')
|
93
|
-
parse('event', :event_name).should eq('event')
|
94
|
-
parse('event_name', :event_name).should eq('event_name')
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'raises on invalid variable names' do
|
98
|
-
lambda{ parse('NotAnEventName', :event_name) }.should raise_error(Citrus::ParseError)
|
99
|
-
lambda{ parse('notAnEventName', :event_name) }.should raise_error(Citrus::ParseError)
|
100
|
-
end
|
101
|
-
|
102
|
-
end # event_name
|
103
|
-
|
104
|
-
### Events
|
105
|
-
|
106
|
-
describe 'the task_start_or_end rule' do
|
107
|
-
|
108
|
-
it 'parses correct event names' do
|
109
|
-
parse('Task:start', :task_start_or_end).should eq('Task:start')
|
110
|
-
parse('Task:end', :task_start_or_end).should eq('Task:end')
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'raises on simple task names' do
|
114
|
-
lambda{ parse('Task', :task_start_or_end) }.should raise_error(Citrus::ParseError)
|
115
|
-
end
|
116
|
-
|
117
|
-
end # task_start_or_end
|
118
|
-
|
119
|
-
describe 'the event rule' do
|
120
|
-
|
121
|
-
it 'parses correct events' do
|
122
|
-
parse('Task:start', :event).should eq('Task:start')
|
123
|
-
parse('Task:end', :event).should eq('Task:end')
|
124
|
-
parse('an_event', :event).should eq('an_event')
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'raises on invalid event names' do
|
128
|
-
lambda{ parse('Task', :event) }.should raise_error(Citrus::ParseError)
|
129
|
-
end
|
130
|
-
|
131
|
-
end # event
|
132
|
-
|
133
|
-
describe 'the event_set rule' do
|
134
|
-
|
135
|
-
it 'parses empty sets' do
|
136
|
-
parse('{}', :event_set).should eq('{}')
|
137
|
-
parse('{ }', :event_set).should eq('{ }')
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'parses event singletons' do
|
141
|
-
parse('{Task:start}', :event_set).should eq('{Task:start}')
|
142
|
-
parse('{ Task:start }', :event_set).should eq('{ Task:start }')
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'parses event sets' do
|
146
|
-
parse('{Task:start, Task:end}', :event_set).should eq('{Task:start, Task:end}')
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'recognizes invalid events in the set' do
|
150
|
-
lambda{ parse('{Task:start, NotAnEvent}', :event_set) }.should raise_error(Citrus::ParseError)
|
151
|
-
end
|
152
|
-
|
153
|
-
end # event_set
|
154
|
-
|
155
|
-
### Variables
|
156
|
-
|
157
|
-
describe 'the fluent_def rule' do
|
158
|
-
|
159
|
-
it 'parses valid fluent definitions' do
|
160
|
-
defn = 'fluent diagKnown {Diagnosis:start}, {Treatment:end} initially false'
|
161
|
-
parse(defn, :fluent_def).should eq(defn)
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'supports a missing initial value' do
|
165
|
-
defn = 'fluent diagKnown {Diagnosis:start}, {Treatment:end}'
|
166
|
-
parse(defn, :fluent_def).should eq(defn)
|
167
|
-
end
|
168
|
-
|
169
|
-
it 'supports empty sets for events' do
|
170
|
-
defn = 'fluent diagKnown {}, {} initially true'
|
171
|
-
parse(defn, :fluent_def).should eq(defn)
|
172
|
-
end
|
173
|
-
|
174
|
-
end # fluent_def
|
175
|
-
|
176
|
-
describe 'the trackvar_def rule' do
|
177
|
-
|
178
|
-
it 'parses valid tracking variable definitions' do
|
179
|
-
defn = 'trackvar plateletLow {BloodTest:end}'
|
180
|
-
parse(defn, :trackvar_def).should eq(defn)
|
181
|
-
end
|
182
|
-
|
183
|
-
it 'supports an optional initial value' do
|
184
|
-
defn = 'trackvar plateletLow {BloodTest:end} initially false'
|
185
|
-
parse(defn, :trackvar_def).should eq(defn)
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'supports optional obsolete events' do
|
189
|
-
defn = 'trackvar plateletLow {BloodTest:end}, {Chemotherapy:end}'
|
190
|
-
parse(defn, :trackvar_def).should eq(defn)
|
191
|
-
end
|
192
|
-
|
193
|
-
end # trackvar_def
|
194
|
-
|
195
|
-
describe 'the bool_expr rule' do
|
196
|
-
|
197
|
-
it 'parses single variable references' do
|
198
|
-
parse('diagKnown', :bool_expr).should eq('diagKnown')
|
199
|
-
end
|
200
|
-
|
201
|
-
it 'parses boolean literals' do
|
202
|
-
parse('true', :bool_expr).should eq('true')
|
203
|
-
parse('false', :bool_expr).should eq('false')
|
204
|
-
end
|
205
|
-
|
206
|
-
it 'parses negated expression' do
|
207
|
-
parse('not diagKnown', :bool_expr).should eq('not diagKnown')
|
208
|
-
parse('not true', :bool_expr).should eq('not true')
|
209
|
-
parse('not false', :bool_expr).should eq('not false')
|
210
|
-
end
|
211
|
-
|
212
|
-
it 'parses or expressions' do
|
213
|
-
parse('diagKnown or platLow', :bool_expr).should eq('diagKnown or platLow')
|
214
|
-
end
|
215
|
-
|
216
|
-
it 'parses and expressions' do
|
217
|
-
parse('diagKnown and platLow', :bool_expr).should eq('diagKnown and platLow')
|
218
|
-
end
|
219
|
-
|
220
|
-
it 'parses complex expressions' do
|
221
|
-
expr = 'diagKnown and (platLow or not(metastased and mplus))'
|
222
|
-
parse(expr, :bool_expr).should eq(expr)
|
223
|
-
end
|
224
|
-
|
225
|
-
end # bool_expr
|
226
|
-
|
227
|
-
### Process statements
|
228
|
-
|
229
|
-
describe 'the par_st rule' do
|
230
|
-
|
231
|
-
it 'parses a single parallel statement' do
|
232
|
-
expr = 'par Task1 Task2 end'
|
233
|
-
parse(expr, :par_st).should eq(expr)
|
234
|
-
end
|
235
|
-
|
236
|
-
end # par_st
|
237
|
-
|
238
|
-
describe 'the seq_st rule' do
|
239
|
-
|
240
|
-
it 'parses a single sequence statement' do
|
241
|
-
expr = 'seq Task1 Task2 end'
|
242
|
-
parse(expr, :seq_st).should eq(expr)
|
243
|
-
end
|
244
|
-
|
245
|
-
end # seq_st
|
246
|
-
|
247
|
-
describe 'the while_statement rule' do
|
248
|
-
|
249
|
-
it 'parses a single while statement' do
|
250
|
-
expr = 'while badCond Task end'
|
251
|
-
parse(expr, :while_st).should eq(expr)
|
252
|
-
end
|
253
|
-
|
254
|
-
end # while_statement
|
255
|
-
|
256
|
-
describe 'the if_st rule' do
|
257
|
-
|
258
|
-
it 'parses a single if statement' do
|
259
|
-
expr = 'if goodCond Task end'
|
260
|
-
parse(expr, :if_st).should eq(expr)
|
261
|
-
end
|
262
|
-
|
263
|
-
it 'supports an optional else' do
|
264
|
-
expr = 'if goodCond GoodTask else BadTask end'
|
265
|
-
parse(expr, :if_st).should eq(expr)
|
266
|
-
end
|
267
|
-
|
268
|
-
it 'supports an optional elsif clauses' do
|
269
|
-
expr = 'if goodCond GoodTask elsif otherCond OtherTask elsif yetAnother BadTask end'
|
270
|
-
parse(expr, :if_st).should eq(expr)
|
271
|
-
end
|
272
|
-
|
273
|
-
end # if_st
|
274
|
-
|
275
|
-
describe 'the process_statement rule' do
|
276
|
-
|
277
|
-
it 'parses a simple process statement' do
|
278
|
-
expr = <<-PROCESS.strip
|
279
|
-
DoSomething
|
280
|
-
if goodCond
|
281
|
-
DoForGood
|
282
|
-
else
|
283
|
-
DoForBad
|
284
|
-
end
|
285
|
-
CleanDesk
|
286
|
-
PROCESS
|
287
|
-
parse(expr, :process_statement).should eq(expr)
|
288
|
-
end
|
289
|
-
|
290
|
-
end # process_statement
|
291
|
-
|
292
|
-
describe 'the task_def rule' do
|
293
|
-
|
294
|
-
it 'parses a simple task definition' do
|
295
|
-
taskdef = <<-TASKDEF.strip
|
296
|
-
task Process
|
297
|
-
refinement Diagnosis end
|
298
|
-
end
|
299
|
-
TASKDEF
|
300
|
-
parse(taskdef, :task_def).should eq(taskdef)
|
301
|
-
end
|
302
|
-
|
303
|
-
it 'supports optional variable definitions in the signature' do
|
304
|
-
taskdef = <<-TASKDEF.strip
|
305
|
-
task Process
|
306
|
-
fluent diagKnown {Diagnosis:start}, {} initially false
|
307
|
-
trackvar mplus {Diagnosis:end}
|
308
|
-
refinement Diagnosis end
|
309
|
-
end
|
310
|
-
TASKDEF
|
311
|
-
parse(taskdef, :task_def).should eq(taskdef)
|
312
|
-
end
|
313
|
-
|
314
|
-
end
|
315
|
-
|
316
|
-
end
|
317
|
-
end
|
@@ -1,257 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
module Gisele::Language::Syntax
|
3
|
-
describe Grammar, "to_ast" do
|
4
|
-
|
5
|
-
def ast(text, rule, consume = true)
|
6
|
-
@parsed = Grammar.parse(text, :root => rule, :consume => consume).to_ast
|
7
|
-
end
|
8
|
-
|
9
|
-
after{ @parsed.should be_a(Gisele::Language::AST::Node) }
|
10
|
-
|
11
|
-
describe "the bool_expr rule" do
|
12
|
-
|
13
|
-
it 'returns expected ast on simple expressions' do
|
14
|
-
expected = \
|
15
|
-
[:bool_expr, [:bool_and, [:var_ref, "diagKnown"], [:var_ref, "platLow"]]]
|
16
|
-
ast("diagKnown and platLow", :bool_expr).should eq(expected)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'respects priorities' do
|
20
|
-
expected = [:bool_expr,
|
21
|
-
[:bool_or, [:bool_and, [:var_ref, "diagKnown"], [:var_ref, "platLow"]], [:var_ref, "platHigh"]]]
|
22
|
-
ast("diagKnown and platLow or platHigh", :bool_expr).should eq(expected)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'supports double negations' do
|
26
|
-
expected = [:bool_expr, [:bool_not, [:bool_not, [:var_ref, "diagKnown"]]]]
|
27
|
-
ast("not not(diagKnown)", :bool_expr).should eq(expected)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'makes boolean literals explicit' do
|
31
|
-
ast("true", :bool_expr).should eq([:bool_expr, [:bool_lit, true]])
|
32
|
-
ast("false", :bool_expr).should eq([:bool_expr, [:bool_lit, false]])
|
33
|
-
end
|
34
|
-
|
35
|
-
end # bool_expr
|
36
|
-
|
37
|
-
describe 'the event_set rule' do
|
38
|
-
|
39
|
-
it 'parses empty lists as expected' do
|
40
|
-
expr = '{ }'
|
41
|
-
expected = [:event_set]
|
42
|
-
ast(expr, :event_set).should eq(expected)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'parses singleton lists as expected' do
|
46
|
-
expr = '{Diagnosis:start}'
|
47
|
-
expected = [:event_set, "Diagnosis:start"]
|
48
|
-
ast(expr, :event_set).should eq(expected)
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'parses non empty lists as expected' do
|
52
|
-
expr = '{Diagnosis:start, an_event, another_one}'
|
53
|
-
expected = [:event_set, "Diagnosis:start", "an_event", "another_one"]
|
54
|
-
ast(expr, :event_set).should eq(expected)
|
55
|
-
end
|
56
|
-
|
57
|
-
end # event_set
|
58
|
-
|
59
|
-
describe "the fluent_def rule" do
|
60
|
-
|
61
|
-
it 'parses fluent definitions as expected' do
|
62
|
-
defn = "fluent diagKnown {Diagnosis:start, diagnosis}, {Treatment:end} initially false"
|
63
|
-
expected = [:fluent,
|
64
|
-
"diagKnown",
|
65
|
-
[:event_set, "Diagnosis:start", "diagnosis"],
|
66
|
-
[:event_set, "Treatment:end"],
|
67
|
-
false]
|
68
|
-
ast(defn, :fluent_def).should eq(expected)
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'does not require the initial value' do
|
72
|
-
defn = "fluent diagKnown {Diagnosis:start, diagnosis}, {Treatment:end}"
|
73
|
-
expected = [:fluent,
|
74
|
-
"diagKnown",
|
75
|
-
[:event_set, "Diagnosis:start", "diagnosis"],
|
76
|
-
[:event_set, "Treatment:end"],
|
77
|
-
nil]
|
78
|
-
ast(defn, :fluent_def).should eq(expected)
|
79
|
-
end
|
80
|
-
|
81
|
-
end # fluent_def rule
|
82
|
-
|
83
|
-
describe "the trackvar_def rule" do
|
84
|
-
|
85
|
-
it 'parses tracking variable definitions as expected' do
|
86
|
-
defn = "trackvar mplus {Diagnosis:start}"
|
87
|
-
expected = [:trackvar,
|
88
|
-
"mplus",
|
89
|
-
[:event_set, "Diagnosis:start"],
|
90
|
-
[:event_set],
|
91
|
-
nil]
|
92
|
-
ast(defn, :trackvar_def).should eq(expected)
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'supports obsolete events and initial value' do
|
96
|
-
defn = "trackvar mplus {Diagnosis:start}, {Treatment:end} initially true"
|
97
|
-
expected = [:trackvar,
|
98
|
-
"mplus",
|
99
|
-
[:event_set, "Diagnosis:start"],
|
100
|
-
[:event_set, "Treatment:end"],
|
101
|
-
true]
|
102
|
-
ast(defn, :trackvar_def).should eq(expected)
|
103
|
-
end
|
104
|
-
|
105
|
-
end # trackvar_def rule
|
106
|
-
|
107
|
-
describe "the task_call_st rule" do
|
108
|
-
|
109
|
-
it 'parses as expected' do
|
110
|
-
ast("Diagnosis", :task_call_st).should eq([:task_call_st, "Diagnosis"])
|
111
|
-
end
|
112
|
-
|
113
|
-
end # task_call_statement
|
114
|
-
|
115
|
-
describe "the par_st rule" do
|
116
|
-
|
117
|
-
it 'parses as expected' do
|
118
|
-
expr = "par Task1 Task2 end"
|
119
|
-
expected = [:par_st, [:task_call_st, "Task1"], [:task_call_st, "Task2"]]
|
120
|
-
ast(expr, :par_st).should eq(expected)
|
121
|
-
end
|
122
|
-
|
123
|
-
end # par_st
|
124
|
-
|
125
|
-
describe "the seq_st rule" do
|
126
|
-
|
127
|
-
it 'parses as expected' do
|
128
|
-
expr = "seq Task1 Task2 end"
|
129
|
-
expected = [:seq_st, [:task_call_st, "Task1"], [:task_call_st, "Task2"]]
|
130
|
-
ast(expr, :seq_st).should eq(expected)
|
131
|
-
end
|
132
|
-
|
133
|
-
end # seq_st
|
134
|
-
|
135
|
-
describe "the while_statement rule" do
|
136
|
-
|
137
|
-
it 'parses as expected' do
|
138
|
-
expr = "while goodCond Task1 end"
|
139
|
-
expected = \
|
140
|
-
[:while_st,
|
141
|
-
[:bool_expr, [:var_ref, "goodCond"]],
|
142
|
-
[:task_call_st, "Task1"]]
|
143
|
-
ast(expr, :while_st).should eq(expected)
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'recognizes implicit sequences' do
|
147
|
-
expr = "while goodCond Task1 Task2 end"
|
148
|
-
expected = \
|
149
|
-
[:while_st,
|
150
|
-
[:bool_expr, [:var_ref, "goodCond"]],
|
151
|
-
[:seq_st, [:task_call_st, "Task1"], [:task_call_st, "Task2"]]]
|
152
|
-
ast(expr, :while_st).should eq(expected)
|
153
|
-
end
|
154
|
-
|
155
|
-
end # while_statement
|
156
|
-
|
157
|
-
describe "the else_clause rule" do
|
158
|
-
|
159
|
-
it 'parses as expected' do
|
160
|
-
expr = "else Task1 "
|
161
|
-
expected = \
|
162
|
-
[:else_clause, [:task_call_st, "Task1"]]
|
163
|
-
ast(expr, :else_clause).should eq(expected)
|
164
|
-
end
|
165
|
-
|
166
|
-
end # else_clause
|
167
|
-
|
168
|
-
describe "the elsif_clause rule" do
|
169
|
-
|
170
|
-
it 'parses as expected' do
|
171
|
-
expr = "elsif goodCond Task1 "
|
172
|
-
expected = \
|
173
|
-
[:elsif_clause,
|
174
|
-
[:bool_expr, [:var_ref, "goodCond"]],
|
175
|
-
[:task_call_st, "Task1"]]
|
176
|
-
ast(expr, :elsif_clause).should eq(expected)
|
177
|
-
end
|
178
|
-
|
179
|
-
end # elsif_clause
|
180
|
-
|
181
|
-
describe "the if_statement rule" do
|
182
|
-
|
183
|
-
it 'parses as expected' do
|
184
|
-
expr = "if goodCond Task1 end"
|
185
|
-
expected = \
|
186
|
-
[:if_st,
|
187
|
-
[:bool_expr, [:var_ref, "goodCond"]],
|
188
|
-
[:task_call_st, "Task1"]]
|
189
|
-
ast(expr, :if_st).should eq(expected)
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'supports a else clause' do
|
193
|
-
expr = "if goodCond Task1 else Task2 end"
|
194
|
-
expected = \
|
195
|
-
[:if_st,
|
196
|
-
[:bool_expr, [:var_ref, "goodCond"]],
|
197
|
-
[:task_call_st, "Task1"],
|
198
|
-
[:else_clause, [:task_call_st, "Task2"]] ]
|
199
|
-
ast(expr, :if_st).should eq(expected)
|
200
|
-
end
|
201
|
-
|
202
|
-
it 'supports elsif clauses' do
|
203
|
-
expr = "if goodCond Task1 elsif otherCond Task2 elsif stillAnother Task3 else Task4 end"
|
204
|
-
expected = \
|
205
|
-
[:if_st,
|
206
|
-
[:bool_expr, [:var_ref, "goodCond"]], [:task_call_st, "Task1"],
|
207
|
-
[:elsif_clause,
|
208
|
-
[:bool_expr, [:var_ref, "otherCond"]], [:task_call_st, "Task2"]],
|
209
|
-
[:elsif_clause,
|
210
|
-
[:bool_expr, [:var_ref, "stillAnother"]], [:task_call_st, "Task3"]],
|
211
|
-
[:else_clause,
|
212
|
-
[:task_call_st, "Task4"]] ]
|
213
|
-
ast(expr, :if_st).should eq(expected)
|
214
|
-
end
|
215
|
-
|
216
|
-
end # if_statement
|
217
|
-
|
218
|
-
describe 'the task_refinement rule' do
|
219
|
-
|
220
|
-
it 'parses as expected' do
|
221
|
-
expr = "refinement Task1 end"
|
222
|
-
expected = [:task_refinement, [:task_call_st, "Task1"]]
|
223
|
-
ast(expr, :task_refinement).should eq(expected)
|
224
|
-
end
|
225
|
-
|
226
|
-
end # task_refinement
|
227
|
-
|
228
|
-
describe 'the task_signature rule' do
|
229
|
-
|
230
|
-
it 'parses as expected' do
|
231
|
-
expr = "fluent diagKnown {}, {}\ntrackvar mplus {}"
|
232
|
-
expected = \
|
233
|
-
[ :task_signature,
|
234
|
-
[:fluent, "diagKnown", [:event_set], [:event_set], nil],
|
235
|
-
[:trackvar, "mplus", [:event_set], [:event_set], nil]]
|
236
|
-
ast(expr, :task_signature).should eq(expected)
|
237
|
-
end
|
238
|
-
|
239
|
-
end # task_signature
|
240
|
-
|
241
|
-
describe 'the task_def rule' do
|
242
|
-
|
243
|
-
it 'parses as expected' do
|
244
|
-
expr = "task Task1 fluent diagKnown {}, {} refinement Task2 end end"
|
245
|
-
expected = \
|
246
|
-
[:task_def, "Task1",
|
247
|
-
[:task_signature,
|
248
|
-
[:fluent, "diagKnown", [:event_set], [:event_set], nil]],
|
249
|
-
[:task_refinement,
|
250
|
-
[:task_call_st, "Task2"]]]
|
251
|
-
ast(expr, :task_def).should eq(expected)
|
252
|
-
end
|
253
|
-
|
254
|
-
end # task_def
|
255
|
-
|
256
|
-
end
|
257
|
-
end
|