Skip to content

Commit 0fb23c2

Browse files
author
Alan Jeffrey
committed
Rewrote to address issues with lifetime polymorphism.
The problem is rust-lang/rust#30867, which means that any type that wants to be polymorphic over `I: Iterator`, and lifetime-polymorpic over `I::Item` needs to take `I::Item` as a type parameter. Concretely, this means that `Stateful<Str>` where `Str: Iterator` needs to be replaced by `Stateful<Ch, Str>` where `Str: Iterator<Item = Ch>`, and ditto the other types. While I was doing a root-and-branch rewrite, I fixed issues #4 and #5.
1 parent e349f0c commit 0fb23c2

File tree

4 files changed

+1557
-1479
lines changed

4 files changed

+1557
-1479
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "parsell"
4-
version = "0.3.2-SNAPSHOT"
4+
version = "0.4.0-SNAPSHOT"
55
authors = [ "Alan Jeffrey <[email protected]>" ]
66

77
description = "Parsell LL(1) streaming parser combinators"

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,31 @@ It is based on:
2020

2121
```rust
2222
extern crate parsell;
23-
use parsell::{character,Parser,Uncommitted,Committed,Stateful};
23+
use parsell::{character,Parser,UncommittedStr,StatefulStr};
2424
use parsell::ParseResult::{Done,Continue};
2525
#[allow(non_snake_case)]
2626
fn main() {
2727

2828
// A sequence of alphanumerics, saved in a string buffer
2929
let ALPHANUMERIC = character(char::is_alphanumeric);
30-
let ALPHANUMERICS = ALPHANUMERIC.star(String::new);
30+
let ALPHANUMERICS = ALPHANUMERIC.plus(String::new);
31+
32+
// If you provide unmatching input to the parser, you'll get back a None response:
33+
match ALPHANUMERICS.init_str("!$?") {
34+
None => (),
35+
_ => panic!("Can't happen."),
36+
}
3137

3238
// If you provide complete input to the parser, you'll get back a Done response:
33-
match ALPHANUMERICS.init().parse("abc123!") {
34-
Done("!",result) => assert_eq!(result, "abc123"),
39+
match ALPHANUMERICS.init_str("abc123!") {
40+
Some(Done(result)) => assert_eq!(result, "abc123"),
3541
_ => panic!("Can't happen."),
3642
}
3743

3844
// If you provide incomplete input to the parser, you'll get back a Continue response:
39-
match ALPHANUMERICS.init().parse("abc") {
40-
Continue("",parsing) => match parsing.parse("123!") {
41-
Done("!",result) => assert_eq!(result, "abc123"),
45+
match ALPHANUMERICS.init_str("abc") {
46+
Some(Continue(parsing)) => match parsing.more_str("123!") {
47+
Done(result) => assert_eq!(result, "abc123"),
4248
_ => panic!("Can't happen."),
4349
},
4450
_ => panic!("Can't happen."),

0 commit comments

Comments
 (0)