diff --git a/onihime/src/lib.rs b/onihime/src/lib.rs index 47d0387..f030f2d 100644 --- a/onihime/src/lib.rs +++ b/onihime/src/lib.rs @@ -1,6 +1,11 @@ //! Onihime programming language. -#![deny(missing_debug_implementations, missing_docs, rust_2018_idioms)] +#![deny( + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unsafe_code +)] mod lexer; mod parser; diff --git a/onihime/src/parser/ast.rs b/onihime/src/parser/ast.rs index 82a326d..5c2f5bb 100644 --- a/onihime/src/parser/ast.rs +++ b/onihime/src/parser/ast.rs @@ -1,4 +1,4 @@ -use super::error::{ParserError, ParserErrorKind}; +use super::error::ParserError; use crate::{ lexer::{Symbol, Token, TokenKind}, span::Span, diff --git a/onihime/src/parser/mod.rs b/onihime/src/parser/mod.rs index 4fc5ad2..e8874b3 100644 --- a/onihime/src/parser/mod.rs +++ b/onihime/src/parser/mod.rs @@ -42,7 +42,7 @@ impl<'parser> Parser<'parser> { // run out of tokens, or an error occurs: while !self.lexer.eof() { if let Some(node) = self.expr()? { - self.current.push_node(node); + self.current.push_node(node)?; } } @@ -88,7 +88,7 @@ impl<'parser> Parser<'parser> { let node = Node::try_from(token)?; let span = node.span.clone(); - self.current.push_node(node); + self.current.push_node(node)?; self.current.span.extend(&span); Ok(None) @@ -160,7 +160,7 @@ mod tests { ( $name:ident: $input:literal, $src:ident => $ast:expr ) => { #[test] fn $name() { - let mut parser = Parser::new($input); + let parser = Parser::new($input); let $src = parser.lexer.source(); assert_eq!(parser.parse(), $ast); } diff --git a/onihime/src/span.rs b/onihime/src/span.rs index c2b7cf5..164d714 100644 --- a/onihime/src/span.rs +++ b/onihime/src/span.rs @@ -197,4 +197,33 @@ mod tests { assert_eq!(source.get_line(1), "line 2"); assert_eq!(source.get_line(2), "line 3"); } + + #[test] + fn span_partial_eq() { + let source = Arc::new(Source::new(None, String::new())); + + let a = Span::new(0..0, source.clone()); + assert_eq!(a, a); + + let b = Span::new(1..10, source.clone()); + assert_ne!(a, b); + + let source2 = Arc::new(Source::new(None, String::from("foo"))); + let c = Span::new(0..0, source2.clone()); + assert_ne!(a, c); + } + + #[test] + fn span_start_end_location() { + let source = Arc::new(Source::new(None, "foo\nbar\nbaz".into())); + let span = Span::new(2..9, source); + + let start = span.location(); + assert_eq!(start.line, 0); + assert_eq!(start.column, 2); + + let end = span.end_location(); + assert_eq!(end.line, 2); + assert_eq!(end.column, 1); + } }