sfp 0.3.11 → 0.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/README.md +110 -99
  2. data/VERSION +1 -1
  3. data/lib/sfp/sas_translator.rb +14 -2
  4. metadata +5 -5
data/README.md CHANGED
@@ -1,16 +1,18 @@
1
1
  SFP Language Parser
2
2
  ===================
3
3
  - Author: Herry (herry13@gmail.com)
4
- - [Version](https://github.com/herry13/sfp-ruby/blob/master/VERSION)
5
- - License: [BSD License](https://github.com/herry13/sfp-ruby/blob/master/LICENSE)
4
+ - [Version](../master/VERSION)
5
+ - License: [BSD License](../master/LICENSE)
6
6
 
7
- A Ruby gem that provides a Ruby interface to parse [SFP language](https://github.com/herry13/nuri/wiki/SFP-language), a declarative language to specify a planning task.
7
+ [![Gem Version](https://badge.fury.io/rb/sfp.png)](http://badge.fury.io/rb/sfp)
8
+
9
+ A Ruby script and library for parsing [SFP language](https://github.com/herry13/nuri/wiki/SFP-language), a declarative language to specify a planning task.
8
10
 
9
11
  Click [here](https://github.com/herry13/nuri/wiki/SFP-language), for more details about SFP language.
10
12
 
11
13
  This is a spin-out project from [Nuri](https://github.com/herry13/nuri).
12
14
 
13
- **The planner has been moved to another project [sfplanner](https://github.com/herry13/sfplanner)**.
15
+ **Note: Since version 0.3.0, the planner has been moved to another project: [sfplanner](https://github.com/herry13/sfplanner)**.
14
16
 
15
17
 
16
18
  To install
@@ -22,8 +24,8 @@ To install
22
24
  Requirements
23
25
  ------------
24
26
  - Ruby (>= 1.8.7)
25
- - Rubygems
26
- - antlr3 (<= 1.8.12)
27
+ - Ruby Gems
28
+ - antlr3 (>= 1.9.0)
27
29
  - json
28
30
 
29
31
 
@@ -40,57 +42,62 @@ To use as Ruby library
40
42
  ----------------------
41
43
  - include file **main.sfp** in your codes:
42
44
 
43
- require 'sfp'
44
-
45
+ ```ruby
46
+ require 'sfp'
47
+ ```
48
+
45
49
  - to parse an SFP file: create a Sfp::Parser object, and then pass the content of the file:
46
50
 
47
- # Determine the home directory of your SFP file.
48
- home_dir = File.expand_path(File.dirname("my_file.sfp"))
49
-
50
- # Create Sfp::Parser object
51
- parser = Sfp::Parser.new({:home_dir => "./"})
51
+ ```ruby
52
+ # Determine the home directory of your SFP file.
53
+ home_dir = File.expand_path(File.dirname("my_file.sfp"))
52
54
 
53
- # Parse the file.
54
- parser.parse(File.read("my_file.sfp"))
55
+ # Create Sfp::Parser object
56
+ parser = Sfp::Parser.new({:home_dir => "./"})
55
57
 
56
- # Get the result in Hash data structure
57
- result = parser.root
58
+ # Parse the file.
59
+ parser.parse(File.read("my_file.sfp"))
58
60
 
61
+ # Get the result in Hash data structure
62
+ result = parser.root
63
+ ```
59
64
 
60
65
 
61
66
  Example of Planning Task
62
67
  ------------------------
63
68
  - Create file **types.sfp** to hold required schemas:
64
69
 
65
- schema Service {
66
- running is false
67
- procedure start {
68
- conditions {
69
- this.running is false
70
- }
71
- effects {
72
- this.running is true
73
- }
70
+ ```javascript
71
+ schema Service {
72
+ running is false
73
+ procedure start {
74
+ conditions {
75
+ this.running is false
74
76
  }
75
- procedure stop {
76
- conditions {
77
- this.running is true
78
- }
79
- effects {
80
- this.running is false
81
- }
77
+ effects {
78
+ this.running is true
82
79
  }
83
80
  }
84
- schema Client {
85
- refer isref Service
86
- procedure redirect(s isref Service) {
87
- conditions { }
88
- effects {
89
- this.refer is s
90
- }
81
+ procedure stop {
82
+ conditions {
83
+ this.running is true
84
+ }
85
+ effects {
86
+ this.running is false
91
87
  }
92
88
  }
93
-
89
+ }
90
+ schema Client {
91
+ refer isref Service
92
+ procedure redirect(s isref Service) {
93
+ conditions { }
94
+ effects {
95
+ this.refer is s
96
+ }
97
+ }
98
+ }
99
+ ```
100
+
94
101
  In this file, we have two schemas that model our domain. First, schema
95
102
  **Service** with an attribute **running**, procedure **start** that
96
103
  changes **running**'s value from **false** to **true**, and procedure
@@ -103,29 +110,31 @@ Example of Planning Task
103
110
 
104
111
  - Create file **task.sfp** to hold the task:
105
112
 
106
- include "types.sfp"
113
+ ```javascript
114
+ include "types.sfp"
107
115
 
108
- initial state {
109
- a isa Service {
110
- running is true
111
- }
112
-
113
- b isa Service // with "running" is false
114
-
115
- pc isa Client {
116
- refer is a
117
- }
116
+ initial state {
117
+ a isa Service {
118
+ running is true
118
119
  }
119
120
 
120
- goal constraint {
121
- pc.refer is b
122
- a.running is false
123
- }
121
+ b isa Service // with "running" is false
124
122
 
125
- global constraint {
126
- pc.refer.running is true
123
+ pc isa Client {
124
+ refer is a
127
125
  }
128
-
126
+ }
127
+
128
+ goal constraint {
129
+ pc.refer is b
130
+ a.running is false
131
+ }
132
+
133
+ global constraint {
134
+ pc.refer.running is true
135
+ }
136
+ ```
137
+
129
138
  In this file, we specify a task where in the initial state of our domain,
130
139
  we have two services **a** and **b**, and a client **pc**. **a** is
131
140
  running, **b** is stopped, and **pc** is referring to **a**. We want to
@@ -140,46 +149,48 @@ Example of Planning Task
140
149
 
141
150
  Which will generate a workflow in JSON
142
151
 
143
- {
144
- "type": "sequential",
145
- "workflow": [
146
- {
147
- "name": "$.b.start",
148
- "parameters": {
149
- },
150
- "condition": {
151
- "$.b.running": false
152
- },
153
- "effect": {
154
- "$.b.running": true
155
- }
156
- },
157
- {
158
- "name": "$.pc.redirect",
159
- "parameters": {
160
- "$.s": "$.b"
161
- },
162
- "condition": {
163
- },
164
- "effect": {
165
- "$.pc.refer": "$.b"
166
- }
167
- },
168
- {
169
- "name": "$.a.stop",
170
- "parameters": {
171
- },
172
- "condition": {
173
- "$.a.running": true
174
- },
175
- "effect": {
176
- "$.a.running": false
177
- }
178
- }
179
- ],
180
- "version": "1",
181
- "total": 3
182
- }
152
+ ```javascript
153
+ {
154
+ "type": "sequential",
155
+ "workflow": [
156
+ {
157
+ "name": "$.b.start",
158
+ "parameters": {
159
+ },
160
+ "condition": {
161
+ "$.b.running": false
162
+ },
163
+ "effect": {
164
+ "$.b.running": true
165
+ }
166
+ },
167
+ {
168
+ "name": "$.pc.redirect",
169
+ "parameters": {
170
+ "$.s": "$.b"
171
+ },
172
+ "condition": {
173
+ },
174
+ "effect": {
175
+ "$.pc.refer": "$.b"
176
+ }
177
+ },
178
+ {
179
+ "name": "$.a.stop",
180
+ "parameters": {
181
+ },
182
+ "condition": {
183
+ "$.a.running": true
184
+ },
185
+ "effect": {
186
+ "$.a.running": false
187
+ }
188
+ }
189
+ ],
190
+ "version": "1",
191
+ "total": 3
192
+ }
193
+ ```
183
194
 
184
195
  This workflow is sequential that has 3 procedures. If you executes
185
196
  the workflow in given order, it will achieves the goal state as well
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.11
1
+ 0.3.12
@@ -175,8 +175,20 @@ module Sfp
175
175
  end
176
176
  end
177
177
 
178
- # add Sfp::Unknown and Sfp::Undefined value to all non-final variables
179
- self.add_unknown_undefined_value_to_variables
178
+ @variables.each_value do |var|
179
+ if !var.index(var.init)
180
+ var << var.init
181
+ @types[var.type] << var.init
182
+ end
183
+ if !var.goal.nil? and !var.index(var.goal)
184
+ var << var.goal
185
+ @types[var.type] << var.goal
186
+ end
187
+ end
188
+ @types.each_value { |type| type.uniq! }
189
+
190
+ # add Sfp::Unknown and Sfp::Undefined value to all non-final variables
191
+ self.add_unknown_undefined_value_to_variables
180
192
 
181
193
  @benchmarks['processing procedures'] = Benchmark.measure do
182
194
  ### process all procedures
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.3.11
4
+ version: 0.3.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &20563100 !ruby/object:Gem::Requirement
16
+ requirement: &9424740 !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: *20563100
24
+ version_requirements: *9424740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: antlr3
27
- requirement: &20562560 !ruby/object:Gem::Requirement
27
+ requirement: &9424160 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 1.9.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *20562560
35
+ version_requirements: *9424160
36
36
  description: A Ruby API and script for SFP language parser
37
37
  email: herry13@gmail.com
38
38
  executables: