From 9106dcb4025ce698db7189b0457a3ff828df675c Mon Sep 17 00:00:00 2001 From: Mau Magnaguagno Date: Sat, 25 May 2024 16:23:44 -0300 Subject: [PATCH] Inline define_effects in JSHOP_Parser --- parsers/JSHOP_Parser.rb | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/parsers/JSHOP_Parser.rb b/parsers/JSHOP_Parser.rb index e654eac..ed8be3b 100644 --- a/parsers/JSHOP_Parser.rb +++ b/parsers/JSHOP_Parser.rb @@ -30,15 +30,6 @@ def scan_tokens(filename) list[0] end - #----------------------------------------------- - # Define effects - #----------------------------------------------- - - def define_effects(name, group) - raise "Error with #{name} effect" unless group.instance_of?(Array) - group.each {|pre,| pre != NOT ? @predicates[pre.freeze] = true : raise("Unexpected not in #{name} effect")} - end - #----------------------------------------------- # Parse operator #----------------------------------------------- @@ -50,14 +41,15 @@ def parse_operator(op) raise "#{name} redefined" if @operators.assoc(name) @operators << [name, op[1], pos = [], neg = [], op[4], op[3]] # Preconditions - raise "Error with #{name} precondition" unless (group = op[2]).instance_of?(Array) - group.each {|pre| + raise "Error with #{name} precondition" unless op[2].instance_of?(Array) + op[2].each {|pre| pre[0] != NOT ? pos << pre : pre.size == 2 ? neg << pre = pre[1] : raise("Error with #{name} negative precondition") @predicates[pre[0].freeze] ||= false } # Effects - define_effects(name, op[3]) - define_effects(name, op[4]) + raise "Error with #{name} effect" unless op[3].instance_of?(Array) and op[4].instance_of?(Array) + op[3].each {|pre,| pre != NOT ? @predicates[pre.freeze] = true : raise("Unexpected not in #{name} effect")} + op[4].each {|pre,| pre != NOT ? @predicates[pre.freeze] = true : raise("Unexpected not in #{name} effect")} end #-----------------------------------------------