summaryrefslogtreecommitdiff
path: root/tests/sexpr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/sexpr.rs')
-rw-r--r--tests/sexpr.rs23
1 files changed, 10 insertions, 13 deletions
diff --git a/tests/sexpr.rs b/tests/sexpr.rs
index a3783f0..fa69610 100644
--- a/tests/sexpr.rs
+++ b/tests/sexpr.rs
@@ -1,8 +1,8 @@
#![allow(dead_code)]
use mon::{
- Parser, ParserIter, ascii_alpha1, ascii_alphanumeric, ascii_alphanumeric1, ascii_numeric1,
- ascii_whitespace1, input::InputIter, tag,
+ Parser, ascii_alpha1, ascii_alphanumeric, ascii_alphanumeric1, ascii_numeric1,
+ ascii_whitespace1, input::Chars, iter::ParserIter, tag,
};
#[derive(Debug)]
@@ -13,32 +13,32 @@ enum Sexpr {
Int(i64),
}
-fn atom<'a>() -> impl Parser<&'a str, Output = Sexpr> {
+fn atom<'a>() -> impl Parser<Chars<'a>, Output = Sexpr> {
ascii_alpha1()
.and(ascii_alphanumeric().repeated().many())
.recognize()
.map(|output: &str| Sexpr::Atom(output.to_string()))
}
-fn string<'a>() -> impl Parser<&'a str, Output = Sexpr> {
+fn string<'a>() -> impl Parser<Chars<'a>, Output = Sexpr> {
ascii_alphanumeric1()
.delimited_by(tag("\""), tag("\""))
.map(|output: &str| Sexpr::String(output.to_string()))
}
-fn int<'a>() -> impl Parser<&'a str, Output = Sexpr> {
+fn int<'a>() -> impl Parser<Chars<'a>, Output = Sexpr> {
ascii_numeric1().map(|output: &str| Sexpr::Int(output.parse().unwrap()))
}
// Recursive parsers must avoid an infinite loop, you can do this
// by returning a closure that accepts an InputIter and returns ParserResult.
-fn sexpr<'a>() -> impl Parser<&'a str, Output = Sexpr> {
+fn sexpr<'a>() -> impl Parser<Chars<'a>, Output = Sexpr> {
|it| {
sexpr()
.separated_by(ascii_whitespace1())
.many()
.delimited_by(tag("("), tag(")"))
- .map(|output| Sexpr::List(output))
+ .map(Sexpr::List)
.or(atom())
.or(string())
.or(int())
@@ -49,23 +49,20 @@ fn sexpr<'a>() -> impl Parser<&'a str, Output = Sexpr> {
#[test]
fn test_atom() {
let input = "atom";
- let it = InputIter::new(input);
- atom().check_finished(it).unwrap();
+ atom().check_finished(Chars::new(input)).unwrap();
}
#[test]
fn test_string() {
let input = r#""string""#;
- let it = InputIter::new(input);
- string().check_finished(it).unwrap()
+ string().check_finished(Chars::new(input)).unwrap()
}
#[test]
fn test_sexpr() {
let input = r#"(let ((a "hello") (b 2)))"#;
- let it = InputIter::new(input);
- dbg!(sexpr().parse_finished(it).unwrap());
+ dbg!(sexpr().parse_finished(Chars::new(input)).unwrap());
}