# Future tools [ ] Lexer/Checker ## Lexer ` Command: grammar --check ` Tries to do a quick grammar check and locate errors * https://brunocalza.me/writing-a-simple-lexer-in-rust/ * https://github.com/goffrie/plex ### Logos, fast lexer * https://crates.io/crates/logos ```rust use logos::Logos; #[derive(Logos, Debug, PartialEq)] #[logos(skip r"[ \t\n\f]+")] // Ignore this regex pattern between tokens enum Token { // Tokens can be literal strings, of any length. #[token("fast")] Fast, #[token(".")] Period, // Or regular expressions. #[regex("[a-zA-Z]+")] Text, } ``` ### Chumsky, full parser ```rust use chumsky::prelude::*; #[derive(Clone)] enum Instr { Left, Right, Incr, Decr, Read, Write, Loop(Vec), } fn parser() -> impl Parser, Error = Simple> { recursive(|bf| choice(( just('<').to(Instr::Left), just('>').to(Instr::Right), just('+').to(Instr::Incr), just('-').to(Instr::Decr), just(',').to(Instr::Read), just('.').to(Instr::Write), bf.delimited_by(just('['), just(']')).map(Instr::Loop), )) .repeated()) } ```