Where clauses are ListPattern

pull/10/head
Tpt 6 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);
impl<'a> fmt::Display for SparqlMultiSetPattern<'a> {
@ -874,6 +883,21 @@ pub enum ListPattern {
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 {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
@ -1000,20 +1024,20 @@ pub enum Query {
SelectQuery {
selection: Selection,
dataset: Dataset,
filter: MultiSetPattern,
filter: ListPattern,
},
ConstructQuery {
construct: Vec<TriplePattern>,
dataset: Dataset,
filter: MultiSetPattern,
filter: ListPattern,
},
DescribeQuery {
dataset: Dataset,
filter: MultiSetPattern,
filter: ListPattern,
},
AskQuery {
dataset: Dataset,
filter: MultiSetPattern,
filter: ListPattern,
},
}
@ -1029,7 +1053,7 @@ impl fmt::Display for Query {
"SELECT {} {} WHERE {{ {} }}",
selection,
dataset,
SparqlMultiSetPattern(&filter)
SparqlListPattern(&filter)
),
Query::ConstructQuery {
construct,
@ -1044,19 +1068,19 @@ impl fmt::Display for Query {
.collect::<Vec<String>>()
.join(" . "),
dataset,
SparqlMultiSetPattern(&filter)
SparqlListPattern(&filter)
),
Query::DescribeQuery { dataset, filter } => write!(
f,
"DESCRIBE {} WHERE {{ {} }}",
dataset,
SparqlMultiSetPattern(&filter)
SparqlListPattern(&filter)
),
Query::AskQuery { dataset, filter } => write!(
f,
"ASK {} WHERE {{ {} }}",
dataset,
SparqlMultiSetPattern(&filter)
SparqlListPattern(&filter)
),
}
}

@ -81,7 +81,7 @@ ConstructQuery -> Query =
Query::ConstructQuery {
construct: c.clone(),
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 {
Query::DescribeQuery {
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
//[17]
WhereClause -> MultiSetPattern = "WHERE"i? _ p:GroupGraphPattern { p }
WhereClause -> ListPattern = "WHERE"i? _ p:GroupGraphPattern {
p.into()
}
//[18]
SolutionModifier -> () = GroupClause? _ HavingClause? _ OrderClause? _ LimitOffsetClauses?
@ -255,7 +257,7 @@ InlineData -> PartialGraphPattern = "VALUES"i _ p:DataBlock { PartialGraphPatter
//[62]
DataBlock -> MultiSetPattern = l:(InlineDataOneVar / InlineDataFull) {
MultiSetPattern::ToMultiSet(Box::new(ListPattern::Data(l)))
ListPattern::Data(l).into()
}
//[63]

Loading…
Cancel
Save