sfp 0.4.4 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,10 +40,26 @@ sfp
40
40
  : { self.init }
41
41
  NL*
42
42
  ( (object_def | abstract_object | state | constraint_def | class_def | procedure) NL*
43
- | include )*
43
+ | include
44
+ | placement
45
+ )*
44
46
  { self.finalize }
45
47
  ;
46
48
 
49
+ placement
50
+ : '!' path
51
+ {
52
+ ref = "$.#{$path.text}"
53
+ parent, id = ref.pop_ref
54
+ @now = @root.at?(parent)
55
+ fail "parent #{parent} is not exist" if not @now.is_a?(Hash)
56
+ }
57
+ assignment[id]
58
+ {
59
+ @now = @root
60
+ }
61
+ ;
62
+
47
63
  constraint_def
48
64
  : goal_constraint
49
65
  | global_constraint
@@ -112,9 +128,10 @@ attribute
112
128
  @is_final = false
113
129
  @now['_finals'] = [] if !@now.has_key? '_finals'
114
130
  }
115
- ('final' { @is_final = true })? attribute_stmt
131
+ ('final' { @is_final = true })?
132
+ ID assignment[$ID.text]
116
133
  {
117
- @now['_finals'] << $attribute_stmt.id if @is_final and !$attribute_stmt.id.nil?
134
+ @now['_finals'] << $ID.text if @is_final
118
135
  }
119
136
  | {
120
137
  @is_final = false
@@ -123,56 +140,51 @@ attribute
123
140
  ('final' { @is_final = true })? object_def NL+
124
141
  ;
125
142
 
126
- attribute_stmt returns [id]
127
- : ID equals_op value NL+
143
+ assignment[id]
144
+ : equals_op value NL+
128
145
  {
129
- if @now.has_key?($ID.text) and @now[$ID.text].is_a?(Hash) and
130
- @now[$ID.text].isset and $value.type == 'Set'
131
- $value.val.each { |v| @now[$ID.text]['_values'].push(v) }
146
+ if @now.has_key?($id) and @now[$id].is_a?(Hash) and
147
+ @now[$id].isset and $value.type == 'Set'
148
+ $value.val.each { |v| @now[$id]['_values'].push(v) }
132
149
  else
133
- @now[$ID.text] = $value.val
150
+ @now[$id] = $value.val
134
151
  end
135
- $id = $ID.text
136
152
  }
137
- | ID reference_type NL+
153
+ | reference_type NL+
138
154
  {
139
- @now[$ID.text] = $reference_type.val
140
- $id = $ID.text
155
+ @now[$id] = $reference_type.val
141
156
  }
142
- | ID set_type NL+
157
+ | set_type NL+
143
158
  {
144
- @now[$ID.text] = $set_type.val
145
- $id = $ID.text
159
+ @now[$id] = $set_type.val
146
160
  }
147
- | ID probability_op set_value NL+
161
+ | probability_op set_value NL+
148
162
  {
149
163
  @conformant = true
150
- @now[$ID.text] = { '_self' => $ID.text,
164
+ @now[$id] = { '_self' => $id,
151
165
  '_context' => 'either',
152
166
  '_parent' => @now,
153
167
  '_values' => $set_value.val
154
168
  }
155
- $id = $ID.text
156
169
  }
157
- | ID ':' path NL+
170
+ | ':' path NL+
158
171
  {
159
172
  case $path.text
160
173
  when 'String'
161
- @now[$ID.text] = { '_context' => 'any_value',
174
+ @now[$id] = { '_context' => 'any_value',
162
175
  '_isa' => '$.String'
163
176
  }
164
177
  when 'Bool'
165
- @now[$ID.text] = { '_context' => 'any_value',
178
+ @now[$id] = { '_context' => 'any_value',
166
179
  '_isa' => '$.Boolean'
167
180
  }
168
181
  when 'Int'
169
- @now[$ID.text] = { '_context' => 'any_value',
182
+ @now[$id] = { '_context' => 'any_value',
170
183
  '_isa' => '$.Number'
171
184
  }
172
185
  else
173
186
  raise Exception, "Use isa/isref for any non-primitive type (#{$path.text})."
174
187
  end
175
- $id = $ID.text
176
188
  }
177
189
  ;
178
190
 
@@ -874,11 +886,11 @@ mutation returns [key, val]
874
886
  ;
875
887
 
876
888
  set_value returns [val]
877
- : '('
889
+ : ('('|'[')
878
890
  { @set = Array.new }
879
891
  (set_item (',' NL* set_item)*)?
880
892
  { $val = @set }
881
- ')'
893
+ (')'|']')
882
894
  ;
883
895
 
884
896
  set_item
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sfp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Herry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-29 00:00:00.000000000 Z
11
+ date: 2014-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: antlr3