talc/talc-lang/src/lib.rs
2024-02-23 14:54:34 -05:00

48 lines
1 KiB
Rust

#[rustfmt::skip]
#[allow(clippy::extra_unused_lifetimes)]
#[allow(clippy::needless_lifetimes)]
#[allow(clippy::let_unit_value)]
#[allow(clippy::just_underscores_and_digits)]
#[allow(clippy::pedantic)]
mod parser {
pub use __intern_token::new_builder as new_builder;
include!(concat!(env!("OUT_DIR"),"/parser.rs"));
}
mod parser_util;
mod vm;
pub mod symbol;
pub mod ast;
pub mod value;
pub mod gc;
pub mod chunk;
pub mod compiler;
pub use parser::BlockParser as Parser;
pub use vm::Vm;
type LexResult<'input> = Result<
(usize, Token<'input>, usize),
ParseError<usize, Token<'input>, parser_util::ParseError>
>;
use lalrpop_util::{ParseError, lexer::{Token, MatcherBuilder}};
pub struct Lexer {
builder: MatcherBuilder,
}
impl Default for Lexer {
fn default() -> Self { Self::new() }
}
impl Lexer {
pub fn new() -> Self {
Self { builder: crate::parser::new_builder() }
}
pub fn lex<'s>(&'s self, input: &'s str) -> impl Iterator<Item=LexResult<'s>> {
self.builder.matcher::<parser_util::ParseError>(input)
}
}