Skip to content

Commit

Permalink
Rewrote to address issues with lifetime polymorphism.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Alan Jeffrey committed Feb 19, 2016
1 parent e349f0c commit 0fb23c2
Show file tree
Hide file tree
Showing 4 changed files with 1,557 additions and 1,479 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "parsell"
version = "0.3.2-SNAPSHOT"
version = "0.4.0-SNAPSHOT"
authors = [ "Alan Jeffrey <ajeffrey@mozilla.com>" ]

description = "Parsell LL(1) streaming parser combinators"
Expand Down
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,31 @@ It is based on:

```rust
extern crate parsell;
use parsell::{character,Parser,Uncommitted,Committed,Stateful};
use parsell::{character,Parser,UncommittedStr,StatefulStr};
use parsell::ParseResult::{Done,Continue};
#[allow(non_snake_case)]
fn main() {

// A sequence of alphanumerics, saved in a string buffer
let ALPHANUMERIC = character(char::is_alphanumeric);
let ALPHANUMERICS = ALPHANUMERIC.star(String::new);
let ALPHANUMERICS = ALPHANUMERIC.plus(String::new);

// If you provide unmatching input to the parser, you'll get back a None response:
match ALPHANUMERICS.init_str("!$?") {
None => (),
_ => panic!("Can't happen."),
}

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

// If you provide incomplete input to the parser, you'll get back a Continue response:
match ALPHANUMERICS.init().parse("abc") {
Continue("",parsing) => match parsing.parse("123!") {
Done("!",result) => assert_eq!(result, "abc123"),
match ALPHANUMERICS.init_str("abc") {
Some(Continue(parsing)) => match parsing.more_str("123!") {
Done(result) => assert_eq!(result, "abc123"),
_ => panic!("Can't happen."),
},
_ => panic!("Can't happen."),
Expand Down
Loading

0 comments on commit 0fb23c2

Please sign in to comment.