Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sozysozbot committed Jul 26, 2020
1 parent 7ff47e1 commit 468f209
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions src/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,21 @@ struct IfStmtAfterZhe3 {
elsecase: Vec<Statement>,
}

impl IfStmtAfterZhe3 {
pub fn to_stmt_with_cond(self, cond: IfCond) -> Statement {
let IfStmtAfterZhe3 {
ifstmts,
elseifcases,
elsecase,
} = self;
Statement::If {
ifcase: (cond, ifstmts),
elseifcases,
elsecase,
}
}
}

fn parse_if_statement_after_zhe3(mut iter: &mut LexIter<'_>) -> Result<IfStmtAfterZhe3, Error> {
// FIXME:
// currently: statement+ ('若非' statement+)? FOR_IF_END ;
Expand Down Expand Up @@ -734,29 +749,10 @@ fn parse_statement(mut iter: &mut LexIter<'_>) -> Result<Statement, Error> {
lex::Lex::Xian2 => parse_arraycat_after_xian2(&mut iter),
lex::Lex::Chong1 => parse_arraypush_after_chong1(&mut iter),
lex::Lex::Ruo4Qi2Bu4Ran2Zhe3 => {
let IfStmtAfterZhe3 {
ifstmts,
elseifcases,
elsecase,
} = parse_if_statement_after_zhe3(&mut iter)?;
Ok(Statement::If {
ifcase: (IfCond::NotQi2, ifstmts),
elseifcases,
elsecase,
})
}
lex::Lex::Ruo4Qi2Ran2Zhe3 => {
let IfStmtAfterZhe3 {
ifstmts,
elseifcases,
elsecase,
} = parse_if_statement_after_zhe3(&mut iter)?;
Ok(Statement::If {
ifcase: (IfCond::Unary(UnaryIfExpr::Simple(DataOrQi2::Qi2)), ifstmts),
elseifcases,
elsecase,
})
Ok(parse_if_statement_after_zhe3(&mut iter)?.to_stmt_with_cond(IfCond::NotQi2))
}
lex::Lex::Ruo4Qi2Ran2Zhe3 => Ok(parse_if_statement_after_zhe3(&mut iter)?
.to_stmt_with_cond(IfCond::Unary(UnaryIfExpr::Simple(DataOrQi2::Qi2)))),
lex::Lex::Ruo4 => {
// if_statement : '若' if_expression '者' statement+ ('或若' if_expression '者' statement+)* ('若非' statement+)? FOR_IF_END ;
let ifexpr = parse_ifexpression_plus_zhe3(&mut iter)?;
Expand Down

0 comments on commit 468f209

Please sign in to comment.