gisele 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/CHANGELOG.md +33 -13
  2. data/Gemfile +3 -2
  3. data/Gemfile.lock +6 -3
  4. data/LICENCE.md +1 -1
  5. data/README.md +5 -2
  6. data/Rakefile +0 -8
  7. data/examples/rectal-cancer-pathway/RectalCancerPathway.gis +1 -1
  8. data/gisele.gemspec +3 -2
  9. data/gisele.noespec +4 -3
  10. data/lib/gisele.rb +11 -7
  11. data/lib/gisele/command.rb +28 -19
  12. data/lib/gisele/compiling.rb +2 -0
  13. data/lib/gisele/compiling/to_glts.rb +125 -0
  14. data/lib/gisele/compiling/to_graph.rb +160 -0
  15. data/lib/gisele/compiling/to_graph.yml +20 -0
  16. data/lib/gisele/language.rb +22 -36
  17. data/lib/gisele/language/ast/bool_and.rb +1 -1
  18. data/lib/gisele/language/ast/bool_expr.rb +9 -1
  19. data/lib/gisele/language/ast/bool_not.rb +1 -1
  20. data/lib/gisele/language/ast/bool_or.rb +1 -1
  21. data/lib/gisele/language/ast/case_st.rb +1 -1
  22. data/lib/gisele/language/ast/else_clause.rb +1 -1
  23. data/lib/gisele/language/ast/node.rb +4 -66
  24. data/lib/gisele/language/grammar.citrus +2 -2
  25. data/lib/gisele/language/grammar.sexp.yml +83 -80
  26. data/lib/gisele/language/processors.rb +2 -2
  27. data/lib/gisele/language/processors/elsif_flattener.rb +14 -13
  28. data/lib/gisele/language/processors/if_to_case.rb +20 -18
  29. data/lib/gisele/language/processors/scoping_helper.rb +32 -0
  30. data/lib/gisele/language/processors/sugar_removal.rb +10 -5
  31. data/lib/gisele/language/syntax/case_st.rb +1 -1
  32. data/lib/gisele/language/syntax/node.rb +6 -2
  33. data/lib/gisele/language/syntax/when_clause.rb +1 -1
  34. data/lib/gisele/loader.rb +2 -1
  35. data/lib/gisele/version.rb +1 -1
  36. data/spec/command/main/gisele_glts.cmd +1 -0
  37. data/spec/command/main/gisele_glts.stdout +85 -0
  38. data/spec/command/main/gisele_help.stdout +3 -2
  39. data/spec/spec_helper.rb +2 -3
  40. data/spec/test_examples.rb +2 -2
  41. data/spec/unit/compiling/test_to_glts.rb +20 -0
  42. data/spec/unit/compiling/test_to_graph.rb +19 -0
  43. data/spec/unit/language/ast/test_bool_expr.rb +50 -0
  44. data/spec/unit/language/grammar_sexp/test_fluent_def.rb +1 -1
  45. data/spec/unit/language/processors/test_elsif_flattener.rb +3 -3
  46. data/spec/unit/language/processors/test_if_to_case.rb +7 -7
  47. data/spec/unit/language/processors/test_scoping_helper.rb +45 -0
  48. data/spec/unit/language/syntax/grammar/test_bool_expr.rb +2 -2
  49. data/spec/unit/language/syntax/grammar/test_boolean_literal.rb +2 -2
  50. data/spec/unit/language/syntax/grammar/test_case_st.rb +2 -2
  51. data/spec/unit/language/syntax/grammar/test_event.rb +2 -2
  52. data/spec/unit/language/syntax/grammar/test_event_name.rb +2 -2
  53. data/spec/unit/language/syntax/grammar/test_event_set.rb +2 -3
  54. data/spec/unit/language/syntax/grammar/test_fluent_def.rb +2 -2
  55. data/spec/unit/language/syntax/grammar/test_if_st.rb +2 -2
  56. data/spec/unit/language/syntax/grammar/test_par_st.rb +2 -2
  57. data/spec/unit/language/syntax/grammar/test_process_statement.rb +2 -2
  58. data/spec/unit/language/syntax/grammar/test_seq_st.rb +2 -2
  59. data/spec/unit/language/syntax/grammar/test_spaces.rb +2 -2
  60. data/spec/unit/language/syntax/grammar/test_spacing.rb +2 -3
  61. data/spec/unit/language/syntax/grammar/test_task_def.rb +2 -2
  62. data/spec/unit/language/syntax/grammar/test_task_name.rb +2 -2
  63. data/spec/unit/language/syntax/grammar/test_task_start_or_end.rb +2 -2
  64. data/spec/unit/language/syntax/grammar/test_trackvar_def.rb +2 -2
  65. data/spec/unit/language/syntax/grammar/test_unit_def.rb +2 -2
  66. data/spec/unit/language/syntax/grammar/test_variable_name.rb +24 -3
  67. data/spec/unit/language/syntax/grammar/test_when_clause.rb +2 -2
  68. data/spec/unit/language/syntax/grammar/test_while_st.rb +2 -2
  69. data/spec/unit/language/syntax/to_ast/test_bool_expr.rb +5 -1
  70. data/spec/unit/language/syntax/to_ast/test_case_st.rb +1 -1
  71. data/spec/unit/language/syntax/to_ast/test_else_clause.rb +1 -1
  72. data/spec/unit/language/syntax/to_ast/test_elsif_clause.rb +1 -1
  73. data/spec/unit/language/syntax/to_ast/test_event_set.rb +1 -1
  74. data/spec/unit/language/syntax/to_ast/test_fluent_def.rb +1 -1
  75. data/spec/unit/language/syntax/to_ast/test_if_st.rb +1 -1
  76. data/spec/unit/language/syntax/to_ast/test_par_st.rb +1 -1
  77. data/spec/unit/language/syntax/to_ast/test_seq_st.rb +1 -1
  78. data/spec/unit/language/syntax/to_ast/test_task_call_st.rb +1 -1
  79. data/spec/unit/language/syntax/to_ast/test_task_def.rb +1 -1
  80. data/spec/unit/language/syntax/to_ast/test_trackvar_def.rb +1 -1
  81. data/spec/unit/language/syntax/to_ast/test_unit_def.rb +1 -1
  82. data/spec/unit/language/syntax/to_ast/test_var_ref.rb +1 -1
  83. data/spec/unit/language/syntax/to_ast/test_when_clause.rb +1 -1
  84. data/spec/unit/language/syntax/to_ast/test_while_st.rb +1 -1
  85. data/spec/unit/language/test_syntax.rb +36 -38
  86. data/spec/unit/test_gisele.rb +1 -1
  87. metadata +189 -190
  88. data/lib/gisele/language/ast.rb +0 -14
  89. data/lib/gisele/language/ast/helpers.rb +0 -43
  90. data/lib/gisele/language/ast/unit_def.rb +0 -10
  91. data/lib/gisele/language/grammar.dot.yml +0 -19
  92. data/lib/gisele/language/processors/to_graph.rb +0 -146
  93. data/lib/gisele/language/rewriter.rb +0 -60
  94. data/lib/gisele/language/rewriter/helper.rb +0 -41
  95. data/lib/gisele/language/rewriter/scoping.rb +0 -34
  96. data/lib/gisele/language/rewriter/work_on_nodes.rb +0 -30
  97. data/lib/gisele/language/syntax.rb +0 -29
  98. data/spec/unit/language/ast/test_node.rb +0 -82
  99. data/spec/unit/language/processors/test_to_graph.rb +0 -17
  100. data/spec/unit/language/rewriter/test_helper.rb +0 -87
  101. data/spec/unit/language/rewriter/test_scoping.rb +0 -46
  102. data/spec/unit/language/rewriter/test_work_on_nodes.rb +0 -45
  103. data/spec/unit/language/test_ast.rb +0 -38
  104. data/spec/unit/language/test_rewriter.rb +0 -81
  105. data/spec/unit/test_language.rb +0 -35
@@ -3,11 +3,11 @@ module Gisele::Language
3
3
  describe IfToCase do
4
4
 
5
5
  def ast(source)
6
- Syntax.ast(source.strip, :root => :if_st)
6
+ Gisele.ast(Gisele.parse(source.strip, :root => :if_st))
7
7
  end
8
8
 
9
9
  def rewrite(ast)
10
- @rewrited = IfToCase.new.call(ast)
10
+ @rewrited = IfToCase.call(ast)
11
11
  end
12
12
 
13
13
  after{
@@ -90,16 +90,16 @@ module Gisele::Language
90
90
  it 'keeps traceability markers on a single if' do
91
91
  if_st = ast("if goodCond Task1 end")
92
92
  rw_st = rewrite(if_st)
93
- rw_st.markers.should eq(if_st.markers)
94
- rw_st.last.markers.should eq(if_st.markers)
93
+ rw_st.tracking_markers.should eq(if_st.tracking_markers)
94
+ rw_st.last.tracking_markers.should eq(if_st.tracking_markers)
95
95
  end
96
96
 
97
97
  it 'keeps traceability markers when a else if present' do
98
98
  if_st = ast("if goodCond Task1 else Task2 end")
99
99
  rw_st = rewrite(if_st)
100
- rw_st.markers.should eq(if_st.markers)
101
- rw_st.last.markers.should eq(if_st.last.markers)
100
+ rw_st.tracking_markers.should eq(if_st.tracking_markers)
101
+ rw_st.last.tracking_markers.should eq(if_st.last.tracking_markers)
102
102
  end
103
103
 
104
104
  end
105
- end
105
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ module Gisele::Language
3
+ describe ScopingHelper do
4
+
5
+ let(:rw_class) do
6
+ Class.new(Sexpr::Rewriter) do
7
+ grammar Gisele::Language
8
+ helper ScopingHelper
9
+
10
+ def on_hello(node)
11
+ scope_stack.dup
12
+ end
13
+
14
+ def on_missing(node)
15
+ call(node.sexpr_body.last)
16
+ end
17
+
18
+ end
19
+ end
20
+ let(:rw){ rw_class.new }
21
+
22
+ it 'installs the methods on the rewriter' do
23
+ rw.respond_to?(:scope_stack).should be_true
24
+ end
25
+
26
+ it 'does nothing special on non _def nodes' do
27
+ node = [:hello, "world"]
28
+ rw.call(node).should eq([])
29
+ end
30
+
31
+ it 'keeps _def nodes as successive scopes' do
32
+ second = [:task_def, [:hello]]
33
+ first = [:task_def, second]
34
+ rw.call(first).should eq([first, second])
35
+ end
36
+
37
+ it 'pops scopes when returning along the stack' do
38
+ second = [:task_def, [:hello]]
39
+ first = [:task_def, second]
40
+ rw.call(first)
41
+ rw.scope_stack.should eq([])
42
+ end
43
+
44
+ end
45
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'bool_expr' do
4
4
 
5
5
  it 'parses single variable references' do
@@ -31,4 +31,4 @@ module Gisele::Language::Syntax
31
31
  end
32
32
 
33
33
  end
34
- end
34
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'boolean_literal' do
4
4
 
5
5
  it 'parses booleans' do
@@ -14,4 +14,4 @@ module Gisele::Language::Syntax
14
14
  end
15
15
 
16
16
  end
17
- end
17
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'case_st' do
4
4
 
5
5
  it 'supports a single when clause' do
@@ -57,4 +57,4 @@ module Gisele::Language::Syntax
57
57
  end
58
58
 
59
59
  end
60
- end
60
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'event' do
4
4
 
5
5
  it 'parses correct events' do
@@ -15,4 +15,4 @@ module Gisele::Language::Syntax
15
15
  end
16
16
 
17
17
  end
18
- end
18
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'event_name' do
4
4
 
5
5
  it 'parses correct event names' do
@@ -18,4 +18,4 @@ module Gisele::Language::Syntax
18
18
  end
19
19
 
20
20
  end
21
- end
21
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'event_set' do
4
4
 
5
5
  it 'parses empty sets' do
@@ -23,5 +23,4 @@ module Gisele::Language::Syntax
23
23
  end
24
24
 
25
25
  end
26
- end
27
-
26
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'fluent_def' do
4
4
 
5
5
  it 'parses valid fluent definitions' do
@@ -18,4 +18,4 @@ module Gisele::Language::Syntax
18
18
  end
19
19
 
20
20
  end
21
- end
21
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'if_st' do
4
4
 
5
5
  it 'parses a single if statement' do
@@ -18,4 +18,4 @@ module Gisele::Language::Syntax
18
18
  end
19
19
 
20
20
  end
21
- end
21
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'par_st' do
4
4
 
5
5
  it 'parses a single parallel statement' do
@@ -8,4 +8,4 @@ module Gisele::Language::Syntax
8
8
  end
9
9
 
10
10
  end
11
- end
11
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'process_statement' do
4
4
 
5
5
  it 'parses a simple process statement' do
@@ -16,4 +16,4 @@ module Gisele::Language::Syntax
16
16
  end
17
17
 
18
18
  end
19
- end
19
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'seq_st' do
4
4
 
5
5
  it 'parses a single sequence statement' do
@@ -8,4 +8,4 @@ module Gisele::Language::Syntax
8
8
  end
9
9
 
10
10
  end
11
- end
11
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'spaces' do
4
4
 
5
5
  it 'parses all kind of spaces' do
@@ -16,4 +16,4 @@ module Gisele::Language::Syntax
16
16
  end
17
17
 
18
18
  end
19
- end
19
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'spacing' do
4
4
 
5
5
  it 'parses all kind of spaces' do
@@ -14,5 +14,4 @@ module Gisele::Language::Syntax
14
14
  end
15
15
 
16
16
  end
17
- end
18
-
17
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'task_def' do
4
4
 
5
5
  it 'parses a simple implicit task definition' do
@@ -32,4 +32,4 @@ module Gisele::Language::Syntax
32
32
  end
33
33
 
34
34
  end
35
- end
35
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar,'task_name' do
4
4
 
5
5
  it 'parses correct task names' do
@@ -16,4 +16,4 @@ module Gisele::Language::Syntax
16
16
  end
17
17
 
18
18
  end
19
- end
19
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'task_start_or_end' do
4
4
 
5
5
  it 'parses correct event names' do
@@ -14,4 +14,4 @@ module Gisele::Language::Syntax
14
14
  end
15
15
 
16
16
  end
17
- end
17
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'trackvar_def' do
4
4
 
5
5
  it 'parses valid tracking variable definitions' do
@@ -18,4 +18,4 @@ module Gisele::Language::Syntax
18
18
  end
19
19
 
20
20
  end
21
- end
21
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'unit' do
4
4
 
5
5
  it 'parses a single task definition' do
@@ -26,4 +26,4 @@ module Gisele::Language::Syntax
26
26
  end
27
27
 
28
28
  end
29
- end
29
+ end
@@ -1,7 +1,28 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'variable_name' do
4
4
 
5
+ RESERVED_WORDS = [
6
+ "if",
7
+ "else",
8
+ "elsif",
9
+ "when",
10
+ "while",
11
+ "seq",
12
+ "par",
13
+ "task",
14
+ "refinement",
15
+ "fluent",
16
+ "trackvar",
17
+ "initially",
18
+ "end",
19
+ "not",
20
+ "or",
21
+ "and",
22
+ "true",
23
+ "false"
24
+ ]
25
+
5
26
  it 'parses correct variable names' do
6
27
  parse('a', :variable_name).should eq('a')
7
28
  parse('diagnosis', :variable_name).should eq('diagnosis')
@@ -9,7 +30,7 @@ module Gisele::Language::Syntax
9
30
  end
10
31
 
11
32
  it 'does not allow reserved words' do
12
- Gisele::Language::RESERVED_WORDS.each do |word|
33
+ RESERVED_WORDS.each do |word|
13
34
  lambda{
14
35
  parse(word.to_s + " ", :variable_name)
15
36
  }.should raise_error(Citrus::ParseError)
@@ -27,4 +48,4 @@ module Gisele::Language::Syntax
27
48
  end
28
49
 
29
50
  end
30
- end
51
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'when_clause' do
4
4
 
5
5
  it 'parses a single when clause statement' do
@@ -18,4 +18,4 @@ module Gisele::Language::Syntax
18
18
  end
19
19
 
20
20
  end
21
- end
21
+ end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- module Gisele::Language::Syntax
2
+ module Gisele::Language
3
3
  describe Grammar, 'while_st' do
4
4
 
5
5
  it 'parses a single while statement' do
@@ -8,4 +8,4 @@ module Gisele::Language::Syntax
8
8
  end
9
9
 
10
10
  end
11
- end
11
+ end
@@ -2,6 +2,10 @@ require 'spec_helper'
2
2
  module Gisele::Language::Syntax
3
3
  describe BoolExpr, "to_ast" do
4
4
 
5
+ it 'is correctly extended by Sexpr' do
6
+ ast("true", :bool_expr).should be_a(Gisele::Language::AST::BoolExpr)
7
+ end
8
+
5
9
  it 'returns expected ast on simple expressions' do
6
10
  expected = \
7
11
  [:bool_expr, [:bool_and, [:var_ref, "diagKnown"], [:var_ref, "platLow"]]]
@@ -25,4 +29,4 @@ module Gisele::Language::Syntax
25
29
  end
26
30
 
27
31
  end
28
- end
32
+ end
@@ -44,4 +44,4 @@ module Gisele::Language::Syntax
44
44
  end
45
45
 
46
46
  end
47
- end
47
+ end
@@ -10,4 +10,4 @@ module Gisele::Language::Syntax
10
10
  end
11
11
 
12
12
  end
13
- end
13
+ end
@@ -12,4 +12,4 @@ module Gisele::Language::Syntax
12
12
  end
13
13
 
14
14
  end
15
- end
15
+ end
@@ -21,4 +21,4 @@ module Gisele::Language::Syntax
21
21
  end
22
22
 
23
23
  end
24
- end
24
+ end
@@ -23,4 +23,4 @@ module Gisele::Language::Syntax
23
23
  end
24
24
 
25
25
  end
26
- end
26
+ end