Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit 25d82b7

Browse files
authored
Merge pull request #21 from glyn/union-child-arity
union child is a single union element
2 parents 5f537a2 + 415f776 commit 25d82b7

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/parser.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,26 @@ fn parse_child_name(matcher_rule: pest::iterators::Pair<Rule>) -> String {
4646
}
4747

4848
fn parse_union_indices(matcher_rule: pest::iterators::Pair<Rule>) -> Vec<UnionElement> {
49-
let mut res = Vec::new();
50-
51-
for r in matcher_rule.into_inner() {
52-
match r.as_rule() {
53-
Rule::unionChild => res.append(&mut parse_union_child(r)),
54-
Rule::unionArrayIndex => res.push(parse_union_array_index(r)),
55-
_ => panic!("invalid parse tree {:?}", r),
56-
}
57-
}
58-
res
59-
}
60-
61-
fn parse_union_child(matcher_rule: pest::iterators::Pair<Rule>) -> Vec<UnionElement> {
6249
matcher_rule
6350
.into_inner()
6451
.map(|r| match r.as_rule() {
65-
Rule::doubleInner => UnionElement::Name(unescape(r.as_str())),
66-
Rule::singleInner => UnionElement::Name(unescape_single(r.as_str())),
52+
Rule::unionChild => parse_union_child(r),
53+
Rule::unionArrayIndex => parse_union_array_index(r),
6754
_ => panic!("invalid parse tree {:?}", r),
6855
})
6956
.collect()
7057
}
7158

59+
fn parse_union_child(matcher_rule: pest::iterators::Pair<Rule>) -> UnionElement {
60+
let r = matcher_rule.into_inner().next().unwrap();
61+
62+
UnionElement::Name(match r.as_rule() {
63+
Rule::doubleInner => unescape(r.as_str()),
64+
Rule::singleInner => unescape_single(r.as_str()),
65+
_ => panic!("invalid parse tree {:?}", r),
66+
})
67+
}
68+
7269
fn parse_union_array_index(matcher_rule: pest::iterators::Pair<Rule>) -> UnionElement {
7370
let i = matcher_rule.as_str().parse().unwrap();
7471
UnionElement::Index(i)

0 commit comments

Comments
 (0)