Skip to content

Commit

Permalink
Use filter_map
Browse files Browse the repository at this point in the history
  • Loading branch information
Masynchin committed Jun 21, 2023
1 parent 9b7f4a5 commit b328dc6
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,10 @@ pub fn parse(input: &str) -> Result<Module, Error<Rule>> {
}

fn parse_module(root: Pair<Rule>) -> Module {
let mut stmts: Vec<Stmt> = Vec::new();
// The Pair.into_inner method returns an iterator over the rules
// inside of the given rule. In this case, it iterates over statements
// extracted by `statement+` part of the `module` rule.
for subpair in root.into_inner() {
if let Some(stmt) = parse_statement(subpair) {
stmts.push(stmt);
}
}
let stmts: Vec<Stmt> = root.into_inner().filter_map(parse_statement).collect();
Module { stmts }
}

Expand Down

0 comments on commit b328dc6

Please sign in to comment.