gisele 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +33 -13
- data/Gemfile +3 -2
- data/Gemfile.lock +6 -3
- data/LICENCE.md +1 -1
- data/README.md +5 -2
- data/Rakefile +0 -8
- data/examples/rectal-cancer-pathway/RectalCancerPathway.gis +1 -1
- data/gisele.gemspec +3 -2
- data/gisele.noespec +4 -3
- data/lib/gisele.rb +11 -7
- data/lib/gisele/command.rb +28 -19
- data/lib/gisele/compiling.rb +2 -0
- data/lib/gisele/compiling/to_glts.rb +125 -0
- data/lib/gisele/compiling/to_graph.rb +160 -0
- data/lib/gisele/compiling/to_graph.yml +20 -0
- data/lib/gisele/language.rb +22 -36
- data/lib/gisele/language/ast/bool_and.rb +1 -1
- data/lib/gisele/language/ast/bool_expr.rb +9 -1
- data/lib/gisele/language/ast/bool_not.rb +1 -1
- data/lib/gisele/language/ast/bool_or.rb +1 -1
- data/lib/gisele/language/ast/case_st.rb +1 -1
- data/lib/gisele/language/ast/else_clause.rb +1 -1
- data/lib/gisele/language/ast/node.rb +4 -66
- data/lib/gisele/language/grammar.citrus +2 -2
- data/lib/gisele/language/grammar.sexp.yml +83 -80
- data/lib/gisele/language/processors.rb +2 -2
- data/lib/gisele/language/processors/elsif_flattener.rb +14 -13
- data/lib/gisele/language/processors/if_to_case.rb +20 -18
- data/lib/gisele/language/processors/scoping_helper.rb +32 -0
- data/lib/gisele/language/processors/sugar_removal.rb +10 -5
- data/lib/gisele/language/syntax/case_st.rb +1 -1
- data/lib/gisele/language/syntax/node.rb +6 -2
- data/lib/gisele/language/syntax/when_clause.rb +1 -1
- data/lib/gisele/loader.rb +2 -1
- data/lib/gisele/version.rb +1 -1
- data/spec/command/main/gisele_glts.cmd +1 -0
- data/spec/command/main/gisele_glts.stdout +85 -0
- data/spec/command/main/gisele_help.stdout +3 -2
- data/spec/spec_helper.rb +2 -3
- data/spec/test_examples.rb +2 -2
- data/spec/unit/compiling/test_to_glts.rb +20 -0
- data/spec/unit/compiling/test_to_graph.rb +19 -0
- data/spec/unit/language/ast/test_bool_expr.rb +50 -0
- data/spec/unit/language/grammar_sexp/test_fluent_def.rb +1 -1
- data/spec/unit/language/processors/test_elsif_flattener.rb +3 -3
- data/spec/unit/language/processors/test_if_to_case.rb +7 -7
- data/spec/unit/language/processors/test_scoping_helper.rb +45 -0
- data/spec/unit/language/syntax/grammar/test_bool_expr.rb +2 -2
- data/spec/unit/language/syntax/grammar/test_boolean_literal.rb +2 -2
- data/spec/unit/language/syntax/grammar/test_case_st.rb +2 -2
- data/spec/unit/language/syntax/grammar/test_event.rb +2 -2
- data/spec/unit/language/syntax/grammar/test_event_name.rb +2 -2
- data/spec/unit/language/syntax/grammar/test_event_set.rb +2 -3
- data/spec/unit/language/syntax/grammar/test_fluent_def.rb +2 -2
- data/spec/unit/language/syntax/grammar/test_if_st.rb +2 -2
- data/spec/unit/language/syntax/grammar/test_par_st.rb +2 -2
- data/spec/unit/language/syntax/grammar/test_process_statement.rb +2 -2
- data/spec/unit/language/syntax/grammar/test_seq_st.rb +2 -2
- data/spec/unit/language/syntax/grammar/test_spaces.rb +2 -2
- data/spec/unit/language/syntax/grammar/test_spacing.rb +2 -3
- data/spec/unit/language/syntax/grammar/test_task_def.rb +2 -2
- data/spec/unit/language/syntax/grammar/test_task_name.rb +2 -2
- data/spec/unit/language/syntax/grammar/test_task_start_or_end.rb +2 -2
- data/spec/unit/language/syntax/grammar/test_trackvar_def.rb +2 -2
- data/spec/unit/language/syntax/grammar/test_unit_def.rb +2 -2
- data/spec/unit/language/syntax/grammar/test_variable_name.rb +24 -3
- data/spec/unit/language/syntax/grammar/test_when_clause.rb +2 -2
- data/spec/unit/language/syntax/grammar/test_while_st.rb +2 -2
- data/spec/unit/language/syntax/to_ast/test_bool_expr.rb +5 -1
- data/spec/unit/language/syntax/to_ast/test_case_st.rb +1 -1
- data/spec/unit/language/syntax/to_ast/test_else_clause.rb +1 -1
- data/spec/unit/language/syntax/to_ast/test_elsif_clause.rb +1 -1
- data/spec/unit/language/syntax/to_ast/test_event_set.rb +1 -1
- data/spec/unit/language/syntax/to_ast/test_fluent_def.rb +1 -1
- data/spec/unit/language/syntax/to_ast/test_if_st.rb +1 -1
- data/spec/unit/language/syntax/to_ast/test_par_st.rb +1 -1
- data/spec/unit/language/syntax/to_ast/test_seq_st.rb +1 -1
- data/spec/unit/language/syntax/to_ast/test_task_call_st.rb +1 -1
- data/spec/unit/language/syntax/to_ast/test_task_def.rb +1 -1
- data/spec/unit/language/syntax/to_ast/test_trackvar_def.rb +1 -1
- data/spec/unit/language/syntax/to_ast/test_unit_def.rb +1 -1
- data/spec/unit/language/syntax/to_ast/test_var_ref.rb +1 -1
- data/spec/unit/language/syntax/to_ast/test_when_clause.rb +1 -1
- data/spec/unit/language/syntax/to_ast/test_while_st.rb +1 -1
- data/spec/unit/language/test_syntax.rb +36 -38
- data/spec/unit/test_gisele.rb +1 -1
- metadata +189 -190
- data/lib/gisele/language/ast.rb +0 -14
- data/lib/gisele/language/ast/helpers.rb +0 -43
- data/lib/gisele/language/ast/unit_def.rb +0 -10
- data/lib/gisele/language/grammar.dot.yml +0 -19
- data/lib/gisele/language/processors/to_graph.rb +0 -146
- data/lib/gisele/language/rewriter.rb +0 -60
- data/lib/gisele/language/rewriter/helper.rb +0 -41
- data/lib/gisele/language/rewriter/scoping.rb +0 -34
- data/lib/gisele/language/rewriter/work_on_nodes.rb +0 -30
- data/lib/gisele/language/syntax.rb +0 -29
- data/spec/unit/language/ast/test_node.rb +0 -82
- data/spec/unit/language/processors/test_to_graph.rb +0 -17
- data/spec/unit/language/rewriter/test_helper.rb +0 -87
- data/spec/unit/language/rewriter/test_scoping.rb +0 -46
- data/spec/unit/language/rewriter/test_work_on_nodes.rb +0 -45
- data/spec/unit/language/test_ast.rb +0 -38
- data/spec/unit/language/test_rewriter.rb +0 -81
- 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
|
data/lib/gisele/language.rb
CHANGED
@@ -1,45 +1,31 @@
|
|
1
|
+
require 'yaml'
|
1
2
|
module Gisele
|
2
|
-
module Language
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
30
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
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,15 @@ module Gisele
|
|
5
5
|
include Node
|
6
6
|
|
7
7
|
def label
|
8
|
-
|
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
|
@@ -3,63 +3,8 @@ module Gisele
|
|
3
3
|
module AST
|
4
4
|
module Node
|
5
5
|
|
6
|
-
|
7
|
-
|
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
|
-
|
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,80 +1,83 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
event_set
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
-
|
79
|
-
-
|
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,16 +1,16 @@
|
|
1
1
|
module Gisele
|
2
2
|
module Language
|
3
|
-
class ElsifFlattener < Rewriter
|
4
|
-
|
3
|
+
class ElsifFlattener < Sexpr::Rewriter
|
4
|
+
grammar Language
|
5
5
|
|
6
|
-
def on_if_st(
|
7
|
-
condition, dost, *clauses =
|
6
|
+
def on_if_st(sexpr)
|
7
|
+
condition, dost, *clauses = sexpr.sexpr_body
|
8
8
|
|
9
9
|
base = [:if_st, condition, dost]
|
10
|
-
base =
|
10
|
+
base = sexpr(base, sexpr.tracking_markers)
|
11
11
|
|
12
12
|
clauses.inject base do |cur_if, clause|
|
13
|
-
rw_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(
|
21
|
+
def on_elsif_clause(sexpr)
|
22
22
|
base = \
|
23
23
|
[:else_clause,
|
24
|
-
[:if_st,
|
25
|
-
base =
|
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(
|
29
|
-
[:else_clause,
|
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
|