Skip to content

Commit

Permalink
Fix extra_requirement_in_impl issue
Browse files Browse the repository at this point in the history
  • Loading branch information
J-F-Liu committed Jan 20, 2017
1 parent 19c74ae commit 50594bd
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 87 deletions.
14 changes: 7 additions & 7 deletions examples/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ pub enum JsonValue {
Object(HashMap<String,JsonValue>)
}

fn space() -> Parser<u8, ()> {
fn space() -> Parser<'static, u8, ()> {
one_of(b" \t\r\n").repeat(0..).discard()
}

fn number() -> Parser<u8, f64> {
fn number() -> Parser<'static, u8, f64> {
let integer = one_of(b"123456789") - one_of(b"0123456789").repeat(0..) | sym(b'0');
let frac = sym(b'.') + one_of(b"0123456789").repeat(1..);
let exp = one_of(b"eE") + one_of(b"+-").opt() + one_of(b"0123456789").repeat(1..);
let number = sym(b'-').opt() + integer + frac.opt() + exp.opt();
number.collect().map(|v|String::from_utf8(v).unwrap()).map(|s|f64::from_str(&s).unwrap())
}

fn string() -> Parser<u8, String> {
fn string() -> Parser<'static, u8, String> {
let special_char = sym(b'\\') | sym(b'/') | sym(b'"')
| sym(b'b').map(|_|b'\x08') | sym(b'f').map(|_|b'\x0C')
| sym(b'n').map(|_|b'\n') | sym(b'r').map(|_|b'\r') | sym(b't').map(|_|b'\t');
Expand All @@ -41,20 +41,20 @@ fn string() -> Parser<u8, String> {
string.map(|strings|strings.concat())
}

fn array() -> Parser<u8, Vec<JsonValue>> {
fn array() -> Parser<'static, u8, Vec<JsonValue>> {
let elems = list(call(value), sym(b',') * space());
let arr = sym(b'[') * space() * elems.opt() - sym(b']');
arr.map(|elems|elems.unwrap_or(vec![]))
}

fn object() -> Parser<u8, HashMap<String, JsonValue>> {
fn object() -> Parser<'static, u8, HashMap<String, JsonValue>> {
let member = string() - space() - sym(b':') - space() + call(value);
let members = list(member, sym(b',') * space());
let obj = sym(b'{') * space() * members.opt() - sym(b'}');
obj.map(|members|members.unwrap_or(vec![]).into_iter().collect::<HashMap<_,_>>())
}

fn value() -> Parser<u8, JsonValue> {
fn value() -> Parser<'static, u8, JsonValue> {
( seq(b"null").map(|_|JsonValue::Null)
| seq(b"true").map(|_|JsonValue::Bool(true))
| seq(b"false").map(|_|JsonValue::Bool(false))
Expand All @@ -65,7 +65,7 @@ fn value() -> Parser<u8, JsonValue> {
) - space()
}

pub fn json() -> Parser<u8, JsonValue> {
pub fn json() -> Parser<'static, u8, JsonValue> {
space() * value() - end()
}

Expand Down
14 changes: 7 additions & 7 deletions examples/json_char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ pub enum JsonValue {
Object(HashMap<String,JsonValue>)
}

fn space() -> Parser<char, ()> {
fn space() -> Parser<'static, char, ()> {
one_of(" \t\r\n").repeat(0..).discard()
}

fn number() -> Parser<char, f64> {
fn number() -> Parser<'static, char, f64> {
let integer = one_of("123456789") - one_of("0123456789").repeat(0..) | sym('0');
let frac = sym('.') + one_of("0123456789").repeat(1..);
let exp = one_of("eE") + one_of("+-").opt() + one_of("0123456789").repeat(1..);
let number = sym('-').opt() + integer + frac.opt() + exp.opt();
number.collect().map(|v|String::from_iter(v)).map(|s|f64::from_str(&s).unwrap())
}

fn string() -> Parser<char, String> {
fn string() -> Parser<'static, char, String> {
let special_char = sym('\\') | sym('/') | sym('"')
| sym('b').map(|_|'\x08') | sym('f').map(|_|'\x0C')
| sym('n').map(|_|'\n') | sym('r').map(|_|'\r') | sym('t').map(|_|'\t');
Expand All @@ -41,20 +41,20 @@ fn string() -> Parser<char, String> {
string.map(|strings|strings.concat())
}

fn array() -> Parser<char, Vec<JsonValue>> {
fn array() -> Parser<'static, char, Vec<JsonValue>> {
let elems = list(call(value), sym(',') * space());
let arr = sym('[') * space() * elems.opt() - sym(']');
arr.map(|elems|elems.unwrap_or(vec![]))
}

fn object() -> Parser<char, HashMap<String, JsonValue>> {
fn object() -> Parser<'static, char, HashMap<String, JsonValue>> {
let member = string() - space() - sym(':') - space() + call(value);
let members = list(member, sym(',') * space());
let obj = sym('{') * space() * members.opt() - sym('}');
obj.map(|members|members.unwrap_or(vec![]).into_iter().collect::<HashMap<_,_>>())
}

fn value() -> Parser<char, JsonValue> {
fn value() -> Parser<'static, char, JsonValue> {
( seq("null").map(|_|JsonValue::Null)
| seq("true").map(|_|JsonValue::Bool(true))
| seq("false").map(|_|JsonValue::Bool(false))
Expand All @@ -65,7 +65,7 @@ fn value() -> Parser<char, JsonValue> {
) - space()
}

pub fn json() -> Parser<char, JsonValue> {
pub fn json() -> Parser<'static, char, JsonValue> {
space() * value() - end()
}

Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![feature(loop_break_value)]
#![feature(collections_range)]
#![feature(collections_bound)]
#![allow(extra_requirement_in_impl)]

mod input;
mod result;
Expand Down
Loading

0 comments on commit 50594bd

Please sign in to comment.