Rebase against rust
branch.
This commit is contained in:
parent
7eea65b3e2
commit
f7285b268b
2 changed files with 47 additions and 56 deletions
|
@ -38,8 +38,20 @@ pub type ResultParser<O, I> = Expected<FnParser<I, fn(I) -> ParseResult<O, I>>>;
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! assert_parses_to {
|
macro_rules! assert_parses_to {
|
||||||
( $parser: expr, $input: expr, $expected: expr ) => {{
|
( $parser: expr, $input: expr, $expected: expr ) => {{
|
||||||
let mut par = $parser();
|
let par = $parser();
|
||||||
let result = par.parse($input.with_spans().into_atom_stream()).map(|x| x.0); // TODO: check remainder of stream.
|
let result = par.skip(eof()).parse($input.with_spans().into_atom_stream()).map(|x| x.0);
|
||||||
|
assert_eq!(result, Ok($expected));
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `assert_edn_parses_to!` simplifies some of the boilerplate around running a parser function
|
||||||
|
/// against string input and expecting a certain result.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! assert_edn_parses_to {
|
||||||
|
( $parser: expr, $input: expr, $expected: expr ) => {{
|
||||||
|
let par = $parser();
|
||||||
|
let input = edn::parse::value($input).expect("to be able to parse input as EDN");
|
||||||
|
let result = par.skip(eof()).parse(input.into_atom_stream()).map(|x| x.0);
|
||||||
assert_eq!(result, Ok($expected));
|
assert_eq!(result, Ok($expected));
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,9 +136,9 @@ def_matches_plain_symbol!(Where, or, "or");
|
||||||
|
|
||||||
def_matches_plain_symbol!(Where, or_join, "or-join");
|
def_matches_plain_symbol!(Where, or_join, "or-join");
|
||||||
|
|
||||||
def_matches_plain_symbol!(Where, or_join, "not");
|
def_matches_plain_symbol!(Where, not, "not");
|
||||||
|
|
||||||
def_matches_plain_symbol!(Where, or_join, "not-join");
|
def_matches_plain_symbol!(Where, not_join, "not-join");
|
||||||
|
|
||||||
def_parser!(Where, rule_vars, Vec<Variable>, {
|
def_parser!(Where, rule_vars, Vec<Variable>, {
|
||||||
seq()
|
seq()
|
||||||
|
@ -187,43 +187,31 @@ def_parser!(Where, or_join_clause, WhereClause, {
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
|
|
||||||
def_value_parser_fn!(Where, not_clause, WhereClause, input, {
|
def_parser!(Where, not_clause, WhereClause, {
|
||||||
satisfy_map(|x: edn::Value| {
|
seq()
|
||||||
seq(x).and_then(|items| {
|
.of_exactly(Where::not()
|
||||||
let mut p = Where::not()
|
.with(many1(Where::clause()))
|
||||||
.with(many1(Where::clause()))
|
.map(|clauses| {
|
||||||
.skip(eof())
|
WhereClause::NotJoin(
|
||||||
.map(|clauses| {
|
NotJoin {
|
||||||
WhereClause::NotJoin(
|
unify_vars: UnifyVars::Implicit,
|
||||||
NotJoin {
|
clauses: clauses,
|
||||||
unify_vars: UnifyVars::Implicit,
|
})
|
||||||
clauses: clauses,
|
}))
|
||||||
})
|
|
||||||
});
|
|
||||||
let r: ParseResult<WhereClause, _> = p.parse_lazy(&items[..]).into();
|
|
||||||
Query::to_parsed_value(r)
|
|
||||||
})
|
|
||||||
}).parse_stream(input)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
def_value_parser_fn!(Where, not_join_clause, WhereClause, input, {
|
def_parser!(Where, not_join_clause, WhereClause, {
|
||||||
satisfy_map(|x: edn::Value| {
|
seq()
|
||||||
seq(x).and_then(|items| {
|
.of_exactly(Where::not_join()
|
||||||
let mut p = Where::not_join()
|
.with(Where::rule_vars())
|
||||||
.with(Where::rule_vars())
|
.and(many1(Where::clause()))
|
||||||
.and(many1(Where::clause()))
|
.map(|(vars, clauses)| {
|
||||||
.skip(eof())
|
WhereClause::NotJoin(
|
||||||
.map(|(vars, clauses)| {
|
NotJoin {
|
||||||
WhereClause::NotJoin(
|
unify_vars: UnifyVars::Explicit(vars),
|
||||||
NotJoin {
|
clauses: clauses,
|
||||||
unify_vars: UnifyVars::Explicit(vars),
|
})
|
||||||
clauses: clauses,
|
}))
|
||||||
})
|
|
||||||
});
|
|
||||||
let r: ParseResult<WhereClause, _> = p.parse_lazy(&items[..]).into();
|
|
||||||
Query::to_parsed_value(r)
|
|
||||||
})
|
|
||||||
}).parse_stream(input)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/// A vector containing just a parenthesized filter expression.
|
/// A vector containing just a parenthesized filter expression.
|
||||||
|
@ -596,17 +584,13 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_not() {
|
fn test_not() {
|
||||||
let oj = edn::PlainSymbol::new("not");
|
|
||||||
let e = edn::PlainSymbol::new("?e");
|
let e = edn::PlainSymbol::new("?e");
|
||||||
let a = edn::PlainSymbol::new("?a");
|
let a = edn::PlainSymbol::new("?a");
|
||||||
let v = edn::PlainSymbol::new("?v");
|
let v = edn::PlainSymbol::new("?v");
|
||||||
let input = [edn::Value::List(
|
|
||||||
vec![edn::Value::PlainSymbol(oj),
|
assert_edn_parses_to!(Where::not_clause,
|
||||||
edn::Value::Vector(vec![edn::Value::PlainSymbol(e.clone()),
|
"(not [?e ?a ?v])",
|
||||||
edn::Value::PlainSymbol(a.clone()),
|
WhereClause::NotJoin(
|
||||||
edn::Value::PlainSymbol(v.clone())])].into_iter().collect())];
|
|
||||||
assert_parses_to!(Where::not_clause, input,
|
|
||||||
WhereClause::NotJoin(
|
|
||||||
NotJoin {
|
NotJoin {
|
||||||
unify_vars: UnifyVars::Implicit,
|
unify_vars: UnifyVars::Implicit,
|
||||||
clauses: vec![
|
clauses: vec![
|
||||||
|
@ -622,18 +606,13 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_not_join() {
|
fn test_not_join() {
|
||||||
let oj = edn::PlainSymbol::new("not-join");
|
|
||||||
let e = edn::PlainSymbol::new("?e");
|
let e = edn::PlainSymbol::new("?e");
|
||||||
let a = edn::PlainSymbol::new("?a");
|
let a = edn::PlainSymbol::new("?a");
|
||||||
let v = edn::PlainSymbol::new("?v");
|
let v = edn::PlainSymbol::new("?v");
|
||||||
let input = [edn::Value::List(
|
|
||||||
vec![edn::Value::PlainSymbol(oj),
|
assert_edn_parses_to!(Where::not_join_clause,
|
||||||
edn::Value::Vector(vec![edn::Value::PlainSymbol(e.clone())]),
|
"(not-join [?e] [?e ?a ?v])",
|
||||||
edn::Value::Vector(vec![edn::Value::PlainSymbol(e.clone()),
|
WhereClause::NotJoin(
|
||||||
edn::Value::PlainSymbol(a.clone()),
|
|
||||||
edn::Value::PlainSymbol(v.clone())])].into_iter().collect())];
|
|
||||||
assert_parses_to!(Where::not_join_clause, input,
|
|
||||||
WhereClause::NotJoin(
|
|
||||||
NotJoin {
|
NotJoin {
|
||||||
unify_vars: UnifyVars::Explicit(vec![variable(e.clone())]),
|
unify_vars: UnifyVars::Explicit(vec![variable(e.clone())]),
|
||||||
clauses: vec![WhereClause::Pattern(Pattern {
|
clauses: vec![WhereClause::Pattern(Pattern {
|
||||||
|
|
Loading…
Reference in a new issue