src/SfpLang.g in sfp-0.3.5 vs src/SfpLang.g in sfp-0.3.6

- old
+ new

@@ -36,15 +36,21 @@ include Sfp::SfpLangHelper } sfp : { self.init } - NL* include* header* - { self.expand_classes } - (object_def NL* | state | constraint | goal_constraint | composite)* + NL* + //{ self.expand_classes } + ( (object_def | state | constraints) NL* | include | class_def | procedure )* + // | goal_constraint | composite)* ; +constraints + : goal_constraint + | global_constraint + | sometime_constraint + ; /*mmutation : reference equals_op value NL+ { path, var = $reference.val.extract @@ -70,26 +76,26 @@ : STRING { self.process_file($STRING.text[1,$STRING.text.length-2]) } ; header - : class_definition + : class_def | procedure ; state - : ID 'state' + : ID 'state' NL* { @now[$ID.text] = { '_self' => $ID.text, '_context' => 'state', '_parent' => @now } @now = @now[$ID.text] } '{' NL* attribute* - '}' NL* + '}' { self.goto_parent(true) } ; composite : 'composite' ID @@ -102,11 +108,11 @@ } '{' NL* ( attribute | constraint )* '}' NL* { self.goto_parent(true) } ; -class_definition +class_def : ('class'|'schema') ID { @now[$ID.text] = { '_self' => $ID.text, '_context' => 'class', '_parent' => @now, @@ -122,10 +128,11 @@ { if not @now.has_key?('_extends') @now['_extends'] = '$.Object' @now['_super'] = ['$.Object'] end + expand_class(@now) self.goto_parent() } ; extends_class returns [val] @@ -261,11 +268,11 @@ end } ; object_body - : '{' NL* ( object_attribute | state_dependency | operator )* '}' + : '{' NL* ( object_attribute | procedure )* '}' ; object_attribute : attribute | ID equals_op NULL NL+ @@ -288,31 +295,10 @@ ( value | NULL ) ; -operator - : 'operator' ID '{' NL* - { - @now[$ID.text] = { '_self' => $ID.text, - '_context' => 'operator', - '_parent' => @now, - '_cost' => 1, - '_condition' => { '_context' => 'constraint' }, - '_effect' => { '_context' => 'effect' } - } - @now = @now[$ID.text] - } - ( 'cost' equals_op NUMBER NL+ - { @now['_cost'] = $NUMBER.text.to_i } - )? - /*op_param**/ - op_conditions? op_effects - '}' NL+ - { self.goto_parent() } - ; - op_param : ID equals_op reference NL+ { @now[$ID.text] = $reference.val } ; @@ -367,11 +353,17 @@ parameters : '(' parameter (',' NL* parameter)* ')' ; parameter - : ID reference_type + : ID ':' path + { + @now[$ID.text] = { '_context' => 'any_value', + '_isa' => self.to_ref($path.text) + } + } + | ID reference_type { @now[$ID.text] = $reference_type.val } | ID 'areall' path { @now[$ID.text] = { '_context' => 'all', '_isa' => self.to_ref($path.text), @@ -422,14 +414,35 @@ '_type' => 'and', '_parent' => @now } @now = @now['goal'] } - '{' NL* goal_body* '}' NL+ + '{' NL* goal_body* '}' { self.goto_parent() } ; +global_constraint + : ('global'|'always') 'constraint'? NL* + { + @now['global'] = self.create_constraint('global', 'and') if !@now.has_key?('global') + @now = @now['global'] + } + '{' NL* constraint_body '}' + { self.goto_parent() } + ; + +sometime_constraint + : 'sometime' 'constraint'? NL* + { + @now['sometime'] = self.create_constraint('sometime', 'or') if !@now.has_key?('sometime') + @now = @now['sometime'] + } + '{' NL* constraint_body '}' + { self.goto_parent() } + ; + + goal_body : ( ( constraint_statement { @now[$constraint_statement.key] = $constraint_statement.val @@ -437,15 +450,15 @@ | constraint_namespace | constraint_iterator | constraint_class_quantification ) NL+) - | 'always' NL* + | ('always'|'global') NL* { - @now['always'] = self.create_constraint('always', 'and') if - not @now.has_key?('always') - @now = @now['always'] + @now['global'] = self.create_constraint('global', 'and') if + not @now.has_key?('global') + @now = @now['global'] } '{' NL* constraint_body '}' NL+ { self.goto_parent() } | 'sometime' NL* { @@ -518,16 +531,16 @@ nested_constraint : '{' NL* constraint_body '}' ; constraint - : ID 'constraint' + : 'constraint' ID { @now[$ID.text] = self.create_constraint($ID.text, 'and') @now = @now[$ID.text] } - '{' NL* constraint_body '}' NL+ + '{' NL* constraint_body '}' { self.goto_parent() } ; constraint_body : ( @@ -1013,11 +1026,11 @@ | 'on' | 'yes' | 'no' ; -ID : ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'-')* +ID : ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9'|'_')* ; NUMBER : '-'?('0'..'9')+ ; @@ -1037,10 +1050,10 @@ MULTILINE_STRING : 'r"' ( options {greedy=false;} : .)* '"' ; -NL : '\r'? '\n' +NL : ('\r'? '\n'|';') ; WS : ( ' ' | '\t' ) {$channel=HIDDEN;} ;