From eda4791472f5bf8daeba342efe97dc0977666613 Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Fri, 8 Jan 2021 18:01:23 +0000 Subject: Minor fix-ups to AutoChomp --- autochomp/build.rs | 21 +++++++++++++-------- autochomp/src/main.rs | 15 ++++++++++++--- autochomp/src/nibble.nb | 8 ++++---- 3 files changed, 29 insertions(+), 15 deletions(-) (limited to 'autochomp') diff --git a/autochomp/build.rs b/autochomp/build.rs index 952d49c..58c12a1 100644 --- a/autochomp/build.rs +++ b/autochomp/build.rs @@ -5,7 +5,7 @@ use std::{ fs, io::{Read, Write}, path::Path, - process::exit, + process::Command, }; use chomp::{ @@ -36,9 +36,13 @@ fn main() { let out_dir = env::var("OUT_DIR").unwrap(); let mut input = String::new(); - let res = fs::File::open(PATH) + + fs::File::open(PATH) .map_err(|e| Box::new(e) as Box) - .and_then(|mut file| file.read_to_string(&mut input).map_err(|e| Box::new(e) as Box)) + .and_then(|mut file| { + file.read_to_string(&mut input) + .map_err(|e| Box::new(e) as Box) + }) .and_then(|_| syn::parse_str(&input).map_err(|e| Box::new(e) as Box)) .and_then(|nibble: File| nibble.convert().ok_or(Box::new(UndecVar) as Box)) .and_then(|(funs, goal)| { @@ -64,10 +68,11 @@ fn main() { fs::File::create(Path::new(&out_dir).join("nibble.rs")) .and_then(|mut f| write!(f, "{}", code)) .map_err(|e| Box::new(e) as Box) - }); + }) + .unwrap(); - if let Err(e) = res { - eprintln!("{}", e); - exit(1) - } + Command::new("rustfmt") + .arg(&format!("{}/nibble.rs", out_dir)) + .status() + .unwrap(); } diff --git a/autochomp/src/main.rs b/autochomp/src/main.rs index 400cc2d..9b3b521 100644 --- a/autochomp/src/main.rs +++ b/autochomp/src/main.rs @@ -1,6 +1,11 @@ -use std::{error::Error, io::{self, Read, Write}, process::exit}; +use std::{ + error::Error, + fs, + io::{self, Read, Write}, + process::exit, +}; -use chewed::Parse; +use chewed::{IterWrapper, Parser}; mod nibble { include!(concat!(env!("OUT_DIR"), "/nibble.rs")); @@ -11,7 +16,11 @@ fn main() { let res = io::stdin() .read_to_string(&mut input) .map_err(|e| Box::new(e) as Box) - .and_then(|_| nibble::Ast::parse(input.chars().peekable()).map_err(|e| Box::new(e) as Box)) + .and_then(|_| { + IterWrapper::new(input.chars()) + .parse::() + .map_err(|e| Box::new(e) as Box) + }) .and_then(|ast| { write!(io::stdout(), "{:?}", ast).map_err(|e| Box::new(e) as Box) }); diff --git a/autochomp/src/nibble.nb b/autochomp/src/nibble.nb index fed3d46..d454adf 100644 --- a/autochomp/src/nibble.nb +++ b/autochomp/src/nibble.nb @@ -5,8 +5,8 @@ let star_(base, step) = [rec](base | step . rec); let Pattern_Whitespace = "\t"|"\n"|"\x0B"|"\x0c"|"\r"|" "|"\u{85}"|"\u{200e}"|"\u{200f}"|"\u{2028}"|"\u{2029}"; -let digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; -let oct_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7"; +let oct_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ; +let digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; let hex_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "a" | "b" | "c" | "d" | "e" | "f" | "A" | "B" | "C" | "D" | "E" | "F" ; @@ -42,8 +42,8 @@ let literal_char = let ws = plus(Pattern_Whitespace); -let punctuated(x, p) = [rec](x . opt(p . opt(ws) . opt(rec))); -let list(x) = "(" . opt(ws) . punctuated(x, ",") . ")"; +let punctuated(x, p) = [rec](x . opt(p . opt(ws) . rec)); +let list(x) = "(" . opt(ws) . [rec](x . opt("," . opt(ws) . opt(rec))) . ")"; let epsilon = "_"; let ident = XID_Start . star(XID_Continue); -- cgit v1.2.3