This is because it contains the latest version of parser and affects the structure of the code
This commit is contained in:
Emily Toop 2017-04-07 12:23:17 +01:00
parent 60592a87e6
commit 649eff08a5
2 changed files with 50 additions and 61 deletions

View file

@ -164,9 +164,25 @@ def_parser!(Where, or_join, edn::ValueAndSpan, {
}) })
}); });
def_matches_plain_symbol!(Where, or_join, "not"); def_parser!(Where, not, edn::ValueAndSpan, {
satisfy(|v: edn::ValueAndSpan| {
if let edn::SpannedValue::PlainSymbol(ref s) = v.inner {
s.0.as_str() == "not"
} else {
false
}
})
});
def_matches_plain_symbol!(Where, or_join, "not-join"); def_parser!(Where, not_join, edn::ValueAndSpan, {
satisfy(|v: edn::ValueAndSpan| {
if let edn::SpannedValue::PlainSymbol(ref s) = v.inner {
s.0.as_str() == "not-join"
} else {
false
}
})
});
def_parser!(Where, rule_vars, Vec<Variable>, { def_parser!(Where, rule_vars, Vec<Variable>, {
seq() seq()
@ -215,43 +231,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.
@ -689,17 +693,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![
@ -715,18 +715,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 {

View file

@ -681,14 +681,8 @@ impl ContainsVariables for WhereClause {
&OrJoin(ref o) => o.accumulate_mentioned_variables(acc), &OrJoin(ref o) => o.accumulate_mentioned_variables(acc),
&Pred(ref p) => p.accumulate_mentioned_variables(acc), &Pred(ref p) => p.accumulate_mentioned_variables(acc),
&Pattern(ref p) => p.accumulate_mentioned_variables(acc), &Pattern(ref p) => p.accumulate_mentioned_variables(acc),
<<<<<<< HEAD
&Not => (),
&NotJoin => (),
&WhereFn(_) => (),
=======
&NotJoin(ref n) => n.accumulate_mentioned_variables(acc), &NotJoin(ref n) => n.accumulate_mentioned_variables(acc),
&WhereFn => (), &WhereFn(_) => (),
>>>>>>> Part 1 - Parse `not` and `not-join`
&RuleExpr => (), &RuleExpr => (),
} }
} }