From 5f8b0934ac54961e398c3ae512f46bc2a874ae1b Mon Sep 17 00:00:00 2001 From: SiriusAshling <53594055+SiriusAshling@users.noreply.github.com> Date: Thu, 24 Nov 2022 16:33:56 +0100 Subject: [PATCH] fix panic when parsing unknown requirements outside of anchors --- wotw_seedgen/src/languages/logic/parser.rs | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/wotw_seedgen/src/languages/logic/parser.rs b/wotw_seedgen/src/languages/logic/parser.rs index 64170a6d..6ebcc01a 100644 --- a/wotw_seedgen/src/languages/logic/parser.rs +++ b/wotw_seedgen/src/languages/logic/parser.rs @@ -636,15 +636,19 @@ fn fill_macros_and_states(contents: &mut Vec, parser: &Parser) -> R } for content in contents { - if let AreaContent::Anchor(anchor) = content { - for refill in &mut anchor.refills { - for requirement in &mut refill.requirements { - fill_group(requirement, ¯os, &states, parser)?; + match content { + AreaContent::Requirement(named_group) | AreaContent::Region(named_group) => + fill_group(&mut named_group.group, ¯os, &states, parser)?, + AreaContent::Anchor(anchor) => { + for refill in &mut anchor.refills { + for requirement in &mut refill.requirements { + fill_group(requirement, ¯os, &states, parser)?; + } } - } - for connection in &mut anchor.connections { - fill_group(&mut connection.requirements, ¯os, &states, parser)?; - } + for connection in &mut anchor.connections { + fill_group(&mut connection.requirements, ¯os, &states, parser)?; + } + }, } } @@ -666,11 +670,9 @@ fn fill_group(group: &mut Group, macros: &[&str], states: &[&str], parser: &Pars } fn fill_requirement(requirement: &mut Requirement, macros: &[&str], states: &[&str], parser: &Parser) -> Result<(), ParseError> { if let RequirementValue::State(identifier) = requirement.value { - requirement.value = if macros.contains(&identifier) { - RequirementValue::Macro(identifier) - } else if states.contains(&identifier) { - RequirementValue::State(identifier) - } else { + if macros.contains(&identifier) { + requirement.value = RequirementValue::Macro(identifier); + } else if !states.contains(&identifier) { return Err(parser.error("unknown requirement", requirement.range.clone())); }; }