src/SfpLang.g in sfp-0.1.0 vs src/SfpLang.g in sfp-0.1.1
- old
+ new
@@ -6,12 +6,11 @@
}
@headers {
=begin
Depends:
-- sfplibs.rb
-- ext.rb
+- Sfplib.rb
Features:
- reference
- object namespace
- SET abstract data-type and membership operators (in, not in, add, remove)
@@ -39,13 +38,31 @@
sfp
: { self.init }
NL* include* header*
{ self.expand_classes }
- (state | composite | constraint | goal_constraint)*
+ (mmutation | object_def NL* | state | constraint | goal_constraint | composite)*
;
+
+mmutation
+ : reference equals_op value NL+
+ {
+ path, var = $reference.val.extract
+ parent = @now.at?(path)
+ raise Exception, "#{path} is not a Hash" if not parent.is_a?(Hash)
+ parent[var] = $value.val
+ }
+ | reference equals_op NULL
+ {
+ path, var = $reference.val.extract
+ parent = @now.at?(path)
+ raise Exception, "#{path} is not a Hash" if not parent.is_a?(Hash)
+ parent[var] = self.null_value
+ }
+ ;
+
include
: 'include' include_file NL+
;
include_file
@@ -57,11 +74,11 @@
: class_definition
| procedure
;
state
- : ID ('state')?
+ : ID 'state'
{
@now[$ID.text] = { '_self' => $ID.text,
'_context' => 'state',
'_parent' => @now
}
@@ -89,21 +106,27 @@
class_definition
: 'class' ID
{
@now[$ID.text] = { '_self' => $ID.text,
'_context' => 'class',
- '_parent' => @now
+ '_parent' => @now,
}
@now = @now[$ID.text]
}
(extends_class
{
@now['_extends'] = $extends_class.val
}
)?
('{' NL* ( attribute | procedure )* '}')? NL*
- { self.goto_parent() }
+ {
+ if not @now.has_key?('_extends')
+ @now['_extends'] = '$.Object'
+ @now['_super'] = ['$.Object']
+ end
+ self.goto_parent()
+ }
;
extends_class returns [val]
: 'extends' path
{
@@ -161,15 +184,14 @@
@now.delete('_is_array')
obj = self.goto_parent()
total = $NUMBER.to_s.to_i
@arrays[obj.ref] = total
for i in 0..(total-1)
- id = obj['_self'] + "[#{i}]"
+ id = obj['_self'] + '[' + i.to_s + ']'
@now[id] = deep_clone(obj)
@now[id]['_self'] = id
@now[id]['_classes'] = obj['_classes']
- #puts 'is_array: ' + $ID.text + '[' + i.to_s + ']'
end
@now.delete(obj['_self'])
else
self.goto_parent()
end
@@ -210,11 +232,11 @@
@now[$ID.text] = { '_self' => $ID.text,
'_context' => 'operator',
'_parent' => @now,
'_cost' => 1,
'_condition' => { '_context' => 'constraint' },
- '_effect' => { '_context' => 'mutation' }
+ '_effect' => { '_context' => 'effect' }
}
@now = @now[$ID.text]
}
( 'cost' equals_op NUMBER NL+
{ @now['_cost'] = $NUMBER.text.to_i }
@@ -229,11 +251,11 @@
: ID equals_op reference NL+
{ @now[$ID.text] = $reference.val }
;
op_conditions
- : 'conditions' '{' NL*
+ : ('conditions' | 'condition') '{' NL*
{
@now['_condition']['_parent'] = @now
@now = @now['_condition']
}
op_statement*
@@ -263,11 +285,11 @@
@now[$ID.text] = { '_self' => $ID.text,
'_context' => 'procedure',
'_parent' => @now,
'_cost' => 1,
'_condition' => { '_context' => 'constraint', '_type' => 'and' },
- '_effect' => { '_context' => 'mutation', '_type' => 'and' }
+ '_effect' => { '_context' => 'effect', '_type' => 'and' }
}
@now = @now[$ID.text]
}
parameters? '{' NL*
( 'cost' equals_op NUMBER
@@ -300,30 +322,34 @@
}
}
;
conditions
- : 'conditions'
+ : ('conditions' | 'condition')
{
@now['_condition']['_parent'] = @now
@now = @now['_condition']
}
'{' NL* constraint_body '}' NL+
{ self.goto_parent() }
;
effects
- : 'effects'
+ : ('effects' | 'effect')
{
@now['_effect']['_parent'] = @now
@now = @now['_effect']
+ @in_effects = true
}
'{' NL*
- mutation_body
+ effect_body
'}' NL+
- { self.goto_parent() }
+ {
+ self.goto_parent()
+ @in_effects = false
+ }
;
goal_constraint
: 'goal' 'constraint'? NL*
{
@@ -709,14 +735,14 @@
}
'{' NL+ constraint_body '}'
{ self.goto_parent() }
;
-mutation_body
+effect_body
: (
- ( mutation_statement
- { @now[$mutation_statement.key] = $mutation_statement.val }
+ ( mutation
+ { @now[$mutation.key] = $mutation.val }
| mutation_iterator
)
NL+)*
;
@@ -729,17 +755,17 @@
'_self' => id,
'_variable' => $ID.text
}
@now = @now[id]
}
- (mutation_statement
- { @now[$mutation_statement.key] = $mutation_statement.val }
+ (mutation
+ { @now[$mutation.key] = $mutation.val }
NL+)*
'}'
{ self.goto_parent() }
;
-mutation_statement returns [key, val]
+mutation returns [key, val]
: reference equals_op value
{
$key = $reference.val
$val = { '_context' => 'mutation',
'_type' => 'equals',