From e72192c0c1825f36f054263437029d05d717c957 Mon Sep 17 00:00:00 2001 From: NanoTech Date: Thu, 8 Dec 2016 03:12:38 -0600 Subject: Begin implementing type checking --- src/main.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index deb6ac3..17c990d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,12 +4,14 @@ extern crate lalrpop_util; extern crate nom; extern crate term_painter; +pub mod context; mod core; pub use core::*; pub mod grammar; mod grammar_util; pub mod lexer; pub mod parser; +pub mod typecheck; use std::io::{self, Read}; @@ -62,29 +64,33 @@ fn print_error(message: &str, source: &str, start: usize, end: usize) { fn main() { let mut buffer = String::new(); io::stdin().read_to_string(&mut buffer).unwrap(); - match parser::parse_expr(&buffer) { - Ok(e) => println!("{:?}", e), + let expr = match parser::parse_expr(&buffer) { + Ok(e) => e, Err(lalrpop_util::ParseError::User { error: lexer::LexicalError::Error(pos, e) }) => { print_error(&format!("Unexpected token {:?}", e), &buffer, pos, pos); + return; } Err(lalrpop_util::ParseError::UnrecognizedToken { token: Some((start, t, end)), expected: e }) => { print_error(&format!("Unrecognized token {:?}", t), &buffer, start, end); if e.len() > 0 { println!("Expected {:?}", e); } + return; } Err(e) => { print_error(&format!("Parser error {:?}", e), &buffer, 0, 0); + return; } - } + }; - /* - expr <- case exprFromText (Directed "(stdin)" 0 0 0 0) inText of - Left err -> Control.Exception.throwIO err - Right expr -> return expr + println!("{:?}", expr); + /* expr' <- load expr + */ + println!("{:?}", typecheck::type_of(&expr)); + /* typeExpr <- case Dhall.TypeCheck.typeOf expr' of Left err -> Control.Exception.throwIO err Right typeExpr -> return typeExpr -- cgit v1.2.3