checkpoint in reconstruction
This commit is contained in:
@@ -51,6 +51,7 @@ use ::pretty::{Arena, Pretty};
|
||||
use lalrpop_util::ParseError;
|
||||
#[cfg(test)]
|
||||
use proptest::{arbitrary::Arbitrary, prop_assert, prop_assert_eq};
|
||||
use std::ops::Range;
|
||||
#[cfg(test)]
|
||||
use std::str::FromStr;
|
||||
use thiserror::Error;
|
||||
@@ -105,7 +106,7 @@ impl ParserError {
|
||||
/// closely. The major thing we do here is convert [`lalrpop`]'s notion of a location,
|
||||
/// which is just an offset that it got from the lexer, into an actual location that
|
||||
/// we can use in our [`Diagnostic`]s.
|
||||
fn convert(file_idx: usize, err: ParseError<usize, Token, LexerError>) -> Self {
|
||||
fn convert(file_idx: usize, err: ParseError<usize, Token, ParserError>) -> Self {
|
||||
match err {
|
||||
ParseError::InvalidToken { location } => {
|
||||
ParserError::InvalidToken(Location::new(file_idx, location..location + 1))
|
||||
@@ -123,11 +124,7 @@ impl ParserError {
|
||||
ParseError::ExtraToken {
|
||||
token: (start, token, end),
|
||||
} => ParserError::ExtraToken(Location::new(file_idx, start..end), token),
|
||||
ParseError::User { error } => match error {
|
||||
LexerError::LexFailure(offset) => {
|
||||
ParserError::LexFailure(Location::new(file_idx, offset..offset + 1))
|
||||
}
|
||||
},
|
||||
ParseError::User { error } => error,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -236,7 +233,7 @@ impl Program {
|
||||
pub fn parse(file_idx: usize, buffer: &str) -> Result<Program, ParserError> {
|
||||
let lexer = Token::lexer(buffer)
|
||||
.spanned()
|
||||
.map(|(token, range)| (range.start, token, range.end));
|
||||
.map(|x| permute_lexer_result(file_idx, x));
|
||||
ProgramParser::new()
|
||||
.parse(file_idx, lexer)
|
||||
.map_err(|e| ParserError::convert(file_idx, e))
|
||||
@@ -253,13 +250,25 @@ impl TopLevel {
|
||||
pub fn parse(file_idx: usize, buffer: &str) -> Result<TopLevel, ParserError> {
|
||||
let lexer = Token::lexer(buffer)
|
||||
.spanned()
|
||||
.map(|(token, range)| (range.start, token, range.end));
|
||||
.map(|x| permute_lexer_result(file_idx, x));
|
||||
TopLevelParser::new()
|
||||
.parse(file_idx, lexer)
|
||||
.map_err(|e| ParserError::convert(file_idx, e))
|
||||
}
|
||||
}
|
||||
|
||||
fn permute_lexer_result(
|
||||
file_idx: usize,
|
||||
result: (Result<Token, ()>, Range<usize>),
|
||||
) -> Result<(usize, Token, usize), ParserError> {
|
||||
let (token, range) = result;
|
||||
|
||||
match token {
|
||||
Ok(v) => Ok((range.start, v, range.end)),
|
||||
Err(()) => Err(ParserError::LexFailure(Location::new(file_idx, range))),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl FromStr for Program {
|
||||
type Err = ParserError;
|
||||
|
||||
Reference in New Issue
Block a user