Some basic parsing, with interned strings.
This commit is contained in:
@@ -1,5 +1,40 @@
|
||||
//use lalrpop_util::lalrpop_mod;
|
||||
use lalrpop_util::lalrpop_mod;
|
||||
|
||||
pub mod tokens;
|
||||
//lalrpop_mod!(pub parser);
|
||||
pub mod ast;
|
||||
mod tokens;
|
||||
mod token_stream;
|
||||
lalrpop_mod!(parser, "/syntax/parser.rs");
|
||||
mod ast;
|
||||
|
||||
pub use crate::syntax::ast::*;
|
||||
use crate::syntax::parser::ProgramParser;
|
||||
use crate::syntax::tokens::Token;
|
||||
use crate::syntax::token_stream::{LexerError, Location, TokenStream};
|
||||
use lalrpop_util::ParseError;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
|
||||
pub enum ParserError {
|
||||
IOError(io::Error),
|
||||
ParseError(ParseError<Location,Token,LexerError>),
|
||||
}
|
||||
|
||||
impl From<io::Error> for ParserError {
|
||||
fn from(x: io::Error) -> Self {
|
||||
ParserError::IOError(x)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ParseError<Location,Token,LexerError>> for ParserError {
|
||||
fn from(x: ParseError<Location, Token, LexerError>) -> Self {
|
||||
ParserError::ParseError(x)
|
||||
}
|
||||
}
|
||||
|
||||
impl Program {
|
||||
pub fn from_file(filename: &str) -> Result<Program, ParserError> {
|
||||
let metadata = fs::metadata(filename)?;
|
||||
let mut buffer = String::with_capacity(metadata.len() as usize);
|
||||
let lexer = TokenStream::from_file(filename, &mut buffer)?;
|
||||
Ok(ProgramParser::new().parse(lexer)?)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user