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
@@ -0,0 +1,20 @@
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
@@ -1,45 +1,31 @@
1
+ require 'yaml'
1
2
  module Gisele
2
- module Language
3
3
 
4
- require 'yaml'
5
- DOT_ATTRIBUTES = YAML.load_file(Path.dir/"language/grammar.dot.yml")
6
- SEXP_GRAMMAR = SexpGrammar.load Path.dir/"language/grammar.sexp.yml"
4
+ # Load the Language through Sexpr
5
+ Language = Sexpr.load Path.dir/"language/grammar.sexp.yml"
6
+
7
+ # Load syntax nodes, abstract syntax nodes, and processors
8
+ require_relative 'language/syntax/node'
9
+ require_relative 'language/ast/node'
10
+ require_relative 'language/processors'
7
11
 
8
- RESERVED_WORDS = [
9
- "if",
10
- "else",
11
- "elsif",
12
- "when",
13
- "while",
14
- "seq",
15
- "par",
16
- "task",
17
- "refinement",
18
- "fluent",
19
- "trackvar",
20
- "initially",
21
- "end",
22
- "not",
23
- "or",
24
- "and",
25
- "true",
26
- "false"
27
- ]
12
+ # Force loading the Citrus parser now
13
+ Language.parser.parser
14
+
15
+ module Language
28
16
 
29
- def rule2mod(rule)
30
- rule.to_s.gsub(/(^|_)([a-z])/){|x| $2.capitalize}.to_sym
17
+ # By default, Sexpr will find for abstract nodes under Language itself. We
18
+ # override that behavior here and let it know that the AST module is the
19
+ # parent of all ast nodes.
20
+ def tagging_reference
21
+ AST
31
22
  end
32
- module_function :rule2mod
33
23
 
34
- def mod2rule(mod)
35
- mod = mod.name.to_s.split('::').last.to_sym if mod.is_a?(Module)
36
- mod.to_s.gsub(/[A-Z]/){|x| "_#{x.downcase}"}[1..-1].to_sym
24
+ # The tagging function (from s-expr kind to AST module) is not complete so far.
25
+ # This allows us to at least include the AST:Node module in all s-expressions.
26
+ def default_tagging_module
27
+ AST::Node
37
28
  end
38
- module_function :mod2rule
39
29
 
40
30
  end # module Language
41
- end # module Gisele
42
- require_relative 'language/syntax'
43
- require_relative 'language/ast'
44
- require_relative 'language/rewriter'
45
- require_relative 'language/processors'
31
+ end # module Gisele
@@ -5,7 +5,7 @@ module Gisele
5
5
  include Node
6
6
 
7
7
  def label
8
- markers[:match] ? markers[:match].to_s : "(#{self[1].label} and #{self[2].label})"
8
+ (citrus_match && citrus_match.to_s) || "(#{self[1].label} and #{self[2].label})"
9
9
  end
10
10
 
11
11
  end # module BoolAnd
@@ -5,7 +5,15 @@ module Gisele
5
5
  include Node
6
6
 
7
7
  def label
8
- markers[:match] ? markers[:match].to_s : last.label
8
+ (citrus_match && citrus_match.to_s) || last.label
9
+ end
10
+
11
+ def negate
12
+ if last.first == :bool_not
13
+ Language.sexpr [:bool_expr, last.last]
14
+ else
15
+ Language.sexpr [ :bool_expr, [:bool_not, last] ]
16
+ end
9
17
  end
10
18
 
11
19
  end # module BoolExpr
@@ -5,7 +5,7 @@ module Gisele
5
5
  include Node
6
6
 
7
7
  def label
8
- markers[:match] ? markers[:match].to_s : "not(#{last.label})"
8
+ (citrus_match && citrus_match.to_s) || "not(#{last.label})"
9
9
  end
10
10
 
11
11
  end # module BoolNot
@@ -5,7 +5,7 @@ module Gisele
5
5
  include Node
6
6
 
7
7
  def label
8
- markers[:match] ? markers[:match].to_s : "(#{self[1].label} or #{self[2].label})"
8
+ (citrus_match && citrus_match.to_s) || "(#{self[1].label} or #{self[2].label})"
9
9
  end
10
10
 
11
11
  end # module BoolOr
@@ -11,4 +11,4 @@ module Gisele
11
11
  end # module CaseSt
12
12
  end # module AST
13
13
  end # module Language
14
- end # module Gisele
14
+ end # module Gisele
@@ -11,4 +11,4 @@ module Gisele
11
11
  end # module ElseClause
12
12
  end # module AST
13
13
  end # module Language
14
- end # module Gisele
14
+ end # module Gisele
@@ -3,63 +3,8 @@ module Gisele
3
3
  module AST
4
4
  module Node
5
5
 
6
- # Returns the node markers
7
- def markers
8
- @markers ||= {}
9
- end
10
-
11
- # Sets node markers
12
- def markers=(markers)
13
- @markers = markers
14
- end
15
-
16
- # Returns the rule name, that is, the first Symbol element
17
- # of the node array.
18
- #
19
- # Example:
20
- # file = ... path to a .gis file ...
21
- # Gisele.ast(file).rule_name
22
- # # => :unit
23
- #
24
- def rule_name
25
- first
26
- end
27
-
28
- # Returns the children of this node.
29
- #
30
- # Children are defined as all but the rule name in the underlying
31
- # array.
32
- #
33
- def children
34
- self[1..-1]
35
- end
36
-
37
- # Returns the associated ast_module
38
- def ast_module
39
- AST::Helpers.send(:ast_module, self)
40
- end
41
-
42
- # Applies copy-and-transform to this node.
43
- #
44
- # Example:
45
- # node = AST.node([:something, "world", [:subnode ...]])
46
- # node.copy do |base,child|
47
- # base << ... make something with child ...
48
- # end
49
- # # => [:something, ...]
50
- #
51
- def copy(&block)
52
- base = AST.node([rule_name], markers.dup)
53
- children.inject(base, &block)
54
- end
55
-
56
- # Duplicates this node.
57
- #
58
- # This method ensures that the node marking through modules
59
- # will correctly be applied to the duplicated array.
60
- #
61
- def dup
62
- AST.node(super, markers.dup)
6
+ def citrus_match
7
+ tracking_markers[:citrus_match]
63
8
  end
64
9
 
65
10
  # Returns a label for this AST node
@@ -67,22 +12,15 @@ module Gisele
67
12
  ""
68
13
  end
69
14
 
70
- # Returns attributes to use for dot printing
71
- def dot_attributes
72
- attrs = Language::DOT_ATTRIBUTES[rule_name.to_s] || {}
73
- attrs.merge(:label => label)
74
- end
75
-
76
15
  # Checks validity over the definition
77
16
  def ===(sexp)
78
- SEXP_GRAMMAR[rule_name] === sexp
17
+ Language[rule_name] === sexp
79
18
  end
80
19
 
81
20
  end # module Node
82
21
  end # module AST
83
22
  end # module Language
84
23
  end # module Gisele
85
- require_relative 'unit_def'
86
24
  require_relative 'task_call_st'
87
25
  require_relative 'while_st'
88
26
  require_relative 'if_st'
@@ -94,4 +32,4 @@ require_relative 'bool_expr'
94
32
  require_relative 'bool_and'
95
33
  require_relative 'bool_or'
96
34
  require_relative 'bool_not'
97
- require_relative 'var_ref'
35
+ require_relative 'var_ref'
@@ -1,4 +1,4 @@
1
- grammar Gisele::Language::Syntax::Grammar
1
+ grammar Gisele::Language::Grammar
2
2
 
3
3
  ### Units
4
4
 
@@ -233,4 +233,4 @@ grammar Gisele::Language::Syntax::Grammar
233
233
  | "false"
234
234
  end
235
235
 
236
- end
236
+ end
@@ -1,80 +1,83 @@
1
- ### units and tasks
2
- unit_def:
3
- - [task_def+]
4
- task_def:
5
- - [task_name, some_def*, statement]
6
- some_def:
7
- - fluent_def
8
- - trackvar_def
9
- - task_def
10
- ### variables
11
- fluent_def:
12
- - [var_name, event_set, event_set, initially]
13
- trackvar_def:
14
- - [var_name, event_set, event_set, initially]
15
- event_set:
16
- - [event*]
17
- event:
18
- - event_name
19
- - task_event_name
20
- var_ref:
21
- - [var_name]
22
- ### statements
23
- statement:
24
- - if_st
25
- - case_st
26
- - while_st
27
- - seq_st
28
- - par_st
29
- - task_call_st
30
- - nop_st
31
- if_st:
32
- - [bool_expr, statement, elsif_clause*, "else_clause?"]
33
- case_st:
34
- - [[var_ref, ~], when_clause+, "else_clause?"]
35
- while_st:
36
- - [bool_expr, statement]
37
- seq_st:
38
- - [statement+]
39
- par_st:
40
- - [statement+]
41
- task_call_st:
42
- - [task_name]
43
- nop_st:
44
- - []
45
- ### clauses
46
- elsif_clause:
47
- - [bool_expr, statement]
48
- else_clause:
49
- - [statement]
50
- when_clause:
51
- - [bool_expr, statement]
52
- ### boolean expressions
53
- bool_expr:
54
- - [bool_expression]
55
- bool_expression:
56
- - bool_or
57
- - bool_and
58
- - bool_not
59
- - var_ref
60
- - bool_lit
61
- bool_or:
62
- - [bool_expression, bool_expression]
63
- bool_and:
64
- - [bool_expression, bool_expression]
65
- bool_not:
66
- - [bool_expression]
67
- bool_lit:
68
- - [ boolean_literal ]
69
- boolean_literal:
70
- - true
71
- - false
72
- ### terminals
73
- task_name: !ruby/regexp /^[A-Z][A-Za-z0-9_]*$/
74
- var_name: !ruby/regexp /^[a-z][A-Za-z0-9_]*$/
75
- event_name: !ruby/regexp /^[a-z][a-z0-9_]*$/
76
- task_event_name: !ruby/regexp /^[A-Z][A-Za-z0-9_]*:(start|end)$/
77
- initially:
78
- - true
79
- - false
80
- - ~
1
+ parser:
2
+ grammar.citrus
3
+ rules:
4
+ ### units and tasks
5
+ unit_def:
6
+ - [task_def+]
7
+ task_def:
8
+ - [task_name, some_def*, statement]
9
+ some_def:
10
+ - fluent_def
11
+ - trackvar_def
12
+ - task_def
13
+ ### variables
14
+ fluent_def:
15
+ - [var_name, event_set, event_set, initially]
16
+ trackvar_def:
17
+ - [var_name, event_set, event_set, initially]
18
+ event_set:
19
+ - [event*]
20
+ event:
21
+ - event_name
22
+ - task_event_name
23
+ var_ref:
24
+ - [var_name]
25
+ ### statements
26
+ statement:
27
+ - if_st
28
+ - case_st
29
+ - while_st
30
+ - seq_st
31
+ - par_st
32
+ - task_call_st
33
+ - nop_st
34
+ if_st:
35
+ - [bool_expr, statement, elsif_clause*, "else_clause?"]
36
+ case_st:
37
+ - [[var_ref, ~], when_clause+, "else_clause?"]
38
+ while_st:
39
+ - [bool_expr, statement]
40
+ seq_st:
41
+ - [statement+]
42
+ par_st:
43
+ - [statement+]
44
+ task_call_st:
45
+ - [task_name]
46
+ nop_st:
47
+ - []
48
+ ### clauses
49
+ elsif_clause:
50
+ - [bool_expr, statement]
51
+ else_clause:
52
+ - [statement]
53
+ when_clause:
54
+ - [bool_expr, statement]
55
+ ### boolean expressions
56
+ bool_expr:
57
+ - [bool_expression]
58
+ bool_expression:
59
+ - bool_or
60
+ - bool_and
61
+ - bool_not
62
+ - var_ref
63
+ - bool_lit
64
+ bool_or:
65
+ - [bool_expression, bool_expression]
66
+ bool_and:
67
+ - [bool_expression, bool_expression]
68
+ bool_not:
69
+ - [bool_expression]
70
+ bool_lit:
71
+ - [ boolean_literal ]
72
+ boolean_literal:
73
+ - true
74
+ - false
75
+ ### terminals
76
+ task_name: !ruby/regexp /^[A-Z][A-Za-z0-9_]*$/
77
+ var_name: !ruby/regexp /^[a-z][A-Za-z0-9_]*$/
78
+ event_name: !ruby/regexp /^[a-z][a-z0-9_]*$/
79
+ task_event_name: !ruby/regexp /^[A-Z][A-Za-z0-9_]*:(start|end)$/
80
+ initially:
81
+ - true
82
+ - false
83
+ - ~
@@ -1,4 +1,4 @@
1
+ require_relative 'processors/scoping_helper'
1
2
  require_relative 'processors/elsif_flattener'
2
3
  require_relative 'processors/if_to_case'
3
- require_relative 'processors/sugar_removal'
4
- require_relative 'processors/to_graph'
4
+ require_relative 'processors/sugar_removal'
@@ -1,16 +1,16 @@
1
1
  module Gisele
2
2
  module Language
3
- class ElsifFlattener < Rewriter
4
- alias :on_missing :copy_and_applyall
3
+ class ElsifFlattener < Sexpr::Rewriter
4
+ grammar Language
5
5
 
6
- def on_if_st(node)
7
- condition, dost, *clauses = node.children
6
+ def on_if_st(sexpr)
7
+ condition, dost, *clauses = sexpr.sexpr_body
8
8
 
9
9
  base = [:if_st, condition, dost]
10
- base = node(base, node.markers.dup)
10
+ base = sexpr(base, sexpr.tracking_markers)
11
11
 
12
12
  clauses.inject base do |cur_if, clause|
13
- rw_clause = call(clause)
13
+ rw_clause = apply(clause)
14
14
  cur_if << rw_clause
15
15
  rw_clause.last
16
16
  end
@@ -18,18 +18,19 @@ module Gisele
18
18
  base
19
19
  end
20
20
 
21
- def on_elsif_clause(node)
21
+ def on_elsif_clause(sexpr)
22
22
  base = \
23
23
  [:else_clause,
24
- [:if_st, node[1], mainflow.call(node[2])] ]
25
- base = node(base, node.markers.dup)
24
+ [:if_st, sexpr[1], apply(sexpr[2])] ]
25
+ base = sexpr(base, sexpr.tracking_markers)
26
26
  end
27
27
 
28
- def on_else_clause(node)
29
- [:else_clause, mainflow.call(node.last)]
28
+ def on_else_clause(sexpr)
29
+ [:else_clause, apply(sexpr.last)]
30
30
  end
31
31
 
32
+ alias :on_missing :copy_and_apply
33
+
32
34
  end # class ElsifFlattener
33
35
  end # module Language
34
- end # module Gisele
35
-
36
+ end # module Gisele