Created
January 31, 2017 00:40
-
-
Save rnewman/e8f23e49096b20d9d9d0ac12427e6c07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait FromValue<T> { | |
fn from_value(edn::Value) -> Option<T>; | |
} | |
impl FromValue<PatternNonValuePlace> for PatternNonValuePlace { | |
fn from_value(v: edn::Value) -> Option<PatternNonValuePlace> { | |
match v { | |
edn::Value::Integer(x) => if x >= 0 { | |
Some(PatternNonValuePlace::Entid(x as u64)) | |
} else { | |
None | |
}, | |
edn::Value::PlainSymbol(x) => if x.0.as_str() == "_" { | |
Some(PatternNonValuePlace::Placeholder) | |
} else if x.is_var_symbol() { | |
Some(PatternNonValuePlace::Variable(Variable(x))) | |
} else { | |
None | |
}, | |
edn::Value::NamespacedKeyword(x) => | |
Some(PatternNonValuePlace::Ident(x)), | |
_ => None, | |
} | |
} | |
} | |
… | |
fn pattern_non_value_place() -> ResultParser<PatternNonValuePlace, I> { | |
fn_parser(Where::<I>::pattern_non_value_place_, "pattern_non_value_place") | |
} | |
fn pattern_non_value_place_(input: I) -> ParseResult<PatternNonValuePlace, I> { | |
satisfy_map(|x: edn::Value| PatternNonValuePlace::from_value(x)).parse_stream(input) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment