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
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
- module Gisele::Language
3
- describe ToGraph do
4
-
5
- it 'returns an array of Digraphs when called on a unit_def' do
6
- got = ToGraph.new.call(complete_ast)
7
- got.should be_a(Array)
8
- got.all?{|x| x.is_a? Yargi::Digraph}.should be_true
9
- end
10
-
11
- it 'returns a Digraph when called on a task_def' do
12
- got = ToGraph.new.call(complete_ast.last)
13
- got.should be_a(Yargi::Digraph)
14
- end
15
-
16
- end
17
- end
@@ -1,87 +0,0 @@
1
- require 'spec_helper'
2
- module Gisele::Language
3
- class Rewriter
4
- describe Helper do
5
-
6
- class FooHelper < Helper
7
- module Methods end
8
-
9
- def on_hello(rw, node)
10
- raise unless rw.is_a?(FooRewriter)
11
- [:foo_hello, yield(rw, node)]
12
- end
13
-
14
- end
15
-
16
- class FooRewriter < Rewriter
17
- FooHelper.install_on(self)
18
- end
19
-
20
- describe "install_on" do
21
-
22
- it 'installs the methods module on the rewriter' do
23
- modules = FooRewriter.included_modules
24
- modules.include?(FooHelper::Methods).should be_true
25
- end
26
-
27
- it 'adds an instance of the helper to the helpers list' do
28
- helper = FooRewriter.helpers.last
29
- helper.should be_a(FooHelper)
30
- end
31
-
32
- it 'does not polute the Rewriter class' do
33
- Rewriter.helpers.size.should eq(1)
34
- end
35
-
36
- end # install_on
37
-
38
- describe 'call' do
39
-
40
- let(:helper) { FooHelper.new }
41
- let(:rewriter) { FooRewriter.new }
42
- let(:toplevel) {
43
- Proc.new do |rw,node|
44
- rw.should eq(rewriter)
45
- [:toplevel, node]
46
- end
47
- }
48
-
49
- it 'dispatches to the method when it exists' do
50
- expected = \
51
- [:foo_hello,
52
- [:toplevel,
53
- [:hello, "world"] ]]
54
- got = helper.call(rewriter, [:hello, "world"], &toplevel)
55
- got.should eq(expected)
56
- end
57
-
58
- it 'falls back to yielding when no method' do
59
- expected = \
60
- [:toplevel,
61
- [:nosuchone] ]
62
- got = helper.call(rewriter, [:nosuchone], &toplevel)
63
- got.should eq(expected)
64
- end
65
-
66
- it 'calls next_in_chain when set' do
67
- helper.next_in_chain = Class.new do
68
- def call(rw, node)
69
- raise unless rw.is_a?(FooRewriter)
70
- yield rw, [:next, node]
71
- end
72
- end.new
73
-
74
- expected = \
75
- [:foo_hello,
76
- [:toplevel,
77
- [:next,
78
- [:hello, "world"] ]]]
79
- got = helper.call(rewriter, [:hello, "world"], &toplevel)
80
- got.should eq(expected)
81
- end
82
-
83
- end # call
84
-
85
- end
86
- end
87
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
- module Gisele::Language
3
- class Rewriter
4
- describe Scoping do
5
-
6
- let(:rw_class) do
7
- Class.new(Rewriter) do
8
-
9
- def on_hello(node)
10
- scope_stack.dup
11
- end
12
-
13
- def on_missing(node)
14
- call(node.children.last)
15
- end
16
-
17
- Scoping.install_on self
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
46
- end
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
- module Gisele::Language
3
- class Rewriter
4
- describe WorkOnNodes do
5
-
6
- let(:won){ WorkOnNodes.new }
7
-
8
- it 'extends input nodes' do
9
- node = [:hello, "world"]
10
- seen = won.call(:rw, node) do |_,n|
11
- n.should be_a(AST::Node)
12
- n
13
- end
14
- seen.should eq(node)
15
- end
16
-
17
- it 'extends output nodes' do
18
- node = [:hello, "world"]
19
- seen = won.call(:rw, node) do |_,n|
20
- n.should be_a(AST::Node)
21
- [:result]
22
- end
23
- seen.should eq([:result])
24
- seen.should be_a(AST::Node)
25
- end
26
-
27
- it 'does not require the output to be a node' do
28
- node = [:hello, "world"]
29
- seen = won.call(:rw, node) do |_,n|
30
- n.should be_a(AST::Node)
31
- "blah"
32
- end
33
- seen.should eq("blah")
34
- seen.should_not be_a(AST::Node)
35
- end
36
-
37
- it 'fails unless the input looks a node' do
38
- lambda{
39
- won.call(:rw, "blah") do |_,n| end
40
- }.should raise_error(ArgumentError, /blah/)
41
- end
42
-
43
- end
44
- end
45
- end
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
- module Gisele::Language
3
- describe AST do
4
-
5
- describe 'ast' do
6
-
7
- it 'returns a node' do
8
- node = [:unit_def].extend(AST::Node)
9
- AST.node(node).object_id.should eq(node.object_id)
10
- end
11
-
12
- it 'coerces an array' do
13
- AST.node([:unit_def]).should eq([:unit_def])
14
- AST.node([:unit_def]).should be_a(AST::UnitDef)
15
- end
16
-
17
- it 'falls back to Node' do
18
- AST.node([:nosuchnode]).should eq([:nosuchnode])
19
- AST.node([:nosuchnode]).should be_a(AST::Node)
20
- end
21
-
22
- it 'applies coercions recursively' do
23
- source = [:unit_def, [:hello, "world"]]
24
- AST.node(source).should eq(source)
25
- AST.node(source).last.should be_a(AST::Node)
26
- end
27
-
28
- it 'raises unless a ast node array' do
29
- lambda{ AST.node("foo") }.should raise_error(ArgumentError, /foo/)
30
- lambda{ AST.node(nil) }.should raise_error(ArgumentError, /nil/)
31
- lambda{ AST.node([]) }.should raise_error(ArgumentError, /\[\]/)
32
- lambda{ AST.node(["foo"]) }.should raise_error(ArgumentError, /foo/)
33
- end
34
-
35
- end # .ast
36
-
37
- end
38
- end
@@ -1,81 +0,0 @@
1
- require 'spec_helper'
2
- module Gisele::Language
3
- describe Rewriter do
4
-
5
- let(:rewriter_class){
6
- Class.new(Rewriter) do
7
-
8
- def on_hello(node)
9
- [:seen_hello, node]
10
- end
11
-
12
- def on_copy(node)
13
- copy_and_applyall(node)
14
- end
15
-
16
- def on_missing(node)
17
- if node.rule_name == :nosuchone
18
- [:seen_missing, node]
19
- else
20
- super
21
- end
22
- end
23
-
24
- end
25
- }
26
- let(:rewriter){ rewriter_class.new }
27
-
28
- describe 'mainflow' do
29
-
30
- it 'defaults to self' do
31
- rewriter.mainflow.should eq(rewriter)
32
- end
33
-
34
- it 'may be passed through options' do
35
- rw = rewriter_class.new(:mainflow => :hello)
36
- rw.mainflow.should eq(:hello)
37
- end
38
-
39
- end # mainflow
40
-
41
- describe 'call' do
42
-
43
- it 'dispatches to existing methods' do
44
- ast = [:hello, "world"]
45
- rewriter.call(ast).should eq([:seen_hello, [:hello, "world"]])
46
- end
47
-
48
- it 'calls on_missing when not found' do
49
- ast = [:nosuchone, "world"]
50
- rewriter.call(ast).should eq([:seen_missing, [:nosuchone, "world"]])
51
- end
52
-
53
- it 'raises unexpected by default in on_missing' do
54
- ast = [:nonono, "world"]
55
- lambda{ rewriter.call(ast) }.should raise_error(Gisele::UnexpectedNodeError, /nonono/)
56
- end
57
-
58
- it 'performs post node transformation if required' do
59
- ast = [:hello, "world"]
60
- rewriter.call(ast).should be_a(AST::Node)
61
- end
62
-
63
- it 'raises an ArgumentError unless called on a non terminal' do
64
- lambda{
65
- rewriter.call("world").should raise_error(ArgumentError, /world/)
66
- }
67
- end
68
-
69
- end
70
-
71
- describe "copy_and_applyall" do
72
-
73
- it 'provides a friendly way of applying copy/recurse' do
74
- ast = [:copy, [:hello, 'world'], "!"]
75
- rewriter.call(ast).should eq([:copy, [:seen_hello, [:hello, "world"]], "!"])
76
- end
77
-
78
- end
79
-
80
- end
81
- end
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
- module Gisele
3
- describe Language do
4
- include Language
5
-
6
- describe "rule2mod" do
7
-
8
- it 'work on simple rule name' do
9
- rule2mod(:test).should eq(:Test)
10
- end
11
-
12
- it 'works when underscores are present' do
13
- rule2mod(:a_rule_name).should eq(:ARuleName)
14
- end
15
-
16
- end # rule2mod
17
-
18
- describe "mod2rule" do
19
-
20
- it 'work on simple module name' do
21
- mod2rule(:Test).should eq(:test)
22
- end
23
-
24
- it 'work on complex module name' do
25
- mod2rule(:ThisIsATest).should eq(:this_is_a_test)
26
- end
27
-
28
- it 'works with a module' do
29
- mod2rule(::Gisele::Language::Syntax::WhileSt).should eq(:while_st)
30
- end
31
-
32
- end # rule2mod
33
-
34
- end
35
- end