gisele 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/CHANGELOG.md +39 -1
  2. data/gisele.noespec +1 -1
  3. data/lib/gisele/command.rb +13 -4
  4. data/lib/gisele/errors.rb +21 -0
  5. data/lib/gisele/language/ast/helpers.rb +37 -0
  6. data/lib/gisele/language/ast/node.rb +54 -0
  7. data/lib/gisele/language/ast/unit.rb +10 -0
  8. data/lib/gisele/language/ast.rb +14 -0
  9. data/lib/gisele/language/sugar_removal.rb +53 -0
  10. data/lib/gisele/language/syntax/bool_and.rb +14 -0
  11. data/lib/gisele/language/syntax/bool_lit.rb +14 -0
  12. data/lib/gisele/language/syntax/bool_not.rb +14 -0
  13. data/lib/gisele/language/syntax/bool_or.rb +14 -0
  14. data/lib/gisele/language/syntax/bool_paren.rb +14 -0
  15. data/lib/gisele/language/syntax/else_clause.rb +14 -0
  16. data/lib/gisele/language/syntax/elsif_clause.rb +16 -0
  17. data/lib/gisele/language/syntax/event_set.rb +15 -0
  18. data/lib/gisele/language/syntax/fluent_def.rb +18 -0
  19. data/lib/gisele/language/syntax/grammar.citrus +202 -0
  20. data/lib/gisele/language/syntax/if_st.rb +18 -0
  21. data/lib/gisele/language/syntax/implicit_seq_st.rb +16 -0
  22. data/lib/gisele/language/syntax/node.rb +35 -0
  23. data/lib/gisele/language/syntax/par_st.rb +14 -0
  24. data/lib/gisele/language/syntax/seq_st.rb +14 -0
  25. data/lib/gisele/language/syntax/st_list.rb +14 -0
  26. data/lib/gisele/language/syntax/task_call_st.rb +14 -0
  27. data/lib/gisele/language/syntax/task_def.rb +17 -0
  28. data/lib/gisele/language/syntax/task_refinement.rb +15 -0
  29. data/lib/gisele/language/syntax/task_signature.rb +15 -0
  30. data/lib/gisele/language/syntax/trackvar_def.rb +19 -0
  31. data/lib/gisele/language/syntax/unit.rb +14 -0
  32. data/lib/gisele/language/syntax/var_ref.rb +14 -0
  33. data/lib/gisele/language/syntax/while_st.rb +16 -0
  34. data/lib/gisele/language/syntax.rb +29 -0
  35. data/lib/gisele/language/transformer.rb +38 -0
  36. data/lib/gisele/language.rb +15 -1
  37. data/lib/gisele/version.rb +2 -2
  38. data/lib/gisele.rb +7 -1
  39. data/spec/command/main/gisele_ast_ruby.stdout +38 -28
  40. data/spec/command/main/gisele_help.stdout +5 -0
  41. data/spec/command/main/gisele_no_sugar.cmd +1 -0
  42. data/spec/command/main/gisele_no_sugar.stdout +61 -0
  43. data/spec/fixtures/tasks/simple.ast +18 -14
  44. data/spec/fixtures/tasks/simple.gis +2 -0
  45. data/spec/spec_helper.rb +3 -3
  46. data/spec/test_examples.rb +3 -3
  47. data/spec/unit/language/ast/test_node.rb +61 -0
  48. data/spec/unit/language/sugar_removal/test_if_to_guarded_commands.rb +90 -0
  49. data/spec/unit/language/{test_grammar.rb → syntax/test_grammar.rb} +18 -30
  50. data/spec/unit/language/syntax/test_to_ast.rb +245 -0
  51. data/spec/unit/language/test_ast.rb +21 -247
  52. data/spec/unit/language/test_syntax.rb +48 -0
  53. data/spec/unit/language/test_transformer.rb +68 -0
  54. data/spec/unit/test_language.rb +35 -0
  55. metadata +69 -25
  56. data/lib/gisele/language/grammar.citrus +0 -246
  57. data/lib/gisele/language/parser.rb +0 -30
  58. data/spec/unit/language/test_parser.rb +0 -27
@@ -1,246 +0,0 @@
1
- grammar Gisele::Language::Grammar
2
-
3
- ### Units
4
-
5
- rule task_unit
6
- (spacing defn:task_def spacing){
7
- defn.value
8
- }
9
- end
10
-
11
- ### Task definitions
12
-
13
- rule task_def
14
- ('task' spaces tname:task_name spaces
15
- signature:(task_signature spaces)?
16
- refinement:(task_refinement spaces)?
17
- 'end'){
18
- sigvalue = [:signature] + (signature.empty? ? [] : signature.first.first.value)
19
- refvalue = [:refinement, (refinement.empty? ? [] : refinement.first.first.value)]
20
- [:task, tname.value, sigvalue, refvalue]
21
- }
22
- end
23
-
24
- rule task_signature
25
- (front:task_signature_element tail:(spaces task_signature)?){
26
- [front.value] + (tail.empty? ? [] : tail.first.matches.last.value)
27
- }
28
- end
29
-
30
- rule task_signature_element
31
- fluent_def | trackvar_def
32
- end
33
-
34
- rule task_refinement
35
- ('refinement' spaces main:process_statement spaces 'end'){
36
- main.value
37
- }
38
- end
39
-
40
- ### Process statements
41
-
42
- rule process_statement
43
- implicit_seq_statement | explicit_statement
44
- end
45
-
46
- rule implicit_seq_statement
47
- (front:explicit_statement spaces tail:statement_list){
48
- [:seq, front.value] + tail.value
49
- }
50
- end
51
-
52
- rule statement_list
53
- (f:explicit_statement t:(spaces statement_list)?){
54
- [f.value] + (t.empty? ? [] : t.first.matches.last.value)
55
- }
56
- end
57
-
58
- rule explicit_statement
59
- if_statement
60
- | while_statement
61
- | seq_statement
62
- | par_statement
63
- | task_call_statement
64
- end
65
-
66
- rule if_statement
67
- ('if' spaces cond:bool_expr spaces
68
- dost:process_statement spaces
69
- elsifclauses:elsif_clause*
70
- elseclause:else_clause?
71
- 'end'){
72
- elsifs = elsifclauses.matches.map{|c| c.value}
73
- elsec = elseclause.empty? ? [] : [elseclause.first.value]
74
- [:if, cond.value, dost.value] + elsifs + elsec
75
- }
76
- end
77
-
78
- rule elsif_clause
79
- ('elsif' spaces cond:bool_expr spaces dost:process_statement spaces){
80
- [:elsif, cond.value, dost.value]
81
- }
82
- end
83
-
84
- rule else_clause
85
- ('else' spaces dost:process_statement spaces){
86
- [:else, dost.value]
87
- }
88
- end
89
-
90
- rule while_statement
91
- ('while' spaces cond:bool_expr spaces
92
- dost:process_statement spaces
93
- 'end'){
94
- [:while, cond.value, dost.value]
95
- }
96
- end
97
-
98
- rule seq_statement
99
- ('seq' spaces list:statement_list spaces 'end'){
100
- [:seq] + list.value
101
- }
102
- end
103
-
104
- rule par_statement
105
- ('par' spaces list:statement_list spaces 'end'){
106
- [:par] + list.value
107
- }
108
- end
109
-
110
- rule task_call_statement
111
- (task_name){
112
- [:task_call, strip]
113
- }
114
- end
115
-
116
- ### Boolean expressions
117
-
118
- rule bool_expr
119
- bool_or
120
- end
121
-
122
- rule bool_or
123
- (left:bool_and spaces 'or' spaces right:bool_or){
124
- [:or, left.value, right.value]
125
- }
126
- | bool_and
127
- end
128
-
129
- rule bool_and
130
- (left:bool_not spaces 'and' spaces right:bool_and){
131
- [:and, left.value, right.value]
132
- }
133
- | bool_not
134
- end
135
-
136
- rule bool_not
137
- ('not' &([ \t\n] | '(') spacing term:bool_not){
138
- [:not, term.value]
139
- }
140
- | bool_term
141
- end
142
-
143
- rule bool_term
144
- bool_parenthesed | boolean_literal | bool_varref
145
- end
146
-
147
- rule bool_parenthesed
148
- ('(' spacing expr:bool_expr spacing ')'){
149
- expr.value
150
- }
151
- end
152
-
153
- rule bool_varref
154
- (variable_name){
155
- [:varref, strip]
156
- }
157
- end
158
-
159
- ### Variables
160
-
161
- rule variable_def
162
- trackvar_def | fluent_def
163
- end
164
-
165
- rule trackvar_def
166
- ('trackvar' spaces name:variable_name spacing
167
- init:event_set term:(spacing ',' spacing event_set)?
168
- initially:initially_def?){
169
- termval = term.empty? ? [:event_set] : term.first.matches.last.value
170
- initval = initially.empty? ? nil : initially.first.value
171
- [:trackvar, name.value, init.value, termval, initval]
172
- }
173
- end
174
-
175
- rule fluent_def
176
- ('fluent' spaces name:variable_name spacing
177
- init:event_set spacing ',' spacing term:event_set initially:initially_def?){
178
- initval = initially.empty? ? nil : initially.first.value
179
- [:fluent, name.value, init.value, term.value, initval]
180
- }
181
- end
182
-
183
- rule initially_def
184
- (spaces 'initially' spaces lit:boolean_literal){
185
- lit.value
186
- }
187
- end
188
-
189
- ### Events
190
-
191
- rule event_set
192
- ('{' spacing list:event_commalist? spacing '}'){
193
- [:event_set] + (list.empty? ? [] : list.first.value)
194
- }
195
- end
196
-
197
- rule event_commalist
198
- (front:event tail:(spacing ',' spacing event_commalist)?){
199
- tailval = tail.empty? ? [] : tail.first.matches.last.value
200
- [ front.value ] + tailval
201
- }
202
- end
203
-
204
- rule event
205
- task_start_or_end | event_name
206
- end
207
-
208
- rule task_start_or_end
209
- task_name ':' ('start' | 'end')
210
- end
211
-
212
- ### Names
213
-
214
- rule task_name
215
- [A-Z] [A-Za-z0-9_]*
216
- end
217
-
218
- rule variable_name
219
- [a-z] [A-Za-z0-9_]*
220
- end
221
-
222
- rule event_name
223
- [a-z] [a-z0-9_]*
224
- end
225
-
226
- ### Literals
227
-
228
- rule boolean_literal
229
- ('true' | 'false'){ strip == "true" ? true : false }
230
- end
231
-
232
- ### Spacing
233
-
234
- rule comment
235
- "#" (![\n] .)*
236
- end
237
-
238
- rule spaces
239
- (comment | [ \t\n])+
240
- end
241
-
242
- rule spacing
243
- (comment | [ \t\n])*
244
- end
245
-
246
- end
@@ -1,30 +0,0 @@
1
- module Gisele
2
- module Language
3
- Citrus.load(File.expand_path('../grammar', __FILE__))
4
- class Parser
5
-
6
- def self.parse(input)
7
- new.parse(input)
8
- end
9
-
10
- def call(input)
11
- return input if input.is_a?(Array)
12
- grammar.parse(parsing_source(input)).value
13
- end
14
- alias :parse :call
15
-
16
- private
17
-
18
- def grammar
19
- Gisele::Language::Grammar
20
- end
21
-
22
- def parsing_source(input)
23
- input = File.read(input.to_path) if input.respond_to?(:to_path)
24
- input = input.to_str if input.respond_to?(:to_str)
25
- input
26
- end
27
-
28
- end # class Parser
29
- end # module Language
30
- end # module Gisele
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
- module Gisele::Language
3
- describe Parser do
4
-
5
- fixture_files('tasks/**/*.gis').each do |file|
6
- if file.sub_ext(".ast").exist?
7
-
8
- it "returns the expected ast on #{file}" do
9
- parsed = Parser.parse(file)
10
- expected = Kernel::eval(file.sub_ext(".ast").read, TOPLEVEL_BINDING, file.sub_ext(".ast").to_s)
11
- parsed.should eq(expected)
12
- end
13
-
14
- else
15
-
16
- it "parses #{file} without error" do
17
- parsed = Parser.parse(file)
18
- parsed.should be_a(Array)
19
- parsed.first.should eq(:task)
20
- end
21
-
22
- end
23
-
24
- end
25
-
26
- end
27
- end