From 415f776bb95d5284a7a5ec87953b53ebd64950d2 Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Thu, 8 Oct 2020 15:44:20 +0100 Subject: [PATCH] union child is a single union element --- src/parser.rs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index a7a5d70..2ebdfbe 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -46,29 +46,26 @@ fn parse_child_name(matcher_rule: pest::iterators::Pair) -> String { } fn parse_union_indices(matcher_rule: pest::iterators::Pair) -> Vec { - let mut res = Vec::new(); - - for r in matcher_rule.into_inner() { - match r.as_rule() { - Rule::unionChild => res.append(&mut parse_union_child(r)), - Rule::unionArrayIndex => res.push(parse_union_array_index(r)), - _ => panic!("invalid parse tree {:?}", r), - } - } - res -} - -fn parse_union_child(matcher_rule: pest::iterators::Pair) -> Vec { matcher_rule .into_inner() .map(|r| match r.as_rule() { - Rule::doubleInner => UnionElement::Name(unescape(r.as_str())), - Rule::singleInner => UnionElement::Name(unescape_single(r.as_str())), + Rule::unionChild => parse_union_child(r), + Rule::unionArrayIndex => parse_union_array_index(r), _ => panic!("invalid parse tree {:?}", r), }) .collect() } +fn parse_union_child(matcher_rule: pest::iterators::Pair) -> UnionElement { + let r = matcher_rule.into_inner().next().unwrap(); + + UnionElement::Name(match r.as_rule() { + Rule::doubleInner => unescape(r.as_str()), + Rule::singleInner => unescape_single(r.as_str()), + _ => panic!("invalid parse tree {:?}", r), + }) +} + fn parse_union_array_index(matcher_rule: pest::iterators::Pair) -> UnionElement { let i = matcher_rule.as_str().parse().unwrap(); UnionElement::Index(i)