oak 0.3.1

A typed parser generator syntax extension for Parsing Expression Grammar (PEG).
note: pub mod calc {
    #![allow(dead_code)]
    #![allow(unused_parens, unused_variables, unused_mut)]
    extern crate oak_runtime;
    use std::str::FromStr;
    use self::Expression::*;
    use self::BinOp::*;
    pub type PExpr = Box<Expression>;
    #[derive(Debug)]
    pub enum Expression {
        Variable(String),
        Digit(u32),
        BinaryExpr(BinOp, PExpr, PExpr),
    }
    #[derive(Debug)]
    pub enum BinOp { Add, Sub, }
    fn digit_expr(digit: u32) -> PExpr { Box::new(Digit(digit)) }
    fn addition_expr(head: PExpr, rest: Vec<PExpr>) -> PExpr {
        rest.into_iter().fold(head,
                              |accu, expr|
                                  Box::new(BinaryExpr(Add, accu, expr)))
    }
    fn variable_expr(raw_text: Vec<char>) -> PExpr {
        Box::new(Variable(raw_text.into_iter().collect()))
    }
    fn to_digit(raw_text: Vec<char>) -> u32 {
        let text: String = raw_text.into_iter().collect();
        u32::from_str(&*text).unwrap()
    }
    #[inline]
    fn recognize_class_char_in_rule_integer_2<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        {
            let past = stream.clone();
            match stream.next() {
                Some(current) if (current >= '0' && current <= '9') => {
                    oak_runtime::ParseState::stateless(stream)
                }
                _ => { oak_runtime::ParseState::error(past, "[\"0-9\"]") }
            }
        }
    }
    #[inline]
    pub fn parse_div_op<S>(mut stream: S) -> oak_runtime::ParseState<S, ()>
     where S: oak_runtime::CharStream {
        recognize_div_op(stream)
    }
    #[inline]
    fn recognize_semantic_action_in_rule_operand_10<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_identifier(stream)
    }
    #[inline]
    fn parse_star_in_rule_identifier_7<S>(mut stream: S)
     -> oak_runtime::ParseState<S, Vec<char>> where
     S: oak_runtime::CharStream {
        {
            let mut state =
                oak_runtime::ParseState::success(stream.clone(), vec!());
            while state.has_successor() {
                let next =
                    parse_class_char_in_rule_identifier_6(state.stream());
                state = state.merge_error(next.error);
                if let Some(success) = next.success {
                    state.merge_success(success);
                } else { break ; }
            }
            {
                if state.stream_eq(&stream) {
                    state.to_error()
                } else { state }
            }
        }
    }
    #[inline]
    fn parse_star_in_rule_integer_3<S>(mut stream: S)
     -> oak_runtime::ParseState<S, Vec<char>> where
     S: oak_runtime::CharStream {
        {
            let mut state =
                oak_runtime::ParseState::success(stream.clone(), vec!());
            while state.has_successor() {
                let next = parse_class_char_in_rule_integer_2(state.stream());
                state = state.merge_error(next.error);
                if let Some(success) = next.success {
                    state.merge_success(success);
                } else { break ; }
            }
            {
                if state.stream_eq(&stream) {
                    state.to_error()
                } else { state }
            }
        }
    }
    #[inline]
    pub fn recognize_add_op<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_str_literal_in_rule_add_op_1(stream)
    }
    #[inline]
    fn recognize_class_char_in_rule_identifier_6<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        {
            let past = stream.clone();
            match stream.next() {
                Some(current) if
                (current >= 'a' && current <= 'z') ||
                    (current >= 'A' && current <= 'Z') ||
                    (current >= '0' && current <= '9') ||
                    (current >= '_' && current <= '_') => {
                    oak_runtime::ParseState::stateless(stream)
                }
                _ => {
                    oak_runtime::ParseState::error(past, "[\"a-zA-Z0-9_\"]")
                }
            }
        }
    }
    #[inline]
    fn parse_str_literal_in_rule_div_op_0<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_str_literal_in_rule_div_op_0(stream)
    }
    #[inline]
    fn recognize_str_literal_in_rule_mul_op_16<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        oak_runtime::recognize_match_literal(stream, "*")
    }
    #[inline]
    fn recognize_semantic_action_in_rule_addition_15<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_sequence_in_rule_addition_14(stream)
    }
    #[inline]
    pub fn recognize_integer<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_semantic_action_in_rule_integer_4(stream)
    }
    #[inline]
    fn recognize_str_literal_in_rule_let_kw_5<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        oak_runtime::recognize_match_literal(stream, "let")
    }
    #[inline]
    pub fn parse_addition<S>(mut stream: S)
     -> oak_runtime::ParseState<S, PExpr> where S: oak_runtime::CharStream {
        parse_semantic_action_in_rule_addition_15(stream)
    }
    #[inline]
    fn parse_class_char_in_rule_identifier_6<S>(mut stream: S)
     -> oak_runtime::ParseState<S, char> where S: oak_runtime::CharStream {
        {
            let past = stream.clone();
            match stream.next() {
                Some(current) if
                (current >= 'a' && current <= 'z') ||
                    (current >= 'A' && current <= 'Z') ||
                    (current >= '0' && current <= '9') ||
                    (current >= '_' && current <= '_') => {
                    oak_runtime::ParseState::success(stream, current)
                }
                _ => {
                    oak_runtime::ParseState::error(past, "[\"a-zA-Z0-9_\"]")
                }
            }
        }
    }
    #[inline]
    pub fn recognize_let_kw<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_str_literal_in_rule_let_kw_5(stream)
    }
    #[inline]
    fn parse_str_literal_in_rule_bind_op_17<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_str_literal_in_rule_bind_op_17(stream)
    }
    #[inline]
    fn parse_sequence_in_rule_addition_12<S>(mut stream: S)
     -> oak_runtime::ParseState<S, PExpr> where S: oak_runtime::CharStream {
        parse_add_op(stream).and_then(move |state1| {
                                      let stream = state1.stream.clone();
                                      parse_operand(stream).and_then(move
                                                                         |state0|
                                                                         {
                                                                     let stream =
                                                                         state0.stream.clone();
                                                                     oak_runtime::ParseState::success(stream,
                                                                                                      state0.data)
                                                                 }) })
    }
    #[inline]
    fn recognize_star_in_rule_identifier_7<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        {
            let mut state =
                oak_runtime::ParseState::stateless(stream.clone());
            while state.has_successor() {
                let next =
                    recognize_class_char_in_rule_identifier_6(state.stream());
                state = state.merge_error(next.error);
                if let Some(success) = next.success {
                    state.merge_success(success);
                } else { break ; }
            }
            {
                if state.stream_eq(&stream) {
                    state.to_error()
                } else { state }
            }
        }
    }
    #[inline]
    fn parse_str_literal_in_rule_mul_op_16<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_str_literal_in_rule_mul_op_16(stream)
    }
    #[inline]
    fn parse_star_in_rule_addition_13<S>(mut stream: S)
     -> oak_runtime::ParseState<S, Vec<PExpr>> where
     S: oak_runtime::CharStream {
        {
            let mut state =
                oak_runtime::ParseState::success(stream.clone(), vec!());
            while state.has_successor() {
                let next = parse_sequence_in_rule_addition_12(state.stream());
                state = state.merge_error(next.error);
                if let Some(success) = next.success {
                    state.merge_success(success);
                } else { break ; }
            }
            state
        }
    }
    #[inline]
    fn parse_class_char_in_rule_integer_2<S>(mut stream: S)
     -> oak_runtime::ParseState<S, char> where S: oak_runtime::CharStream {
        {
            let past = stream.clone();
            match stream.next() {
                Some(current) if (current >= '0' && current <= '9') => {
                    oak_runtime::ParseState::success(stream, current)
                }
                _ => { oak_runtime::ParseState::error(past, "[\"0-9\"]") }
            }
        }
    }
    #[inline]
    pub fn parse_let_kw<S>(mut stream: S) -> oak_runtime::ParseState<S, ()>
     where S: oak_runtime::CharStream {
        recognize_let_kw(stream)
    }
    #[inline]
    fn recognize_semantic_action_in_rule_operand_9<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_integer(stream)
    }
    #[inline]
    pub fn parse_add_op<S>(mut stream: S) -> oak_runtime::ParseState<S, ()>
     where S: oak_runtime::CharStream {
        recognize_add_op(stream)
    }
    #[inline]
    pub fn recognize_sub_op<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_str_literal_in_rule_sub_op_18(stream)
    }
    #[inline]
    fn parse_sequence_in_rule_addition_14<S>(mut stream: S)
     -> oak_runtime::ParseState<S, (PExpr, Vec<PExpr>)> where
     S: oak_runtime::CharStream {
        parse_operand(stream).and_then(move |state1| {
                                       let stream = state1.stream.clone();
                                       parse_star_in_rule_addition_13(stream).and_then(move
                                                                                           |state0|
                                                                                           {
                                                                                       let stream =
                                                                                           state0.stream.clone();
                                                                                       oak_runtime::ParseState::success(stream,
                                                                                                                        (state1.data,
                                                                                                                         state0.data))
                                                                                   })
                                   })
    }
    #[inline]
    fn parse_str_literal_in_rule_add_op_1<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_str_literal_in_rule_add_op_1(stream)
    }
    #[inline]
    pub fn recognize_bind_op<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_str_literal_in_rule_bind_op_17(stream)
    }
    #[inline]
    fn parse_str_literal_in_rule_let_kw_5<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_str_literal_in_rule_let_kw_5(stream)
    }
    #[inline]
    pub fn parse_sub_op<S>(mut stream: S) -> oak_runtime::ParseState<S, ()>
     where S: oak_runtime::CharStream {
        recognize_sub_op(stream)
    }
    #[inline]
    fn recognize_str_literal_in_rule_in_kw_8<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        oak_runtime::recognize_match_literal(stream, "in")
    }
    #[inline]
    fn recognize_str_literal_in_rule_add_op_1<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        oak_runtime::recognize_match_literal(stream, "+")
    }
    #[inline]
    fn parse_str_literal_in_rule_in_kw_8<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_str_literal_in_rule_in_kw_8(stream)
    }
    #[inline]
    pub fn parse_bind_op<S>(mut stream: S) -> oak_runtime::ParseState<S, ()>
     where S: oak_runtime::CharStream {
        recognize_bind_op(stream)
    }
    #[inline]
    fn parse_semantic_action_in_rule_addition_15<S>(mut stream: S)
     -> oak_runtime::ParseState<S, PExpr> where S: oak_runtime::CharStream {
        parse_sequence_in_rule_addition_14(stream).map_data(|data|
                                                                addition_expr(data.0,
                                                                              data.1))
    }
    #[inline]
    pub fn recognize_addition<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_semantic_action_in_rule_addition_15(stream)
    }
    #[inline]
    pub fn recognize_mul_op<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_str_literal_in_rule_mul_op_16(stream)
    }
    #[inline]
    fn recognize_sequence_in_rule_addition_12<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_add_op(stream).and_then(|success| {
                                          let stream = success.stream;
                                          recognize_operand(stream) })
    }
    #[inline]
    fn parse_semantic_action_in_rule_operand_9<S>(mut stream: S)
     -> oak_runtime::ParseState<S, PExpr> where S: oak_runtime::CharStream {
        parse_integer(stream).map_data(|data| digit_expr(data))
    }
    #[inline]
    fn parse_choice_in_rule_operand_11<S>(mut stream: S)
     -> oak_runtime::ParseState<S, PExpr> where S: oak_runtime::CharStream {
        parse_semantic_action_in_rule_operand_9(stream.clone()).or_else_merge(||
                                                                                  parse_semantic_action_in_rule_operand_10(stream))
    }
    #[inline]
    fn recognize_sequence_in_rule_addition_14<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_operand(stream).and_then(|success| {
                                           let stream = success.stream;
                                           recognize_star_in_rule_addition_13(stream)
                                       })
    }
    #[inline]
    pub fn parse_mul_op<S>(mut stream: S) -> oak_runtime::ParseState<S, ()>
     where S: oak_runtime::CharStream {
        recognize_mul_op(stream)
    }
    #[inline]
    fn recognize_str_literal_in_rule_div_op_0<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        oak_runtime::recognize_match_literal(stream, "/")
    }
    #[inline]
    fn recognize_choice_in_rule_operand_11<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_semantic_action_in_rule_operand_9(stream.clone()).or_else_merge(||
                                                                                      recognize_semantic_action_in_rule_operand_10(stream))
    }
    #[inline]
    fn recognize_semantic_action_in_rule_integer_4<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_star_in_rule_integer_3(stream)
    }
    #[inline]
    pub fn parse_in_kw<S>(mut stream: S) -> oak_runtime::ParseState<S, ()>
     where S: oak_runtime::CharStream {
        recognize_in_kw(stream)
    }
    #[inline]
    pub fn recognize_identifier<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_star_in_rule_identifier_7(stream)
    }
    #[inline]
    fn recognize_str_literal_in_rule_sub_op_18<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        oak_runtime::recognize_match_literal(stream, "-")
    }
    #[inline]
    fn recognize_star_in_rule_integer_3<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        {
            let mut state =
                oak_runtime::ParseState::stateless(stream.clone());
            while state.has_successor() {
                let next =
                    recognize_class_char_in_rule_integer_2(state.stream());
                state = state.merge_error(next.error);
                if let Some(success) = next.success {
                    state.merge_success(success);
                } else { break ; }
            }
            {
                if state.stream_eq(&stream) {
                    state.to_error()
                } else { state }
            }
        }
    }
    #[inline]
    pub fn parse_integer<S>(mut stream: S) -> oak_runtime::ParseState<S, u32>
     where S: oak_runtime::CharStream {
        parse_semantic_action_in_rule_integer_4(stream)
    }
    #[inline]
    fn parse_semantic_action_in_rule_operand_10<S>(mut stream: S)
     -> oak_runtime::ParseState<S, PExpr> where S: oak_runtime::CharStream {
        parse_identifier(stream).map_data(|data| variable_expr(data))
    }
    #[inline]
    fn recognize_str_literal_in_rule_bind_op_17<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        oak_runtime::recognize_match_literal(stream, "=")
    }
    #[inline]
    pub fn parse_operand<S>(mut stream: S)
     -> oak_runtime::ParseState<S, PExpr> where S: oak_runtime::CharStream {
        parse_choice_in_rule_operand_11(stream)
    }
    #[inline]
    fn parse_str_literal_in_rule_sub_op_18<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_str_literal_in_rule_sub_op_18(stream)
    }
    #[inline]
    pub fn recognize_div_op<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_str_literal_in_rule_div_op_0(stream)
    }
    #[inline]
    pub fn recognize_operand<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        recognize_choice_in_rule_operand_11(stream)
    }
    #[inline]
    fn recognize_star_in_rule_addition_13<S>(mut stream: S)
     -> oak_runtime::ParseState<S, ()> where S: oak_runtime::CharStream {
        {
            let mut state =
                oak_runtime::ParseState::stateless(stream.clone());
            while state.has_successor() {
                let next =
                    recognize_sequence_in_rule_addition_12(state.stream());
                state = state.merge_error(next.error);
                if let Some(success) = next.success {
                    state.merge_success(success);
                } else { break ; }
            }
            state
        }
    }
    #[inline]
    pub fn recognize_in_kw<S>(mut stream: S) -> oak_runtime::ParseState<S, ()>
     where S: oak_runtime::CharStream {
        recognize_str_literal_in_rule_in_kw_8(stream)
    }
    #[inline]
    pub fn parse_identifier<S>(mut stream: S)
     -> oak_runtime::ParseState<S, Vec<char>> where
     S: oak_runtime::CharStream {
        parse_star_in_rule_identifier_7(stream)
    }
    #[inline]
    fn parse_semantic_action_in_rule_integer_4<S>(mut stream: S)
     -> oak_runtime::ParseState<S, u32> where S: oak_runtime::CharStream {
        parse_star_in_rule_integer_3(stream).map_data(|data| to_digit(data))
    }
}