summaryrefslogtreecommitdiff
path: root/autochomp/src
diff options
context:
space:
mode:
Diffstat (limited to 'autochomp/src')
-rw-r--r--autochomp/src/main.rs15
-rw-r--r--autochomp/src/nibble.nb8
2 files changed, 16 insertions, 7 deletions
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<dyn Error>)
- .and_then(|_| nibble::Ast::parse(input.chars().peekable()).map_err(|e| Box::new(e) as Box<dyn Error>))
+ .and_then(|_| {
+ IterWrapper::new(input.chars())
+ .parse::<nibble::Ast>()
+ .map_err(|e| Box::new(e) as Box<dyn Error>)
+ })
.and_then(|ast| {
write!(io::stdout(), "{:?}", ast).map_err(|e| Box::new(e) as Box<dyn Error>)
});
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);