Skip to content

Commit

Permalink
Merge pull request #2 from Masynchin/master
Browse files Browse the repository at this point in the history
Use filter_map
  • Loading branch information
orsinium authored Jun 21, 2023
2 parents 9b7f4a5 + b328dc6 commit 1297aa2
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 1297aa2

Please sign in to comment.