Skip to content

Commit

Permalink
Inline define_effects in JSHOP_Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Maumagnaguagno committed May 25, 2024
1 parent c0e8fa6 commit 9106dcb
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions parsers/JSHOP_Parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#-----------------------------------------------
Expand All @@ -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

#-----------------------------------------------
Expand Down

0 comments on commit 9106dcb

Please sign in to comment.