-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parsing User Error for InvalidToken (#21)
* Lexer captures InvalidToken and parser returns it as a * Positions can now be implemented by @l and @r tokens at Lalrpop #5 . * The F/lex FFI part of lexer is now more documented. * The token position is now checked and implemented from the Lexer grammar.
- Loading branch information
Showing
20 changed files
with
1,291 additions
and
718 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#[macro_use] | ||
extern crate criterion; | ||
extern crate telamon_gen; | ||
|
||
use criterion::Criterion; | ||
|
||
use telamon_gen::lexer; | ||
|
||
use std::fs; | ||
use std::ffi::OsStr; | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
let entries = fs::read_dir("cc_tests/src/").unwrap(); | ||
for entry in entries { | ||
if let Ok(entry) = entry { | ||
if entry.path().extension().eq(&Some(OsStr::new("exh"))) { | ||
let path = entry.path(); | ||
let mut input = fs::File::open(&path).unwrap(); | ||
let mut name = String::from("lexer "); | ||
name.push_str(path.file_stem().unwrap().to_str().unwrap()); | ||
|
||
c.bench_function(&name, move |b| b.iter(|| lexer::Lexer::new(&mut input))); | ||
} | ||
} | ||
} | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
use super::lexer; | ||
use super::lalrpop_util::*; | ||
|
||
use std::{path, fmt}; | ||
use std::error::Error; | ||
|
||
#[derive(Debug)] | ||
pub enum Cause { | ||
/// Lalrpop | ||
Parse(ParseError<lexer::Position, | ||
lexer::Token, | ||
lexer::LexicalError>), | ||
/// Will be remplaced by field for Ast [...] | ||
Other, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct ProcessError<'a> { | ||
/// Display of filename. | ||
pub path: path::Display<'a>, | ||
/// Position of lexeme. | ||
pub span: Option<lexer::Span>, | ||
cause: Cause, | ||
} | ||
|
||
impl <'a>From<(path::Display<'a>, | ||
ParseError<lexer::Position, | ||
lexer::Token, | ||
lexer::LexicalError> | ||
)> for ProcessError<'a> { | ||
fn from((path, parse): (path::Display<'a>, | ||
ParseError<lexer::Position, | ||
lexer::Token, | ||
lexer::LexicalError> | ||
)) -> Self { | ||
match parse { | ||
ParseError::InvalidToken { location } | ||
=> ProcessError { | ||
path: path, | ||
span: Some(lexer::Span { leg: location, ..Default::default() }), | ||
cause: Cause::Parse(parse), | ||
}, | ||
ParseError::UnrecognizedToken { token: None, .. } | ||
=> ProcessError { | ||
path: path, | ||
span: None, | ||
cause: Cause::Parse(parse), | ||
}, | ||
ParseError::UnrecognizedToken { token: Some((l, .., e)), .. } | | ||
ParseError::ExtraToken { token: (l, .., e) } | | ||
ParseError::User { error: lexer::LexicalError::UnexpectedToken(l, .., e) } | | ||
ParseError::User { error: lexer::LexicalError::InvalidToken(l, .., e) } | ||
=> ProcessError { | ||
path: path, | ||
span: Some(lexer::Span { leg: l, end: Some(e) }), | ||
cause: Cause::Parse(parse), | ||
}, | ||
} | ||
} | ||
} | ||
|
||
impl <'a> fmt::Display for ProcessError<'a> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match self { | ||
ProcessError { path, span, cause: Cause::Parse( | ||
ParseError::UnrecognizedToken { | ||
token: Some((_, ref token, _)), .. | ||
}), ..} | | ||
ProcessError { path, span, cause: Cause::Parse(ParseError::ExtraToken { | ||
token: (_, ref token, _) | ||
}), ..} | | ||
ProcessError { path, span, cause: Cause::Parse( | ||
ParseError::User { | ||
error: lexer::LexicalError::UnexpectedToken(_, ref token, _) | ||
}), ..} | | ||
ProcessError { path, span, cause: Cause::Parse( | ||
ParseError::User { | ||
error: lexer::LexicalError::InvalidToken(_, ref token, _) | ||
}), ..} => { | ||
if let Some(span) = span { | ||
write!(f, "{}, {} -> {}", token, span, path) | ||
} else { | ||
write!(f, "{} -> {}", token, path) | ||
} | ||
}, | ||
_ => Ok(()), | ||
} | ||
} | ||
} | ||
|
||
impl <'a>Error for ProcessError<'a> { | ||
fn description(&self) -> &str { | ||
"Process error" | ||
} | ||
|
||
fn cause(&self) -> Option<&Error> { | ||
if let Cause::Parse(ref parse) = self.cause { | ||
parse.cause() | ||
} else { | ||
None | ||
} | ||
} | ||
} |
Oops, something went wrong.