Where clauses are ListPattern

pull/10/head
Tpt 7 years ago
parent 9dfe0655e3
commit a513fdb707
  1. 40
      src/sparql/algebra.rs
  2. 10
      src/sparql/sparql_grammar.rustpeg

@ -785,6 +785,15 @@ impl From<PropertyPathPattern> for MultiSetPattern {
} }
} }
impl From<ListPattern> for MultiSetPattern {
fn from(pattern: ListPattern) -> Self {
match pattern {
ListPattern::ToList(pattern) => pattern,
pattern => MultiSetPattern::ToMultiSet(Box::new(pattern)),
}
}
}
struct SparqlMultiSetPattern<'a>(&'a MultiSetPattern); struct SparqlMultiSetPattern<'a>(&'a MultiSetPattern);
impl<'a> fmt::Display for SparqlMultiSetPattern<'a> { impl<'a> fmt::Display for SparqlMultiSetPattern<'a> {
@ -874,6 +883,21 @@ pub enum ListPattern {
Slice(Box<MultiSetPattern>, usize, usize), Slice(Box<MultiSetPattern>, usize, usize),
} }
impl Default for ListPattern {
fn default() -> Self {
ListPattern::Data(Vec::default())
}
}
impl From<MultiSetPattern> for ListPattern {
fn from(pattern: MultiSetPattern) -> Self {
match pattern {
MultiSetPattern::ToMultiSet(pattern) => *pattern,
pattern => ListPattern::ToList(pattern),
}
}
}
impl fmt::Display for ListPattern { impl fmt::Display for ListPattern {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self { match self {
@ -1000,20 +1024,20 @@ pub enum Query {
SelectQuery { SelectQuery {
selection: Selection, selection: Selection,
dataset: Dataset, dataset: Dataset,
filter: MultiSetPattern, filter: ListPattern,
}, },
ConstructQuery { ConstructQuery {
construct: Vec<TriplePattern>, construct: Vec<TriplePattern>,
dataset: Dataset, dataset: Dataset,
filter: MultiSetPattern, filter: ListPattern,
}, },
DescribeQuery { DescribeQuery {
dataset: Dataset, dataset: Dataset,
filter: MultiSetPattern, filter: ListPattern,
}, },
AskQuery { AskQuery {
dataset: Dataset, dataset: Dataset,
filter: MultiSetPattern, filter: ListPattern,
}, },
} }
@ -1029,7 +1053,7 @@ impl fmt::Display for Query {
"SELECT {} {} WHERE {{ {} }}", "SELECT {} {} WHERE {{ {} }}",
selection, selection,
dataset, dataset,
SparqlMultiSetPattern(&filter) SparqlListPattern(&filter)
), ),
Query::ConstructQuery { Query::ConstructQuery {
construct, construct,
@ -1044,19 +1068,19 @@ impl fmt::Display for Query {
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join(" . "), .join(" . "),
dataset, dataset,
SparqlMultiSetPattern(&filter) SparqlListPattern(&filter)
), ),
Query::DescribeQuery { dataset, filter } => write!( Query::DescribeQuery { dataset, filter } => write!(
f, f,
"DESCRIBE {} WHERE {{ {} }}", "DESCRIBE {} WHERE {{ {} }}",
dataset, dataset,
SparqlMultiSetPattern(&filter) SparqlListPattern(&filter)
), ),
Query::AskQuery { dataset, filter } => write!( Query::AskQuery { dataset, filter } => write!(
f, f,
"ASK {} WHERE {{ {} }}", "ASK {} WHERE {{ {} }}",
dataset, dataset,
SparqlMultiSetPattern(&filter) SparqlListPattern(&filter)
), ),
} }
} }

@ -81,7 +81,7 @@ ConstructQuery -> Query =
Query::ConstructQuery { Query::ConstructQuery {
construct: c.clone(), construct: c.clone(),
dataset: d, dataset: d,
filter: MultiSetPattern::BGP(c.into_iter().map(|p| PropertyPathPattern::from(p)).collect()) filter: MultiSetPattern::BGP(c.into_iter().map(|p| PropertyPathPattern::from(p)).collect()).into()
} }
} }
@ -91,7 +91,7 @@ ConstructQuery_optional_triple_template -> Vec<TriplePattern> = TriplesTemplate
DescribeQuery -> Query = "DESCRIBE"i _ ('*' / (VarOrIri _)+) _ d:DatasetClauses f:WhereClause? _ SolutionModifier { DescribeQuery -> Query = "DESCRIBE"i _ ('*' / (VarOrIri _)+) _ d:DatasetClauses f:WhereClause? _ SolutionModifier {
Query::DescribeQuery { Query::DescribeQuery {
dataset: d, dataset: d,
filter: f.unwrap_or_else(MultiSetPattern::default) filter: f.unwrap_or_else(ListPattern::default)
} }
} }
@ -123,7 +123,9 @@ NamedGraphClause -> Dataset = "NAMED"i _ s:SourceSelector {
SourceSelector -> NamedNode = iri SourceSelector -> NamedNode = iri
//[17] //[17]
WhereClause -> MultiSetPattern = "WHERE"i? _ p:GroupGraphPattern { p } WhereClause -> ListPattern = "WHERE"i? _ p:GroupGraphPattern {
p.into()
}
//[18] //[18]
SolutionModifier -> () = GroupClause? _ HavingClause? _ OrderClause? _ LimitOffsetClauses? SolutionModifier -> () = GroupClause? _ HavingClause? _ OrderClause? _ LimitOffsetClauses?
@ -255,7 +257,7 @@ InlineData -> PartialGraphPattern = "VALUES"i _ p:DataBlock { PartialGraphPatter
//[62] //[62]
DataBlock -> MultiSetPattern = l:(InlineDataOneVar / InlineDataFull) { DataBlock -> MultiSetPattern = l:(InlineDataOneVar / InlineDataFull) {
MultiSetPattern::ToMultiSet(Box::new(ListPattern::Data(l))) ListPattern::Data(l).into()
} }
//[63] //[63]

Loading…
Cancel
Save