Applies Property Path Patterns translation

pull/10/head
Tpt 6 years ago
parent b9548e6536
commit cdafcfc2cc
  1. 36
      src/sparql/parser.rs
  2. 10
      src/sparql/sparql_grammar.rustpeg

@ -63,14 +63,38 @@ mod grammar {
PropertyPath(PropertyPath), PropertyPath(PropertyPath),
} }
fn to_triple_or_path_pattern( impl From<Variable> for VariableOrPropertyPath {
fn from(var: Variable) -> Self {
VariableOrPropertyPath::Variable(var)
}
}
impl From<PropertyPath> for VariableOrPropertyPath {
fn from(path: PropertyPath) -> Self {
VariableOrPropertyPath::PropertyPath(path)
}
}
fn add_to_triple_or_path_patterns(
s: TermOrVariable, s: TermOrVariable,
p: VariableOrPropertyPath, p: impl Into<VariableOrPropertyPath>,
o: TermOrVariable, o: TermOrVariable,
) -> TripleOrPathPattern { patterns: &mut Vec<TripleOrPathPattern>,
match p { ) {
VariableOrPropertyPath::Variable(p) => TriplePattern::new(s, p, o).into(), match p.into() {
VariableOrPropertyPath::PropertyPath(p) => PathPattern::new(s, p, o).into(), VariableOrPropertyPath::Variable(p) => {
patterns.push(TriplePattern::new(s, p, o).into())
}
VariableOrPropertyPath::PropertyPath(p) => match p {
PropertyPath::PredicatePath(p) => patterns.push(TriplePattern::new(s, p, o).into()),
PropertyPath::InversePath(p) => add_to_triple_or_path_patterns(o, *p, s, patterns),
PropertyPath::SequencePath(a, b) => {
let middle = Variable::default();
add_to_triple_or_path_patterns(s, *a, middle.clone().into(), patterns);
add_to_triple_or_path_patterns(middle.into(), *b, o, patterns);
}
p => patterns.push(PathPattern::new(s, p, o).into()),
},
} }
} }

@ -458,7 +458,7 @@ TriplesSameSubjectPath -> Vec<TripleOrPathPattern> =
let mut patterns = po.patterns; let mut patterns = po.patterns;
for (p, os) in po.focus { for (p, os) in po.focus {
for o in os { for o in os {
patterns.push(to_triple_or_path_pattern(s.clone(), p.clone(), o)) add_to_triple_or_path_patterns(s.clone(), p.clone(), o, &mut patterns);
} }
} }
patterns patterns
@ -468,7 +468,7 @@ TriplesSameSubjectPath -> Vec<TripleOrPathPattern> =
patterns.extend_from_slice(&po.patterns); patterns.extend_from_slice(&po.patterns);
for (p, os) in po.focus { for (p, os) in po.focus {
for o in os { for o in os {
patterns.push(to_triple_or_path_pattern(s.focus.clone(), p.clone(), o)) add_to_triple_or_path_patterns(s.focus.clone(), p.clone(), o, &mut patterns);
} }
} }
patterns patterns
@ -502,12 +502,12 @@ PropertyListPathNotEmpty_item_content -> FocusedTriplePattern<(VariableOrPropert
//[84] //[84]
VerbPath -> VariableOrPropertyPath = p:Path { VerbPath -> VariableOrPropertyPath = p:Path {
VariableOrPropertyPath::PropertyPath(p) p.into()
} }
//[85] //[85]
VerbSimple -> VariableOrPropertyPath = v:Var { VerbSimple -> VariableOrPropertyPath = v:Var {
VariableOrPropertyPath::Variable(v) v.into()
} }
//[86] //[86]
@ -625,7 +625,7 @@ BlankNodePropertyListPath -> FocusedTripleOrPathPattern<TermOrVariable> = '[' _
let mut bnode = TermOrVariable::from(BlankNode::default()); let mut bnode = TermOrVariable::from(BlankNode::default());
for (p, os) in po.focus { for (p, os) in po.focus {
for o in os { for o in os {
patterns.push(to_triple_or_path_pattern(bnode.clone(), p.clone(), o)); add_to_triple_or_path_patterns(bnode.clone(), p.clone(), o, &mut patterns);
} }
} }
FocusedTripleOrPathPattern { FocusedTripleOrPathPattern {

Loading…
Cancel
Save