1#![doc = r"Traits and definitions for building a brainfuck interpreter"]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3
4use crate::token::BFToken;
11use std::{io::BufRead, io::Write};
12
13pub trait Operator {
14 fn op_ptr_left(&mut self);
15 fn op_ptr_right(&mut self);
16 fn op_add_to_cell(&mut self);
17 fn op_sub_from_cell(&mut self);
18 fn op_print_cell_as_char(&self, writer: &mut impl Write);
19 fn op_input_to_cell(&mut self, reader: &mut impl BufRead);
20 fn op_jump_forwards(&mut self);
21 fn op_jump_backwards(&mut self);
22}
23
24pub trait Runner: Clone + Sized {
25 fn add_tokens(&mut self, token_stream: Vec<BFToken>) -> &mut Self;
27 fn clean_env(&mut self) -> &mut Self;
30 fn next_instruction(&mut self, reader: &mut impl BufRead, writer: &mut impl Write)
32 -> &mut Self;
33 fn run_full_stack(&mut self, reader: &mut impl BufRead, writer: &mut impl Write) -> &mut Self;
35}