summaryrefslogtreecommitdiff
path: root/dhall/src/main.rs
diff options
context:
space:
mode:
authorNadrieril2019-04-12 21:44:47 +0200
committerNadrieril2019-04-12 21:44:47 +0200
commit57fb440349443b20a6b72ee04f93e0abc4d03e56 (patch)
tree7142754f6a5c69b86aaaff863656169ac0e72ef2 /dhall/src/main.rs
parent3cd881387d1e356db574448a9006596038877b5c (diff)
Restrict public API to its most minimal expression
Diffstat (limited to 'dhall/src/main.rs')
-rw-r--r--dhall/src/main.rs160
1 files changed, 81 insertions, 79 deletions
diff --git a/dhall/src/main.rs b/dhall/src/main.rs
index 3b61a44..e25a535 100644
--- a/dhall/src/main.rs
+++ b/dhall/src/main.rs
@@ -1,91 +1,93 @@
-use std::error::Error;
-use std::io::{self, Read};
-use term_painter::ToStyle;
+// use std::error::Error;
+// use std::io::{self, Read};
+// use term_painter::ToStyle;
-const ERROR_STYLE: term_painter::Color = term_painter::Color::Red;
-const BOLD: term_painter::Attr = term_painter::Attr::Bold;
+// const ERROR_STYLE: term_painter::Color = term_painter::Color::Red;
+// const BOLD: term_painter::Attr = term_painter::Attr::Bold;
-fn print_error(message: &str, source: &str, start: usize, end: usize) {
- let line_number = bytecount::count(source[..start].as_bytes(), b'\n');
- let line_start = source[..start].rfind('\n').map(|i| i + 1).unwrap_or(0);
- let line_end = source[end..].find('\n').unwrap_or(0) + end;
- let context_prefix = &source[line_start..start];
- let context_highlighted = &source[start..end];
- let context_suffix = &source[end..line_end];
+// fn print_error(message: &str, source: &str, start: usize, end: usize) {
+// let line_number = bytecount::count(source[..start].as_bytes(), b'\n');
+// let line_start = source[..start].rfind('\n').map(|i| i + 1).unwrap_or(0);
+// let line_end = source[end..].find('\n').unwrap_or(0) + end;
+// let context_prefix = &source[line_start..start];
+// let context_highlighted = &source[start..end];
+// let context_suffix = &source[end..line_end];
- let line_number_str = line_number.to_string();
- let line_number_width = line_number_str.len();
+// let line_number_str = line_number.to_string();
+// let line_number_width = line_number_str.len();
- BOLD.with(|| {
- ERROR_STYLE.with(|| {
- print!("error: ");
- });
- println!("{}", message);
- });
- BOLD.with(|| {
- print!(" -->");
- });
- println!(" (stdin):{}:0", line_number);
- BOLD.with(|| {
- println!("{:w$} |", "", w = line_number_width);
- print!("{} |", line_number_str);
- });
- print!(" {}", context_prefix);
- BOLD.with(|| {
- ERROR_STYLE.with(|| {
- print!("{}", context_highlighted);
- });
- });
- println!("{}", context_suffix);
- BOLD.with(|| {
- print!("{:w$} |", "", w = line_number_width);
- ERROR_STYLE.with(|| {
- println!(
- " {:so$}{:^>ew$}",
- "",
- "",
- so = source[line_start..start].chars().count(),
- ew = ::std::cmp::max(1, source[start..end].chars().count())
- );
- });
- });
-}
+// BOLD.with(|| {
+// ERROR_STYLE.with(|| {
+// print!("error: ");
+// });
+// println!("{}", message);
+// });
+// BOLD.with(|| {
+// print!(" -->");
+// });
+// println!(" (stdin):{}:0", line_number);
+// BOLD.with(|| {
+// println!("{:w$} |", "", w = line_number_width);
+// print!("{} |", line_number_str);
+// });
+// print!(" {}", context_prefix);
+// BOLD.with(|| {
+// ERROR_STYLE.with(|| {
+// print!("{}", context_highlighted);
+// });
+// });
+// println!("{}", context_suffix);
+// BOLD.with(|| {
+// print!("{:w$} |", "", w = line_number_width);
+// ERROR_STYLE.with(|| {
+// println!(
+// " {:so$}{:^>ew$}",
+// "",
+// "",
+// so = source[line_start..start].chars().count(),
+// ew = ::std::cmp::max(1, source[start..end].chars().count())
+// );
+// });
+// });
+// }
fn main() {
- let mut buffer = String::new();
- io::stdin().read_to_string(&mut buffer).unwrap();
+ // let mut buffer = String::new();
+ // io::stdin().read_to_string(&mut buffer).unwrap();
- let expr = match dhall::expr::Parsed::parse_str(&buffer) {
- Ok(expr) => expr,
- Err(e) => {
- print_error(&format!("Parse error {}", e), &buffer, 0, 0);
- return;
- }
- };
+ // TODO: public API is too restricted for this
+ // let expr = match dhall::expr::Parsed::parse_str(&buffer) {
+ // Ok(expr) => expr,
+ // Err(e) => {
+ // print_error(&format!("Parse error {}", e), &buffer, 0, 0);
+ // return;
+ // }
+ // };
- let expr = expr.resolve().unwrap();
+ // let expr = expr.resolve().unwrap();
- let expr = match expr.typecheck() {
- Ok(expr) => expr,
- Err(e) => {
- let explain = ::std::env::args().any(|s| s == "--explain");
- if !explain {
- term_painter::Color::BrightBlack.with(|| {
- println!("Use \"dhall --explain\" for detailed errors");
- });
- }
- ERROR_STYLE.with(|| print!("Error: "));
- println!("{}", e.type_message.description());
- if explain {
- println!("{}", e.type_message);
- }
- println!("{}", e.current);
- // FIXME Print source position
- return;
- }
- };
+ // let expr = match expr.typecheck() {
+ // Ok(expr) => expr,
+ // Err(e) => {
+ // // TODO: implement pretty type error printing
+ // // let explain = ::std::env::args().any(|s| s == "--explain");
+ // // if !explain {
+ // // term_painter::Color::BrightBlack.with(|| {
+ // // println!("Use \"dhall --explain\" for detailed errors");
+ // // });
+ // // }
+ // // ERROR_STYLE.with(|| print!("Error: "));
+ // // println!("{}", e.type_message.description());
+ // // if explain {
+ // // println!("{}", e.type_message);
+ // // }
+ // // println!("{}", e.current);
+ // // // FIXME Print source position
+ // return;
+ // }
+ // };
- let expr = expr.normalize();
+ // let expr = expr.normalize();
- println!("{}", expr);
+ // println!("{}", expr);
}