sfp 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,11 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'sfp'
3
- s.version = '0.1.0'
3
+ s.version = '0.1.1'
4
4
  s.date = '2013-04-20'
5
5
  s.summary = 'SFP Parser and Planner'
6
- s.description = 'A Ruby gem that provides a Ruby interface to parse SFP language. ' +
7
- 'It also provides a Ruby interface for a solver to generate a workflow ' +
8
- 'for a planning task written in SFP language.'
6
+ s.description = 'A Ruby gem that provides a Ruby API to SFP language parser and ' +
7
+ 'SFP planner. It also provides a planner sript to solve a planning problem ' +
8
+ 'written in SFP language.'
9
9
  s.authors = ['Herry']
10
10
  s.email = 'herry13@gmail.com'
11
11
 
@@ -8,8 +8,7 @@ options {
8
8
  @headers {
9
9
  =begin
10
10
  Depends:
11
- - sfplibs.rb
12
- - ext.rb
11
+ - Sfplib.rb
13
12
 
14
13
  Features:
15
14
  - reference
@@ -41,7 +40,25 @@ sfp
41
40
  : { self.init }
42
41
  NL* include* header*
43
42
  { self.expand_classes }
44
- (state | composite | constraint | goal_constraint)*
43
+ (mmutation | object_def NL* | state | constraint | goal_constraint | composite)*
44
+ ;
45
+
46
+
47
+ mmutation
48
+ : reference equals_op value NL+
49
+ {
50
+ path, var = $reference.val.extract
51
+ parent = @now.at?(path)
52
+ raise Exception, "#{path} is not a Hash" if not parent.is_a?(Hash)
53
+ parent[var] = $value.val
54
+ }
55
+ | reference equals_op NULL
56
+ {
57
+ path, var = $reference.val.extract
58
+ parent = @now.at?(path)
59
+ raise Exception, "#{path} is not a Hash" if not parent.is_a?(Hash)
60
+ parent[var] = self.null_value
61
+ }
45
62
  ;
46
63
 
47
64
  include
@@ -59,7 +76,7 @@ header
59
76
  ;
60
77
 
61
78
  state
62
- : ID ('state')?
79
+ : ID 'state'
63
80
  {
64
81
  @now[$ID.text] = { '_self' => $ID.text,
65
82
  '_context' => 'state',
@@ -91,7 +108,7 @@ class_definition
91
108
  {
92
109
  @now[$ID.text] = { '_self' => $ID.text,
93
110
  '_context' => 'class',
94
- '_parent' => @now
111
+ '_parent' => @now,
95
112
  }
96
113
  @now = @now[$ID.text]
97
114
  }
@@ -101,7 +118,13 @@ class_definition
101
118
  }
102
119
  )?
103
120
  ('{' NL* ( attribute | procedure )* '}')? NL*
104
- { self.goto_parent() }
121
+ {
122
+ if not @now.has_key?('_extends')
123
+ @now['_extends'] = '$.Object'
124
+ @now['_super'] = ['$.Object']
125
+ end
126
+ self.goto_parent()
127
+ }
105
128
  ;
106
129
 
107
130
  extends_class returns [val]
@@ -163,11 +186,10 @@ object_def
163
186
  total = $NUMBER.to_s.to_i
164
187
  @arrays[obj.ref] = total
165
188
  for i in 0..(total-1)
166
- id = obj['_self'] + "[#{i}]"
189
+ id = obj['_self'] + '[' + i.to_s + ']'
167
190
  @now[id] = deep_clone(obj)
168
191
  @now[id]['_self'] = id
169
192
  @now[id]['_classes'] = obj['_classes']
170
- #puts 'is_array: ' + $ID.text + '[' + i.to_s + ']'
171
193
  end
172
194
  @now.delete(obj['_self'])
173
195
  else
@@ -212,7 +234,7 @@ operator
212
234
  '_parent' => @now,
213
235
  '_cost' => 1,
214
236
  '_condition' => { '_context' => 'constraint' },
215
- '_effect' => { '_context' => 'mutation' }
237
+ '_effect' => { '_context' => 'effect' }
216
238
  }
217
239
  @now = @now[$ID.text]
218
240
  }
@@ -231,7 +253,7 @@ op_param
231
253
  ;
232
254
 
233
255
  op_conditions
234
- : 'conditions' '{' NL*
256
+ : ('conditions' | 'condition') '{' NL*
235
257
  {
236
258
  @now['_condition']['_parent'] = @now
237
259
  @now = @now['_condition']
@@ -265,7 +287,7 @@ procedure
265
287
  '_parent' => @now,
266
288
  '_cost' => 1,
267
289
  '_condition' => { '_context' => 'constraint', '_type' => 'and' },
268
- '_effect' => { '_context' => 'mutation', '_type' => 'and' }
290
+ '_effect' => { '_context' => 'effect', '_type' => 'and' }
269
291
  }
270
292
  @now = @now[$ID.text]
271
293
  }
@@ -302,7 +324,7 @@ parameter
302
324
  ;
303
325
 
304
326
  conditions
305
- : 'conditions'
327
+ : ('conditions' | 'condition')
306
328
  {
307
329
  @now['_condition']['_parent'] = @now
308
330
  @now = @now['_condition']
@@ -313,15 +335,19 @@ conditions
313
335
  ;
314
336
 
315
337
  effects
316
- : 'effects'
338
+ : ('effects' | 'effect')
317
339
  {
318
340
  @now['_effect']['_parent'] = @now
319
341
  @now = @now['_effect']
342
+ @in_effects = true
320
343
  }
321
344
  '{' NL*
322
- mutation_body
345
+ effect_body
323
346
  '}' NL+
324
- { self.goto_parent() }
347
+ {
348
+ self.goto_parent()
349
+ @in_effects = false
350
+ }
325
351
  ;
326
352
 
327
353
  goal_constraint
@@ -711,10 +737,10 @@ conditional_constraint_then_part
711
737
  { self.goto_parent() }
712
738
  ;
713
739
 
714
- mutation_body
740
+ effect_body
715
741
  : (
716
- ( mutation_statement
717
- { @now[$mutation_statement.key] = $mutation_statement.val }
742
+ ( mutation
743
+ { @now[$mutation.key] = $mutation.val }
718
744
  | mutation_iterator
719
745
  )
720
746
  NL+)*
@@ -731,14 +757,14 @@ mutation_iterator
731
757
  }
732
758
  @now = @now[id]
733
759
  }
734
- (mutation_statement
735
- { @now[$mutation_statement.key] = $mutation_statement.val }
760
+ (mutation
761
+ { @now[$mutation.key] = $mutation.val }
736
762
  NL+)*
737
763
  '}'
738
764
  { self.goto_parent() }
739
765
  ;
740
766
 
741
- mutation_statement returns [key, val]
767
+ mutation returns [key, val]
742
768
  : reference equals_op value
743
769
  {
744
770
  $key = $reference.val
@@ -3,5 +3,5 @@
3
3
  antlr4ruby SfpLang.g
4
4
 
5
5
  rm -f SfpLang.tokens
6
- mv -f SfpLangLexer.rb ../lib
7
- mv -f SfpLangParser.rb ../lib
6
+ mv -f SfpLangLexer.rb ../lib/sfp
7
+ mv -f SfpLangParser.rb ../lib/sfp
@@ -0,0 +1,14 @@
1
+
2
+
3
+ b
4
+
5
+ a {
6
+ x is true
7
+ refer is b
8
+ }
9
+
10
+ a.x is false
11
+
12
+ a.refer is null
13
+
14
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sfp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-04-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &6400440 !ruby/object:Gem::Requirement
16
+ requirement: &8708440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.7.5
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *6400440
24
+ version_requirements: *8708440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: antlr3
27
- requirement: &6399940 !ruby/object:Gem::Requirement
27
+ requirement: &8707420 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,9 @@ dependencies:
32
32
  version: 1.8.12
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *6399940
36
- description: A Ruby gem that provides a Ruby interface to parse SFP language. It also
37
- provides a Ruby interface for a solver to generate a workflow for a planning task
38
- written in SFP language.
35
+ version_requirements: *8707420
36
+ description: A Ruby gem that provides a Ruby API to SFP language parser and SFP planner.
37
+ It also provides a planner sript to solve a planning problem written in SFP language.
39
38
  email: herry13@gmail.com
40
39
  executables:
41
40
  - sfp
@@ -67,6 +66,7 @@ files:
67
66
  - test/cloud1.sfp
68
67
  - test/cloud2.sfp
69
68
  - test/cloud3.sfp
69
+ - test/s.sfp
70
70
  - test/service-classes.sfp
71
71
  - test/service1.sfp
72
72
  - test/service3.sfp
@@ -107,6 +107,7 @@ test_files:
107
107
  - test/cloud1.sfp
108
108
  - test/cloud2.sfp
109
109
  - test/cloud3.sfp
110
+ - test/s.sfp
110
111
  - test/service-classes.sfp
111
112
  - test/service1.sfp
112
113
  - test/service3.sfp