1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Brainfuck-like language library.
//!
//! This library can define a variant of Brainfuck-like language parser
//! and can run parsed program.
//!
//! # Examples
//!
//! ```
//! use libbf::{parser::Parser, runtime, token::simple::SimpleTokenSpec};
//! use std::io::{self, Read};
//!
//! // Create parser with token specification.
//! let parser = Parser::new(
//! SimpleTokenSpec {
//! // You can specify tokens with `ToString` (`char`, `&str`, `String`, etc.)
//! ptr_inc: '>', // char
//! ptr_dec: "<", // &str
//! data_inc: "+".to_string(), // String
//! data_dec: '-',
//! output: '.',
//! input: ',',
//! loop_head: '[',
//! loop_tail: ']',
//! }
//! .to_tokenizer(),
//! );
//!
//! let source = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.";
//! let program = parser.parse_str(source).expect("Failed to parse");
//! let mut output = Vec::new();
//! let result = runtime::run(&program, io::stdin(), &mut output);
//!
//! assert!(result.is_ok());
//! assert_eq!(output, b"Hello World!\n");
//! ```
/// `use libbf::prelude::*` is easy way to use this library;