brainfuck/
ast.rs

1use core;
2
3use std::convert::From;
4use std::iter::IntoIterator;
5
6#[derive(Debug, PartialEq)]
7pub enum Node {
8    LShift,
9    RShift,
10    Inc,
11    Dec,
12    PutCh,
13    GetCh,
14    Loop(Block),
15}
16
17#[derive(Debug, PartialEq)]
18pub struct Block(Vec<Node>);
19
20impl Block {
21    pub fn new() -> Block {
22        Block(Vec::new())
23    }
24
25    pub fn push(&mut self, node: Node) {
26        self.0.push(node);
27    }
28}
29
30impl Default for Block {
31    fn default() -> Self {
32        Block::new()
33    }
34}
35
36impl From<Vec<Node>> for Block {
37    fn from(nodes: Vec<Node>) -> Self {
38        Block(nodes)
39    }
40}
41
42impl<'a> IntoIterator for &'a Block {
43    type Item     = &'a Node;
44    type IntoIter = self::core::slice::Iter<'a, Node>;
45
46    fn into_iter(self) -> Self::IntoIter {
47        self.0.iter()
48    }
49}