src/SfpLang.g in sfp-0.3.10 vs src/SfpLang.g in sfp-0.3.11
- old
+ new
@@ -35,55 +35,32 @@
@members {
include Sfp::SfpLangHelper
}
sfp
- : { self.init }
+ : { self.init }
NL*
- //{ self.expand_classes }
- ( (object_def | state | constraints) NL* | include | class_def | procedure )*
- // | goal_constraint | composite)*
+ ( (object_def | abstract_object | state | constraint_def | class_def | procedure) NL*
+ | include )*
+ { self.finalize }
;
-constraints
+constraint_def
: goal_constraint
| global_constraint
| sometime_constraint
;
-/*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
: STRING
{ self.process_file($STRING.text[1,$STRING.text.length-2]) }
;
-header
- : class_def
- | procedure
- ;
-
state
: ID 'state' NL*
{
@now[$ID.text] = { '_self' => $ID.text,
'_context' => 'state',
@@ -95,23 +72,10 @@
attribute*
'}'
{ self.goto_parent(true) }
;
-composite
- : 'composite' ID
- {
- @now[$ID.text] = { '_self' => $ID.text,
- '_context' => 'composite',
- '_parent' => @now
- }
- @now = @now[$ID.text]
- }
- '{' NL* ( attribute | constraint )* '}' NL*
- { self.goto_parent(true) }
- ;
-
class_def
: ('class'|'schema') ID
{
@now[$ID.text] = { '_self' => $ID.text,
'_context' => 'class',
@@ -122,11 +86,11 @@
(extends_class
{
@now['_extends'] = $extends_class.val
}
)?
- ('{' NL* ( attribute | procedure )* '}')? NL*
+ ('{' NL* ( attribute | procedure NL* )* '}')?
{
if not @now.has_key?('_extends')
@now['_extends'] = '$.Object'
@now['_super'] = ['$.Object']
end
@@ -219,13 +183,18 @@
object_schemata
: ',' object_schema
;
-object_def
+abstract_object
+ : 'abstract' object_def
+ { @root[$object_def.id]['_context'] = 'abstract' }
+ ;
+
+object_def returns [id]
: { @use_template = false }
- ID
+ ID { $id = $ID.text }
('extends' path
{
template = @root.at?($path.text)
raise Exception, "Object template #{$path.text} is not found!" if
template.is_a?(Sfp::Unknown) or template.is_a?(Sfp::Undefined)
@@ -347,10 +316,10 @@
parameters? '{' NL*
( 'cost' equals_op NUMBER
{ @now['_cost'] = $NUMBER.text.to_i }
NL+
)?
- conditions? effects '}' NL+
+ conditions? effects '}'
{ self.goto_parent() }
;
parameters
: '(' parameter (',' NL* parameter)* ')'