Rebase against https://github.com/mozilla/mentat/pull/402.
This is because it contains the latest version of parser and affects the structure of the code
This commit is contained in:
parent
60592a87e6
commit
649eff08a5
2 changed files with 50 additions and 61 deletions
|
@ -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>, {
|
||||
seq()
|
||||
|
@ -215,43 +231,31 @@ def_parser!(Where, or_join_clause, WhereClause, {
|
|||
}))
|
||||
});
|
||||
|
||||
def_value_parser_fn!(Where, not_clause, WhereClause, input, {
|
||||
satisfy_map(|x: edn::Value| {
|
||||
seq(x).and_then(|items| {
|
||||
let mut p = Where::not()
|
||||
.with(many1(Where::clause()))
|
||||
.skip(eof())
|
||||
.map(|clauses| {
|
||||
WhereClause::NotJoin(
|
||||
NotJoin {
|
||||
unify_vars: UnifyVars::Implicit,
|
||||
clauses: clauses,
|
||||
})
|
||||
});
|
||||
let r: ParseResult<WhereClause, _> = p.parse_lazy(&items[..]).into();
|
||||
Query::to_parsed_value(r)
|
||||
})
|
||||
}).parse_stream(input)
|
||||
def_parser!(Where, not_clause, WhereClause, {
|
||||
seq()
|
||||
.of_exactly(Where::not()
|
||||
.with(many1(Where::clause()))
|
||||
.map(|clauses| {
|
||||
WhereClause::NotJoin(
|
||||
NotJoin {
|
||||
unify_vars: UnifyVars::Implicit,
|
||||
clauses: clauses,
|
||||
})
|
||||
}))
|
||||
});
|
||||
|
||||
def_value_parser_fn!(Where, not_join_clause, WhereClause, input, {
|
||||
satisfy_map(|x: edn::Value| {
|
||||
seq(x).and_then(|items| {
|
||||
let mut p = Where::not_join()
|
||||
.with(Where::rule_vars())
|
||||
.and(many1(Where::clause()))
|
||||
.skip(eof())
|
||||
.map(|(vars, clauses)| {
|
||||
WhereClause::NotJoin(
|
||||
NotJoin {
|
||||
unify_vars: UnifyVars::Explicit(vars),
|
||||
clauses: clauses,
|
||||
})
|
||||
});
|
||||
let r: ParseResult<WhereClause, _> = p.parse_lazy(&items[..]).into();
|
||||
Query::to_parsed_value(r)
|
||||
})
|
||||
}).parse_stream(input)
|
||||
def_parser!(Where, not_join_clause, WhereClause, {
|
||||
seq()
|
||||
.of_exactly(Where::not_join()
|
||||
.with(Where::rule_vars())
|
||||
.and(many1(Where::clause()))
|
||||
.map(|(vars, clauses)| {
|
||||
WhereClause::NotJoin(
|
||||
NotJoin {
|
||||
unify_vars: UnifyVars::Explicit(vars),
|
||||
clauses: clauses,
|
||||
})
|
||||
}))
|
||||
});
|
||||
|
||||
/// A vector containing just a parenthesized filter expression.
|
||||
|
@ -689,17 +693,13 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_not() {
|
||||
let oj = edn::PlainSymbol::new("not");
|
||||
let e = edn::PlainSymbol::new("?e");
|
||||
let a = edn::PlainSymbol::new("?a");
|
||||
let v = edn::PlainSymbol::new("?v");
|
||||
let input = [edn::Value::List(
|
||||
vec![edn::Value::PlainSymbol(oj),
|
||||
edn::Value::Vector(vec![edn::Value::PlainSymbol(e.clone()),
|
||||
edn::Value::PlainSymbol(a.clone()),
|
||||
edn::Value::PlainSymbol(v.clone())])].into_iter().collect())];
|
||||
assert_parses_to!(Where::not_clause, input,
|
||||
WhereClause::NotJoin(
|
||||
|
||||
assert_edn_parses_to!(Where::not_clause,
|
||||
"(not [?e ?a ?v])",
|
||||
WhereClause::NotJoin(
|
||||
NotJoin {
|
||||
unify_vars: UnifyVars::Implicit,
|
||||
clauses: vec![
|
||||
|
@ -715,18 +715,13 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_not_join() {
|
||||
let oj = edn::PlainSymbol::new("not-join");
|
||||
let e = edn::PlainSymbol::new("?e");
|
||||
let a = edn::PlainSymbol::new("?a");
|
||||
let v = edn::PlainSymbol::new("?v");
|
||||
let input = [edn::Value::List(
|
||||
vec![edn::Value::PlainSymbol(oj),
|
||||
edn::Value::Vector(vec![edn::Value::PlainSymbol(e.clone())]),
|
||||
edn::Value::Vector(vec![edn::Value::PlainSymbol(e.clone()),
|
||||
edn::Value::PlainSymbol(a.clone()),
|
||||
edn::Value::PlainSymbol(v.clone())])].into_iter().collect())];
|
||||
assert_parses_to!(Where::not_join_clause, input,
|
||||
WhereClause::NotJoin(
|
||||
|
||||
assert_edn_parses_to!(Where::not_join_clause,
|
||||
"(not-join [?e] [?e ?a ?v])",
|
||||
WhereClause::NotJoin(
|
||||
NotJoin {
|
||||
unify_vars: UnifyVars::Explicit(vec![variable(e.clone())]),
|
||||
clauses: vec![WhereClause::Pattern(Pattern {
|
||||
|
|
|
@ -681,14 +681,8 @@ impl ContainsVariables for WhereClause {
|
|||
&OrJoin(ref o) => o.accumulate_mentioned_variables(acc),
|
||||
&Pred(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),
|
||||
&WhereFn => (),
|
||||
>>>>>>> Part 1 - Parse `not` and `not-join`
|
||||
&WhereFn(_) => (),
|
||||
&RuleExpr => (),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue