Very weirdly organized, but it JITs!
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user