From 9dfe0655e35a308fd3be6932f16a7d54597454c6 Mon Sep 17 00:00:00 2001 From: Tpt Date: Tue, 19 Jun 2018 19:09:36 +0200 Subject: [PATCH] Adds Service to the algebra --- src/sparql/algebra.rs | 12 ++++++++++++ src/sparql/sparql_grammar.rustpeg | 7 +++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/sparql/algebra.rs b/src/sparql/algebra.rs index 121fba31..9b328fc1 100644 --- a/src/sparql/algebra.rs +++ b/src/sparql/algebra.rs @@ -746,6 +746,7 @@ pub enum MultiSetPattern { Extend(Box, Variable, Expression), Minus(Box, Box), ToMultiSet(Box), + Service(NamedNodeOrVariable, Box, bool), } impl fmt::Display for MultiSetPattern { @@ -767,6 +768,7 @@ impl fmt::Display for MultiSetPattern { MultiSetPattern::Extend(p, v, e) => write!(f, "Extend({}), {}, {})", p, v, e), MultiSetPattern::Minus(a, b) => write!(f, "Minus({}, {})", a, b), MultiSetPattern::ToMultiSet(l) => write!(f, "{}", l), + MultiSetPattern::Service(n, p, s) => write!(f, "Service({}, {}, {})", n, p, s), } } } @@ -844,6 +846,16 @@ impl<'a> fmt::Display for SparqlMultiSetPattern<'a> { SparqlMultiSetPattern(&*b) ), MultiSetPattern::ToMultiSet(l) => write!(f, "{}", SparqlListPattern(&l)), + MultiSetPattern::Service(n, p, s) => if *s { + write!( + f, + "SERVICE SILENT {} {{ {} }}", + n, + SparqlMultiSetPattern(&*p) + ) + } else { + write!(f, "SERVICE {} {{ {} }}", n, SparqlMultiSetPattern(&*p)) + }, } } } diff --git a/src/sparql/sparql_grammar.rustpeg b/src/sparql/sparql_grammar.rustpeg index ea1cb433..75aa466e 100644 --- a/src/sparql/sparql_grammar.rustpeg +++ b/src/sparql/sparql_grammar.rustpeg @@ -241,10 +241,9 @@ GraphGraphPattern -> PartialGraphPattern = "GRAPH"i _ g:VarOrIri _ p:GroupGraphP } //[59] -ServiceGraphPattern -> PartialGraphPattern = "SERVICE"i _ "SILENT"i? _ s:VarOrIri _ p:GroupGraphPattern { - PartialGraphPattern::Other(MultiSetPattern::default()) - //TODO PartialGraphPattern::Other(MultiSetPattern::ServicePattern(s, Box::new(p))) -} +ServiceGraphPattern -> PartialGraphPattern = + "SERVICE"i _ "SILENT"i _ s:VarOrIri _ p:GroupGraphPattern { PartialGraphPattern::Other(MultiSetPattern::Service(s, Box::new(p), true)) } / + "SERVICE"i _ s:VarOrIri _ p:GroupGraphPattern { PartialGraphPattern::Other(MultiSetPattern::Service(s, Box::new(p), false)) } //[60] Bind -> PartialGraphPattern = "BIND"i _ '(' _ e:Expression _ "AS"i _ v:Var _ ')' {