brainstem 0.1.0

A Brainfuck compiler and interpreter library, with a BrainStem frontend language.
Documentation
use lalrpop_util::ParseError;
use crate::bfi::ast::{Op, finalize};

grammar;

Terminal: Op = {
    ">" => Op::MovePointer(1),
    "<" => Op::MovePointer(-1),
    "+" => Op::Increment(1),
    "-" => Op::Increment(-1),
    "[" => Op::JumpIfZero(0),
    "]" => Op::JumpBack(0),
    "," => Op::Read,
    "." => Op::Write,
};

pub Program : Vec<Op> = {
    <v:Terminal*> =>? {
        finalize(v).map_err(|e| ParseError::User {
            error: e
        })
    }
}

match {
    ">",
    "<",
    "+",
    "-",
    "[",
    "]",
    ",",
    ".",
    r"[^<>\+\-\[\]\,\.]*" => { },  // Ignore any non-bf characters.
}