Very weirdly organized, but it JITs!

This commit is contained in:
2023-03-24 10:28:32 -05:00
parent ff8412acca
commit 4aa3a9419a
14 changed files with 441 additions and 81 deletions

View File

@@ -1,4 +1,4 @@
use codespan_reporting::{files::SimpleFiles, diagnostic::Diagnostic};
use codespan_reporting::{diagnostic::Diagnostic, files::SimpleFiles};
use lalrpop_util::lalrpop_mod;
use logos::Logos;
@@ -22,6 +22,8 @@ use lalrpop_util::ParseError;
use std::str::FromStr;
use thiserror::Error;
use self::parser::StatementParser;
#[derive(Debug, Error)]
pub enum ParserError {
#[error("Invalid token")]
@@ -178,6 +180,17 @@ impl Program {
}
}
impl Statement {
pub fn parse(file_idx: usize, buffer: &str) -> Result<Statement, ParserError> {
let lexer = Token::lexer(buffer)
.spanned()
.map(|(token, range)| (range.start, token, range.end));
StatementParser::new()
.parse(file_idx, lexer)
.map_err(|e| ParserError::convert(file_idx, e))
}
}
#[cfg(test)]
impl FromStr for Program {
type Err = ParserError;