def if_stmt(): def process(parsed): (((((_, cond), _), true_stmt), else_parsed), _) = parsed if else_parsed: (_, else_stmt) = else_parsed else: else_stmt = None return ast.IfStmtAST(cond, true_stmt, else_stmt) return (parse_keyword('if') + b_expr() + parse_keyword('then') + cb.Lazy(stmt_list) + cb.Option(parse_keyword('else') + cb.Lazy(stmt_list)) + parse_keyword('end') ^ process)
def while_stmt(): def process(parsed): ((((_, cond), _), body), _) = parsed return ast.WhileStmtAST(cond, body) return (parse_keyword('while') + b_expr() + parse_keyword('do') + cb.Lazy(stmt_list) + parse_keyword('end') ^ process)
def a_expr_group(): return (parse_keyword('(') + cb.Lazy(a_expr) + parse_keyword(')') ^ process_group)
def b_expr_not(): return (parse_keyword('not') + cb.Lazy(b_expr_term) ^ (lambda parsed: ast.NotExprAST(parsed[1])))