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.
- data/README.md +110 -99
- data/VERSION +1 -1
- data/lib/sfp/sas_translator.rb +14 -2
- 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](
|
5
|
-
- License: [BSD License](
|
4
|
+
- [Version](../master/VERSION)
|
5
|
+
- License: [BSD License](../master/LICENSE)
|
6
6
|
|
7
|
-
|
7
|
+
[](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
|
-
**
|
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
|
-
-
|
26
|
-
- antlr3 (
|
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
|
-
|
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
|
-
|
48
|
-
|
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
|
-
|
54
|
-
|
55
|
+
# Create Sfp::Parser object
|
56
|
+
parser = Sfp::Parser.new({:home_dir => "./"})
|
55
57
|
|
56
|
-
|
57
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
76
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
-
|
113
|
+
```javascript
|
114
|
+
include "types.sfp"
|
107
115
|
|
108
|
-
|
109
|
-
|
110
|
-
|
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
|
-
|
121
|
-
pc.refer is b
|
122
|
-
a.running is false
|
123
|
-
}
|
121
|
+
b isa Service // with "running" is false
|
124
122
|
|
125
|
-
|
126
|
-
|
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
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
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.
|
1
|
+
0.3.12
|
data/lib/sfp/sas_translator.rb
CHANGED
@@ -175,8 +175,20 @@ module Sfp
|
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
|
-
|
179
|
-
|
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.
|
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: &
|
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: *
|
24
|
+
version_requirements: *9424740
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: antlr3
|
27
|
-
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: *
|
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:
|