gisele-language 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/CHANGELOG.md +5 -0
  2. data/Gemfile +12 -0
  3. data/Gemfile.lock +26 -0
  4. data/LICENCE.md +22 -0
  5. data/Manifest.txt +13 -0
  6. data/README.md +7 -0
  7. data/Rakefile +11 -0
  8. data/gisele-language.gemspec +188 -0
  9. data/gisele-language.noespec +24 -0
  10. data/lib/gisele/language/ast/bool_and.rb +14 -0
  11. data/lib/gisele/language/ast/bool_expr.rb +22 -0
  12. data/lib/gisele/language/ast/bool_not.rb +14 -0
  13. data/lib/gisele/language/ast/bool_or.rb +14 -0
  14. data/lib/gisele/language/ast/case_st.rb +14 -0
  15. data/lib/gisele/language/ast/else_clause.rb +14 -0
  16. data/lib/gisele/language/ast/elsif_clause.rb +14 -0
  17. data/lib/gisele/language/ast/if_st.rb +14 -0
  18. data/lib/gisele/language/ast/node.rb +35 -0
  19. data/lib/gisele/language/ast/task_call_st.rb +14 -0
  20. data/lib/gisele/language/ast/var_ref.rb +14 -0
  21. data/lib/gisele/language/ast/when_clause.rb +14 -0
  22. data/lib/gisele/language/ast/while_st.rb +14 -0
  23. data/lib/gisele/language/grammar.citrus +236 -0
  24. data/lib/gisele/language/grammar.sexp.yml +83 -0
  25. data/lib/gisele/language/processors/elsif_flattener.rb +36 -0
  26. data/lib/gisele/language/processors/if_to_case.rb +65 -0
  27. data/lib/gisele/language/processors/scoping_helper.rb +32 -0
  28. data/lib/gisele/language/processors/sugar_removal.rb +17 -0
  29. data/lib/gisele/language/processors.rb +4 -0
  30. data/lib/gisele/language/syntax/bool_and.rb +14 -0
  31. data/lib/gisele/language/syntax/bool_expr.rb +14 -0
  32. data/lib/gisele/language/syntax/bool_lit.rb +14 -0
  33. data/lib/gisele/language/syntax/bool_not.rb +14 -0
  34. data/lib/gisele/language/syntax/bool_or.rb +14 -0
  35. data/lib/gisele/language/syntax/bool_paren.rb +14 -0
  36. data/lib/gisele/language/syntax/case_st.rb +19 -0
  37. data/lib/gisele/language/syntax/else_clause.rb +14 -0
  38. data/lib/gisele/language/syntax/elsif_clause.rb +16 -0
  39. data/lib/gisele/language/syntax/event_set.rb +15 -0
  40. data/lib/gisele/language/syntax/fluent_def.rb +18 -0
  41. data/lib/gisele/language/syntax/if_st.rb +18 -0
  42. data/lib/gisele/language/syntax/implicit_seq_st.rb +16 -0
  43. data/lib/gisele/language/syntax/node.rb +40 -0
  44. data/lib/gisele/language/syntax/par_st.rb +14 -0
  45. data/lib/gisele/language/syntax/seq_st.rb +14 -0
  46. data/lib/gisele/language/syntax/st_list.rb +14 -0
  47. data/lib/gisele/language/syntax/task_call_st.rb +14 -0
  48. data/lib/gisele/language/syntax/task_def.rb +18 -0
  49. data/lib/gisele/language/syntax/trackvar_def.rb +19 -0
  50. data/lib/gisele/language/syntax/unit_def.rb +14 -0
  51. data/lib/gisele/language/syntax/var_ref.rb +14 -0
  52. data/lib/gisele/language/syntax/when_clause.rb +16 -0
  53. data/lib/gisele/language/syntax/while_st.rb +16 -0
  54. data/lib/gisele/language.rb +31 -0
  55. data/lib/gisele-language/loader.rb +3 -0
  56. data/lib/gisele-language/version.rb +16 -0
  57. data/lib/gisele-language.rb +19 -0
  58. data/spec/fixtures/tasks/complete.gis +40 -0
  59. data/spec/fixtures/tasks/simple.ast +51 -0
  60. data/spec/fixtures/tasks/simple.gis +16 -0
  61. data/spec/language/ast/test_bool_expr.rb +50 -0
  62. data/spec/language/grammar_sexp/test_case_st.rb +20 -0
  63. data/spec/language/grammar_sexp/test_event_set.rb +14 -0
  64. data/spec/language/grammar_sexp/test_fluent_def.rb +18 -0
  65. data/spec/language/grammar_sexp/test_initially.rb +18 -0
  66. data/spec/language/grammar_sexp/test_nop_st.rb +10 -0
  67. data/spec/language/grammar_sexp/test_when_clause.rb +12 -0
  68. data/spec/language/processors/test_elsif_flattener.rb +94 -0
  69. data/spec/language/processors/test_if_to_case.rb +105 -0
  70. data/spec/language/processors/test_scoping_helper.rb +45 -0
  71. data/spec/language/syntax/grammar/test_bool_expr.rb +34 -0
  72. data/spec/language/syntax/grammar/test_boolean_literal.rb +17 -0
  73. data/spec/language/syntax/grammar/test_case_st.rb +60 -0
  74. data/spec/language/syntax/grammar/test_event.rb +18 -0
  75. data/spec/language/syntax/grammar/test_event_name.rb +21 -0
  76. data/spec/language/syntax/grammar/test_event_set.rb +26 -0
  77. data/spec/language/syntax/grammar/test_fluent_def.rb +21 -0
  78. data/spec/language/syntax/grammar/test_if_st.rb +21 -0
  79. data/spec/language/syntax/grammar/test_par_st.rb +11 -0
  80. data/spec/language/syntax/grammar/test_process_statement.rb +19 -0
  81. data/spec/language/syntax/grammar/test_seq_st.rb +11 -0
  82. data/spec/language/syntax/grammar/test_spaces.rb +19 -0
  83. data/spec/language/syntax/grammar/test_spacing.rb +17 -0
  84. data/spec/language/syntax/grammar/test_task_def.rb +35 -0
  85. data/spec/language/syntax/grammar/test_task_name.rb +19 -0
  86. data/spec/language/syntax/grammar/test_task_start_or_end.rb +17 -0
  87. data/spec/language/syntax/grammar/test_trackvar_def.rb +21 -0
  88. data/spec/language/syntax/grammar/test_unit_def.rb +29 -0
  89. data/spec/language/syntax/grammar/test_variable_name.rb +51 -0
  90. data/spec/language/syntax/grammar/test_when_clause.rb +21 -0
  91. data/spec/language/syntax/grammar/test_while_st.rb +11 -0
  92. data/spec/language/syntax/to_ast/test_bool_expr.rb +32 -0
  93. data/spec/language/syntax/to_ast/test_case_st.rb +47 -0
  94. data/spec/language/syntax/to_ast/test_else_clause.rb +13 -0
  95. data/spec/language/syntax/to_ast/test_elsif_clause.rb +15 -0
  96. data/spec/language/syntax/to_ast/test_event_set.rb +24 -0
  97. data/spec/language/syntax/to_ast/test_fluent_def.rb +26 -0
  98. data/spec/language/syntax/to_ast/test_if_st.rb +39 -0
  99. data/spec/language/syntax/to_ast/test_par_st.rb +12 -0
  100. data/spec/language/syntax/to_ast/test_seq_st.rb +12 -0
  101. data/spec/language/syntax/to_ast/test_task_call_st.rb +10 -0
  102. data/spec/language/syntax/to_ast/test_task_def.rb +44 -0
  103. data/spec/language/syntax/to_ast/test_trackvar_def.rb +26 -0
  104. data/spec/language/syntax/to_ast/test_unit_def.rb +28 -0
  105. data/spec/language/syntax/to_ast/test_var_ref.rb +12 -0
  106. data/spec/language/syntax/to_ast/test_when_clause.rb +15 -0
  107. data/spec/language/syntax/to_ast/test_while_st.rb +24 -0
  108. data/spec/language/test_syntax.rb +51 -0
  109. data/spec/spec_helper.rb +44 -0
  110. data/spec/test_gisele-language.rb +8 -0
  111. data/tasks/gem.rake +73 -0
  112. data/tasks/spec_test.rake +71 -0
  113. metadata +269 -0
@@ -0,0 +1,236 @@
1
+ grammar Gisele::Language::Grammar
2
+
3
+ ### Units
4
+
5
+ rule unit_def
6
+ (spacing task_def (spaces task_def)* spacing)
7
+ <Gisele::Language::Syntax::UnitDef>
8
+ end
9
+
10
+ ### Task definitions
11
+
12
+ rule task_def
13
+ ('task' spaces task_name spaces
14
+ (some_def spaces)*
15
+ (explicit_statement spaces)?
16
+ 'end')
17
+ <Gisele::Language::Syntax::TaskDef>
18
+ end
19
+
20
+ rule some_def
21
+ fluent_def | trackvar_def | task_def
22
+ end
23
+
24
+ ### Process statements
25
+
26
+ rule process_statement
27
+ implicit_seq_st | explicit_statement
28
+ end
29
+
30
+ rule implicit_seq_st
31
+ (explicit_statement spaces st_list)
32
+ <Gisele::Language::Syntax::ImplicitSeqSt>
33
+ end
34
+
35
+ rule st_list
36
+ (explicit_statement (spaces explicit_statement)*)
37
+ <Gisele::Language::Syntax::StList>
38
+ end
39
+
40
+ rule explicit_statement
41
+ if_st
42
+ | case_st
43
+ | while_st
44
+ | seq_st
45
+ | par_st
46
+ | task_call_st
47
+ end
48
+
49
+ rule case_st
50
+ ('case' spaces (var_ref spaces)?
51
+ (when_clause spaces)+
52
+ (else_clause spaces)?
53
+ 'end')
54
+ <Gisele::Language::Syntax::CaseSt>
55
+ end
56
+
57
+ rule when_clause
58
+ ('when' spaces bool_expr spaces process_statement)
59
+ <Gisele::Language::Syntax::WhenClause>
60
+ end
61
+
62
+ rule if_st
63
+ ('if' spaces bool_expr spaces
64
+ process_statement spaces
65
+ (elsif_clause spaces)*
66
+ (else_clause spaces)?
67
+ 'end')
68
+ <Gisele::Language::Syntax::IfSt>
69
+ end
70
+
71
+ rule elsif_clause
72
+ ('elsif' spaces bool_expr spaces process_statement)
73
+ <Gisele::Language::Syntax::ElsifClause>
74
+ end
75
+
76
+ rule else_clause
77
+ ('else' spaces process_statement)
78
+ <Gisele::Language::Syntax::ElseClause>
79
+ end
80
+
81
+ rule while_st
82
+ ('while' spaces bool_expr spaces process_statement spaces 'end')
83
+ <Gisele::Language::Syntax::WhileSt>
84
+ end
85
+
86
+ rule seq_st
87
+ ('seq' spaces st_list spaces 'end')
88
+ <Gisele::Language::Syntax::SeqSt>
89
+ end
90
+
91
+ rule par_st
92
+ ('par' spaces st_list spaces 'end')
93
+ <Gisele::Language::Syntax::ParSt>
94
+ end
95
+
96
+ rule task_call_st
97
+ (task_name)
98
+ <Gisele::Language::Syntax::TaskCallSt>
99
+ end
100
+
101
+ ### Boolean expressions
102
+
103
+ rule bool_expr
104
+ (spacing theexpr:bool_or)
105
+ <Gisele::Language::Syntax::BoolExpr>
106
+ end
107
+
108
+ rule bool_or
109
+ (left:bool_and spaces 'or' spaces right:bool_or)
110
+ <Gisele::Language::Syntax::BoolOr>
111
+ | bool_and
112
+ end
113
+
114
+ rule bool_and
115
+ (left:bool_not spaces 'and' spaces right:bool_and)
116
+ <Gisele::Language::Syntax::BoolAnd>
117
+ | bool_not
118
+ end
119
+
120
+ rule bool_not
121
+ ('not' &([ \t\n] | '(') spacing expr:bool_not)
122
+ <Gisele::Language::Syntax::BoolNot>
123
+ | bool_term
124
+ end
125
+
126
+ rule bool_term
127
+ bool_paren | bool_lit | var_ref
128
+ end
129
+
130
+ rule bool_paren
131
+ ('(' spacing expr:bool_or spacing ')')
132
+ <Gisele::Language::Syntax::BoolParen>
133
+ end
134
+
135
+ rule bool_lit
136
+ (boolean_literal)
137
+ <Gisele::Language::Syntax::BoolLit>
138
+ end
139
+
140
+ ### Variables
141
+
142
+ rule variable_def
143
+ trackvar_def | fluent_def
144
+ end
145
+
146
+ rule trackvar_def
147
+ ('trackvar' spaces variable_name spacing event_set (spacing ',' spacing event_set)? initially_def?)
148
+ <Gisele::Language::Syntax::TrackvarDef>
149
+ end
150
+
151
+ rule fluent_def
152
+ ('fluent' spaces variable_name spacing event_set spacing ',' spacing event_set initially_def?)
153
+ <Gisele::Language::Syntax::FluentDef>
154
+ end
155
+
156
+ rule initially_def
157
+ (spaces 'initially' spaces lit:boolean_literal){ lit.value }
158
+ end
159
+
160
+ rule var_ref
161
+ (variable_name)
162
+ <Gisele::Language::Syntax::VarRef>
163
+ end
164
+
165
+ ### Events
166
+
167
+ rule event_set
168
+ ('{' spacing (event (spacing ',' spacing event)*)? spacing '}')
169
+ <Gisele::Language::Syntax::EventSet>
170
+ end
171
+
172
+ rule event
173
+ task_start_or_end | event_name
174
+ end
175
+
176
+ rule task_start_or_end
177
+ task_name ':' ('start' | 'end')
178
+ end
179
+
180
+ ### Names
181
+
182
+ rule task_name
183
+ [A-Z] [A-Za-z0-9_]*
184
+ end
185
+
186
+ rule variable_name
187
+ !(reserved_word spaces) [a-z] [A-Za-z0-9_]*
188
+ end
189
+
190
+ rule event_name
191
+ !(reserved_word spaces) [a-z] [a-z0-9_]*
192
+ end
193
+
194
+ ### Literals
195
+
196
+ rule boolean_literal
197
+ ('true' | 'false'){ strip == "true" }
198
+ end
199
+
200
+ ### Spacing
201
+
202
+ rule comment
203
+ "#" (![\n] .)*
204
+ end
205
+
206
+ rule spaces
207
+ (comment | [ \t\n])+
208
+ end
209
+
210
+ rule spacing
211
+ (comment | [ \t\n])*
212
+ end
213
+
214
+ ### Reserved Words
215
+ rule reserved_word
216
+ "if"
217
+ | "else"
218
+ | "elsif"
219
+ | "when"
220
+ | "while"
221
+ | "seq"
222
+ | "par"
223
+ | "task"
224
+ | "refinement"
225
+ | "fluent"
226
+ | "trackvar"
227
+ | "initially"
228
+ | "end"
229
+ | "not"
230
+ | "or"
231
+ | "and"
232
+ | "true"
233
+ | "false"
234
+ end
235
+
236
+ end
@@ -0,0 +1,83 @@
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
+ - ~
@@ -0,0 +1,36 @@
1
+ module Gisele
2
+ module Language
3
+ class ElsifFlattener < Sexpr::Rewriter
4
+ grammar Language
5
+
6
+ def on_if_st(sexpr)
7
+ condition, dost, *clauses = sexpr.sexpr_body
8
+
9
+ base = [:if_st, condition, dost]
10
+ base = sexpr(base, sexpr.tracking_markers)
11
+
12
+ clauses.inject base do |cur_if, clause|
13
+ rw_clause = apply(clause)
14
+ cur_if << rw_clause
15
+ rw_clause.last
16
+ end
17
+
18
+ base
19
+ end
20
+
21
+ def on_elsif_clause(sexpr)
22
+ base = \
23
+ [:else_clause,
24
+ [:if_st, sexpr[1], apply(sexpr[2])] ]
25
+ base = sexpr(base, sexpr.tracking_markers)
26
+ end
27
+
28
+ def on_else_clause(sexpr)
29
+ [:else_clause, apply(sexpr.last)]
30
+ end
31
+
32
+ alias :on_missing :copy_and_apply
33
+
34
+ end # class ElsifFlattener
35
+ end # module Language
36
+ end # module Gisele
@@ -0,0 +1,65 @@
1
+ module Gisele
2
+ module Language
3
+ class IfToCase < Sexpr::Rewriter
4
+ grammar Language
5
+
6
+ def on_if_st(sexpr)
7
+ condition, dost, *clauses = sexpr.sexpr_body
8
+
9
+ # create case_st with same markers as the if_st
10
+ when_clause = [:when_clause, condition, apply(dost)]
11
+ when_clause = sexpr(when_clause, sexpr.tracking_markers)
12
+ base = [:case_st, nil, when_clause]
13
+ base = sexpr(base, sexpr.tracking_markers)
14
+
15
+ # this is the condition for elsif clauses
16
+ @condition = negate(condition.last)
17
+
18
+ # make injection now
19
+ clauses.inject base do |memo,clause|
20
+ memo << apply(clause)
21
+ end
22
+ end
23
+
24
+ def on_elsif_clause(sexpr)
25
+ condition, dost, = sexpr.sexpr_body
26
+
27
+ # install new conditions for me and next elsif clauses
28
+ condition = condition.last
29
+ previous = @condition
30
+ @condition = [:bool_and, negate(condition), @condition]
31
+
32
+ # convert elsif to when and keep the markers
33
+ base = \
34
+ [:when_clause,
35
+ [:bool_expr, [:bool_and, condition, previous]],
36
+ apply(dost) ]
37
+ sexpr(base, sexpr.tracking_markers)
38
+ end
39
+
40
+ def on_else_clause(sexpr)
41
+ dost, = sexpr.sexpr_body
42
+
43
+ # convert else to when and keep the markers
44
+ base = \
45
+ [:when_clause,
46
+ [:bool_expr, @condition],
47
+ apply(dost)]
48
+ sexpr(base, sexpr.tracking_markers)
49
+ end
50
+
51
+ alias :on_missing :copy_and_apply
52
+
53
+ private
54
+
55
+ def negate(cond)
56
+ if cond.first == :bool_not
57
+ cond.last
58
+ else
59
+ [:bool_not, cond]
60
+ end
61
+ end
62
+
63
+ end # class IfToCase
64
+ end # module Language
65
+ end # module Gisele
@@ -0,0 +1,32 @@
1
+ module Gisele
2
+ module Language
3
+ class ScopingHelper < Sexpr::Processor::Helper
4
+
5
+ module Methods
6
+
7
+ def scope_stack
8
+ @scope_stack ||= []
9
+ end
10
+
11
+ def with_scope(scope)
12
+ scope_stack.push(scope)
13
+ result = yield
14
+ scope_stack.pop
15
+ result
16
+ end
17
+
18
+ end # module Methods
19
+
20
+ def on_missing(rw, sexpr)
21
+ if sexpr.first.to_s =~ /_def/
22
+ rw.with_scope(sexpr) do
23
+ yield(rw, sexpr)
24
+ end
25
+ else
26
+ yield(rw, sexpr)
27
+ end
28
+ end
29
+
30
+ end # module ScopingHelper
31
+ end # module Language
32
+ end # module Gisele
@@ -0,0 +1,17 @@
1
+ module Gisele
2
+ module Language
3
+ class SugarRemoval < Sexpr::Rewriter
4
+ grammar Language
5
+
6
+ # (elsif ... -> else if ...)
7
+ use ElsifFlattener
8
+
9
+ def apply(sexpr)
10
+ # all is already done by preprocessors so that we can simply return
11
+ # the s-expression.
12
+ sexpr
13
+ end
14
+
15
+ end # class SugarRemoval
16
+ end # module Language
17
+ end # module Gisele
@@ -0,0 +1,4 @@
1
+ require_relative 'processors/scoping_helper'
2
+ require_relative 'processors/elsif_flattener'
3
+ require_relative 'processors/if_to_case'
4
+ require_relative 'processors/sugar_removal'
@@ -0,0 +1,14 @@
1
+ module Gisele
2
+ module Language
3
+ module Syntax
4
+ module BoolAnd
5
+ include Node
6
+
7
+ def _to_ast
8
+ [:bool_and, left.to_ast, right.to_ast]
9
+ end
10
+
11
+ end # module BoolAnd
12
+ end # module Syntax
13
+ end # module Language
14
+ end # module Gisele
@@ -0,0 +1,14 @@
1
+ module Gisele
2
+ module Language
3
+ module Syntax
4
+ module BoolExpr
5
+ include Node
6
+
7
+ def _to_ast
8
+ [:bool_expr, captures[:theexpr].first.to_ast]
9
+ end
10
+
11
+ end # module BoolExpr
12
+ end # module Syntax
13
+ end # module Language
14
+ end # module Gisele
@@ -0,0 +1,14 @@
1
+ module Gisele
2
+ module Language
3
+ module Syntax
4
+ module BoolLit
5
+ include Node
6
+
7
+ def _to_ast
8
+ [:bool_lit, strip == "true"]
9
+ end
10
+
11
+ end # module BoolLit
12
+ end # module Syntax
13
+ end # module Language
14
+ end # module Gisele
@@ -0,0 +1,14 @@
1
+ module Gisele
2
+ module Language
3
+ module Syntax
4
+ module BoolNot
5
+ include Node
6
+
7
+ def _to_ast
8
+ [:bool_not, captures[:expr].first.to_ast]
9
+ end
10
+
11
+ end # module BoolParen
12
+ end # module Syntax
13
+ end # module Language
14
+ end # module Gisele
@@ -0,0 +1,14 @@
1
+ module Gisele
2
+ module Language
3
+ module Syntax
4
+ module BoolOr
5
+ include Node
6
+
7
+ def _to_ast
8
+ [:bool_or, left.to_ast, right.to_ast]
9
+ end
10
+
11
+ end # module BoolOr
12
+ end # module Syntax
13
+ end # module Language
14
+ end # module Gisele
@@ -0,0 +1,14 @@
1
+ module Gisele
2
+ module Language
3
+ module Syntax
4
+ module BoolParen
5
+ include Node
6
+
7
+ def _to_ast
8
+ captures[:expr].first.to_ast
9
+ end
10
+
11
+ end # module BoolParen
12
+ end # module Syntax
13
+ end # module Language
14
+ end # module Gisele
@@ -0,0 +1,19 @@
1
+ module Gisele
2
+ module Language
3
+ module Syntax
4
+ module CaseSt
5
+ include Node
6
+
7
+ def _to_ast
8
+ var = captures[:var_ref].first
9
+ var = var.to_ast if var
10
+ var = nil if var && var.empty?
11
+ whens = captures[:when_clause].map{|x| x.to_ast}
12
+ els = captures[:else_clause].map{|x| x.to_ast}
13
+ [:case_st, var] + whens + els
14
+ end
15
+
16
+ end # module CaseSt
17
+ end # module Syntax
18
+ end # module Language
19
+ end # module Gisele
@@ -0,0 +1,14 @@
1
+ module Gisele
2
+ module Language
3
+ module Syntax
4
+ module ElseClause
5
+ include Node
6
+
7
+ def _to_ast
8
+ [:else_clause, captures[:process_statement].first.to_ast]
9
+ end
10
+
11
+ end # module ElseClause
12
+ end # module Syntax
13
+ end # module Language
14
+ end # module Gisele
@@ -0,0 +1,16 @@
1
+ module Gisele
2
+ module Language
3
+ module Syntax
4
+ module ElsifClause
5
+ include Node
6
+
7
+ def _to_ast
8
+ cond = captures[:bool_expr].first.to_ast
9
+ dost = captures[:process_statement].first.to_ast
10
+ [:elsif_clause, cond, dost]
11
+ end
12
+
13
+ end # module ElsifClause
14
+ end # module Syntax
15
+ end # module Language
16
+ end # module Gisele
@@ -0,0 +1,15 @@
1
+ module Gisele
2
+ module Language
3
+ module Syntax
4
+ module EventSet
5
+ include Node
6
+
7
+ def _to_ast
8
+ events = (captures[:event] || []).map{|e| e.value}
9
+ [:event_set] + events
10
+ end
11
+
12
+ end # module EventSet
13
+ end # module Syntax
14
+ end # module Language
15
+ end # module Gisele
@@ -0,0 +1,18 @@
1
+ module Gisele
2
+ module Language
3
+ module Syntax
4
+ module FluentDef
5
+ include Node
6
+
7
+ def _to_ast
8
+ name = captures[:variable_name].first.strip
9
+ init, term = captures[:event_set].map{|x| x.to_ast}
10
+ initval = captures[:initially_def].first
11
+ initval = (initval && !initval.empty?) ? initval.value : nil
12
+ [:fluent_def, name, init, term, initval]
13
+ end
14
+
15
+ end # module FluentDef
16
+ end # module Syntax
17
+ end # module Language
18
+ end # module Gisele
@@ -0,0 +1,18 @@
1
+ module Gisele
2
+ module Language
3
+ module Syntax
4
+ module IfSt
5
+ include Node
6
+
7
+ def _to_ast
8
+ cond = captures[:bool_expr].first.to_ast
9
+ dost = captures[:process_statement].first.to_ast
10
+ elsifs = captures[:elsif_clause].map{|x| x.to_ast}
11
+ els = captures[:else_clause].map{|x| x.to_ast}
12
+ [:if_st, cond, dost] + elsifs + els
13
+ end
14
+
15
+ end # module IfSt
16
+ end # module Syntax
17
+ end # module Language
18
+ end # module Gisele
@@ -0,0 +1,16 @@
1
+ module Gisele
2
+ module Language
3
+ module Syntax
4
+ module ImplicitSeqSt
5
+ include Node
6
+
7
+ def _to_ast
8
+ front = captures[:explicit_statement].first.to_ast
9
+ tail = captures[:st_list].first.value
10
+ [:seq_st, front] + tail
11
+ end
12
+
13
+ end # module ImplicitSeqSt
14
+ end # module Syntax
15
+ end # module Language
16
+ end # module Gisele