Skip to content

Commit 52d1461

Browse files
Now with neat combinator
1 parent 288c189 commit 52d1461

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/meta_lang/partial.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,27 +137,25 @@ where
137137
let mut children_ids = Vec::new();
138138
let mut nodes = Vec::new();
139139
for token in value {
140-
let node = if let Ok(node) = PartialLang::<L>::from_op(token, vec![]) {
141-
// Sibling case
142-
node
143-
} else {
140+
// Sibling case
141+
let node = PartialLang::<L>::from_op(token, vec![]).or_else(|_| {
144142
// Parent case (has to take all the existing children_ids)
145143
loop {
146144
if let Ok(node) = PartialLang::<L>::from_op(token, children_ids.clone()) {
147145
children_ids.clear();
148-
break node;
146+
break Ok(node);
149147
}
150148
nodes.push(PartialLang::Placeholder);
151149
children_ids.push(Id::from(nodes.len() - 1));
152150

153151
if children_ids.len() > L::MAX_ARITY {
154-
return Err(MetaLangError::MaxArity(
152+
break Err(MetaLangError::MaxArity(
155153
token.to_owned(),
156154
children_ids.len(),
157155
));
158156
}
159157
}
160-
};
158+
})?;
161159
nodes.push(node);
162160
children_ids.push(Id::from(nodes.len() - 1));
163161
}

0 commit comments

Comments
 (0)