Skip to content

Commit d48a4a5

Browse files
Now with a nice loop!
1 parent 01884fc commit d48a4a5

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

src/meta_lang/partial.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,27 +137,30 @@ where
137137
let mut children_ids = Vec::new();
138138
let mut nodes = Vec::new();
139139
for token in value {
140-
// Sibling case
141-
if let Ok(node) = PartialLang::<L>::from_op(token, vec![]) {
142-
nodes.push(node);
143-
children_ids.push(Id::from(nodes.len() - 1));
144-
continue;
145-
}
146-
// Parent case (has to take all the existing children_ids)
147-
for n in children_ids.len().. {
148-
if let Ok(node) = PartialLang::<L>::from_op(token, children_ids.clone()) {
149-
nodes.push(node);
150-
children_ids.clear();
140+
let node = if let Ok(node) = PartialLang::<L>::from_op(token, vec![]) {
141+
// Sibling case
142+
node
143+
} else {
144+
// Parent case (has to take all the existing children_ids)
145+
loop {
146+
if let Ok(node) = PartialLang::<L>::from_op(token, children_ids.clone()) {
147+
children_ids.clear();
148+
break node;
149+
}
150+
nodes.push(PartialLang::Placeholder);
151151
children_ids.push(Id::from(nodes.len() - 1));
152-
break;
153-
}
154-
nodes.push(PartialLang::Placeholder);
155-
children_ids.push(Id::from(nodes.len() - 1));
156152

157-
if n > L::MAX_ARITY {
158-
return Err(MetaLangError::MaxArity(token.to_owned(), n));
153+
if children_ids.len() > L::MAX_ARITY {
154+
return Err(MetaLangError::MaxArity(
155+
token.to_owned(),
156+
children_ids.len(),
157+
));
158+
}
159159
}
160-
}
160+
};
161+
nodes.push(node);
162+
children_ids.push(Id::from(nodes.len() - 1));
163+
161164
// }
162165
}
163166
Ok(nodes)

0 commit comments

Comments
 (0)