Optimize format performance

As seen in the https://rust.godbolt.org/z/Y8djWsq1P - write! macro produces significantly more code than a write_str call, so this change should have somewhat better performance.  To my knowledge, a lot of ppl tried to solve this optimization in the compiler, but no luck yet, so may help compiler ourselves for now.
pull/766/head
Yuri Astrakhan 9 months ago committed by Thomas Tanon
parent c0d245871c
commit 1e4326a2c5
  1. 2
      lib/oxrdf/src/blank_node.rs
  2. 2
      lib/oxrdf/src/triple.rs
  3. 2
      lib/oxrdf/src/variable.rs
  4. 2
      lib/oxrdfio/src/error.rs
  5. 14
      lib/oxsdatatypes/src/date_time.rs
  6. 10
      lib/oxsdatatypes/src/decimal.rs
  7. 16
      lib/oxsdatatypes/src/duration.rs
  8. 2
      lib/oxsdatatypes/src/integer.rs
  9. 4
      lib/oxttl/src/trig.rs
  10. 518
      lib/spargebra/src/algebra.rs
  11. 56
      lib/spargebra/src/query.rs
  12. 64
      lib/spargebra/src/term.rs
  13. 84
      lib/spargebra/src/update.rs
  14. 68
      lib/sparql-smith/src/lib.rs
  15. 6
      lib/src/sparql/error.rs
  16. 4
      testsuite/src/sparql_evaluator.rs

@ -351,7 +351,7 @@ pub struct BlankNodeIdParseError;
impl fmt::Display for BlankNodeIdParseError { impl fmt::Display for BlankNodeIdParseError {
#[inline] #[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "The blank node identifier is invalid") f.write_str("The blank node identifier is invalid")
} }
} }

@ -983,7 +983,7 @@ impl fmt::Display for GraphNameRef<'_> {
match self { match self {
Self::NamedNode(node) => node.fmt(f), Self::NamedNode(node) => node.fmt(f),
Self::BlankNode(node) => node.fmt(f), Self::BlankNode(node) => node.fmt(f),
Self::DefaultGraph => write!(f, "DEFAULT"), Self::DefaultGraph => f.write_str("DEFAULT"),
} }
} }
} }

@ -218,7 +218,7 @@ pub struct VariableNameParseError;
impl fmt::Display for VariableNameParseError { impl fmt::Display for VariableNameParseError {
#[inline] #[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "The variable name is invalid") f.write_str("The variable name is invalid")
} }
} }

@ -144,7 +144,7 @@ impl fmt::Display for SyntaxError {
match &self.inner { match &self.inner {
SyntaxErrorKind::Turtle(e) => e.fmt(f), SyntaxErrorKind::Turtle(e) => e.fmt(f),
SyntaxErrorKind::RdfXml(e) => e.fmt(f), SyntaxErrorKind::RdfXml(e) => e.fmt(f),
SyntaxErrorKind::Msg { msg } => write!(f, "{msg}"), SyntaxErrorKind::Msg { msg } => f.write_str(msg),
} }
} }
} }

@ -281,7 +281,7 @@ impl fmt::Display for DateTime {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let year = self.year(); let year = self.year();
if year < 0 { if year < 0 {
write!(f, "-")?; f.write_str("-")?;
} }
let second = self.second(); let second = self.second();
write!( write!(
@ -783,7 +783,7 @@ impl fmt::Display for Date {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let year = self.year(); let year = self.year();
if year < 0 { if year < 0 {
write!(f, "-")?; f.write_str("-")?;
} }
write!(f, "{:04}-{:02}-{:02}", year.abs(), self.month(), self.day())?; write!(f, "{:04}-{:02}-{:02}", year.abs(), self.month(), self.day())?;
if let Some(timezone_offset) = self.timezone_offset() { if let Some(timezone_offset) = self.timezone_offset() {
@ -925,7 +925,7 @@ impl fmt::Display for GYearMonth {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let year = self.year(); let year = self.year();
if year < 0 { if year < 0 {
write!(f, "-")?; f.write_str("-")?;
} }
write!(f, "{:04}-{:02}", year.abs(), self.month())?; write!(f, "{:04}-{:02}", year.abs(), self.month())?;
if let Some(timezone_offset) = self.timezone_offset() { if let Some(timezone_offset) = self.timezone_offset() {
@ -1066,7 +1066,7 @@ impl fmt::Display for GYear {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let year = self.year(); let year = self.year();
if year < 0 { if year < 0 {
write!(f, "-")?; f.write_str("-")?;
} }
write!(f, "{:04}", year.abs())?; write!(f, "{:04}", year.abs())?;
if let Some(timezone_offset) = self.timezone_offset() { if let Some(timezone_offset) = self.timezone_offset() {
@ -1544,7 +1544,7 @@ impl fmt::Display for TimezoneOffset {
#[inline] #[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.offset { match self.offset {
0 => write!(f, "Z"), 0 => f.write_str("Z"),
offset if offset < 0 => write!(f, "-{:02}:{:02}", -offset / 60, -offset % 60), offset if offset < 0 => write!(f, "-{:02}:{:02}", -offset / 60, -offset % 60),
offset => write!(f, "+{:02}:{:02}", offset / 60, offset % 60), offset => write!(f, "+{:02}:{:02}", offset / 60, offset % 60),
} }
@ -2060,7 +2060,7 @@ impl fmt::Display for ParseDateTimeError {
} }
ParseDateTimeErrorKind::Overflow(error) => error.fmt(f), ParseDateTimeErrorKind::Overflow(error) => error.fmt(f),
ParseDateTimeErrorKind::InvalidTimezone(error) => error.fmt(f), ParseDateTimeErrorKind::InvalidTimezone(error) => error.fmt(f),
ParseDateTimeErrorKind::Message(msg) => write!(f, "{msg}"), ParseDateTimeErrorKind::Message(msg) => f.write_str(msg),
} }
} }
} }
@ -2415,7 +2415,7 @@ pub struct DateTimeOverflowError;
impl fmt::Display for DateTimeOverflowError { impl fmt::Display for DateTimeOverflowError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "overflow during xsd:dateTime computation") f.write_str("overflow during xsd:dateTime computation")
} }
} }

@ -638,10 +638,10 @@ const PARSE_UNEXPECTED_END: ParseDecimalError = ParseDecimalError {
impl fmt::Display for ParseDecimalError { impl fmt::Display for ParseDecimalError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.kind { match self.kind {
DecimalParseErrorKind::Overflow => write!(f, "Value overflow"), DecimalParseErrorKind::Overflow => f.write_str("Value overflow"),
DecimalParseErrorKind::Underflow => write!(f, "Value underflow"), DecimalParseErrorKind::Underflow => f.write_str("Value underflow"),
DecimalParseErrorKind::UnexpectedChar => write!(f, "Unexpected character"), DecimalParseErrorKind::UnexpectedChar => f.write_str("Unexpected character"),
DecimalParseErrorKind::UnexpectedEnd => write!(f, "Unexpected end of string"), DecimalParseErrorKind::UnexpectedEnd => f.write_str("Unexpected end of string"),
} }
} }
} }
@ -664,7 +664,7 @@ pub struct TooLargeForDecimalError;
impl fmt::Display for TooLargeForDecimalError { impl fmt::Display for TooLargeForDecimalError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Value too large for xsd:decimal internal representation") f.write_str("Value too large for xsd:decimal internal representation")
} }
} }

@ -206,12 +206,12 @@ impl fmt::Display for Duration {
return Err(fmt::Error); // Not able to format with only a part of the duration that is negative return Err(fmt::Error); // Not able to format with only a part of the duration that is negative
} }
if ym < 0 || ss < 0.into() { if ym < 0 || ss < 0.into() {
write!(f, "-")?; f.write_str("-")?;
} }
write!(f, "P")?; f.write_str("P")?;
if ym == 0 && ss == 0.into() { if ym == 0 && ss == 0.into() {
return write!(f, "T0S"); return f.write_str("T0S");
} }
{ {
@ -245,7 +245,7 @@ impl fmt::Display for Duration {
} }
if h != 0 || m != 0 || s != 0.into() { if h != 0 || m != 0 || s != 0.into() {
write!(f, "T")?; f.write_str("T")?;
if h != 0 { if h != 0 {
write!(f, "{}H", h.abs())?; write!(f, "{}H", h.abs())?;
} }
@ -423,7 +423,7 @@ impl fmt::Display for YearMonthDuration {
#[inline] #[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.months == 0 { if self.months == 0 {
write!(f, "P0M") f.write_str("P0M")
} else { } else {
Duration::from(*self).fmt(f) Duration::from(*self).fmt(f)
} }
@ -948,7 +948,7 @@ const OVERFLOW_ERROR: ParseDurationError = ParseDurationError {
impl fmt::Display for ParseDurationError { impl fmt::Display for ParseDurationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.msg) f.write_str(self.msg)
} }
} }
@ -968,7 +968,7 @@ pub struct DurationOverflowError;
impl fmt::Display for DurationOverflowError { impl fmt::Display for DurationOverflowError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "overflow during xsd:duration computation") f.write_str("overflow during xsd:duration computation")
} }
} }
@ -980,7 +980,7 @@ pub struct OppositeSignInDurationComponentsError;
impl fmt::Display for OppositeSignInDurationComponentsError { impl fmt::Display for OppositeSignInDurationComponentsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "The xsd:yearMonthDuration and xsd:dayTimeDuration components of a xsd:duration can't have opposite sign") f.write_str("The xsd:yearMonthDuration and xsd:dayTimeDuration components of a xsd:duration can't have opposite sign")
} }
} }

@ -269,7 +269,7 @@ pub struct TooLargeForIntegerError;
impl fmt::Display for TooLargeForIntegerError { impl fmt::Display for TooLargeForIntegerError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Value too large for xsd:integer internal representation") f.write_str("Value too large for xsd:integer internal representation")
} }
} }

@ -987,7 +987,7 @@ struct TurtlePredicate<'a> {
impl<'a> fmt::Display for TurtlePredicate<'a> { impl<'a> fmt::Display for TurtlePredicate<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.named_node == rdf::TYPE { if self.named_node == rdf::TYPE {
write!(f, "a") f.write_str("a")
} else { } else {
TurtleTerm { TurtleTerm {
term: self.named_node.into(), term: self.named_node.into(),
@ -1027,7 +1027,7 @@ impl<'a> fmt::Display for TurtleTerm<'a> {
_ => false, _ => false,
}; };
if inline { if inline {
write!(f, "{value}") f.write_str(value)
} else if v.is_plain() { } else if v.is_plain() {
write!(f, "{v}") write!(f, "{v}")
} else { } else {

@ -23,45 +23,45 @@ impl PropertyPathExpression {
match self { match self {
Self::NamedNode(p) => write!(f, "{p}"), Self::NamedNode(p) => write!(f, "{p}"),
Self::Reverse(p) => { Self::Reverse(p) => {
write!(f, "(reverse ")?; f.write_str("(reverse ")?;
p.fmt_sse(f)?; p.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Alternative(a, b) => { Self::Alternative(a, b) => {
write!(f, "(alt ")?; f.write_str("(alt ")?;
a.fmt_sse(f)?; a.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
b.fmt_sse(f)?; b.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Sequence(a, b) => { Self::Sequence(a, b) => {
write!(f, "(seq ")?; f.write_str("(seq ")?;
a.fmt_sse(f)?; a.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
b.fmt_sse(f)?; b.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::ZeroOrMore(p) => { Self::ZeroOrMore(p) => {
write!(f, "(path* ")?; f.write_str("(path* ")?;
p.fmt_sse(f)?; p.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::OneOrMore(p) => { Self::OneOrMore(p) => {
write!(f, "(path+ ")?; f.write_str("(path+ ")?;
p.fmt_sse(f)?; p.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::ZeroOrOne(p) => { Self::ZeroOrOne(p) => {
write!(f, "(path? ")?; f.write_str("(path? ")?;
p.fmt_sse(f)?; p.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::NegatedPropertySet(p) => { Self::NegatedPropertySet(p) => {
write!(f, "(notoneof")?; f.write_str("(notoneof")?;
for p in p { for p in p {
write!(f, " {p}")?; write!(f, " {p}")?;
} }
write!(f, ")") f.write_str(")")
} }
} }
} }
@ -78,14 +78,14 @@ impl fmt::Display for PropertyPathExpression {
Self::OneOrMore(p) => write!(f, "({p})+"), Self::OneOrMore(p) => write!(f, "({p})+"),
Self::ZeroOrOne(p) => write!(f, "({p})?"), Self::ZeroOrOne(p) => write!(f, "({p})?"),
Self::NegatedPropertySet(p) => { Self::NegatedPropertySet(p) => {
write!(f, "!(")?; f.write_str("!(")?;
for (i, c) in p.iter().enumerate() { for (i, c) in p.iter().enumerate() {
if i > 0 { if i > 0 {
write!(f, " | ")?; f.write_str(" | ")?;
} }
write!(f, "{c}")?; write!(f, "{c}")?;
} }
write!(f, ")") f.write_str(")")
} }
} }
} }
@ -161,13 +161,13 @@ impl Expression {
Self::Less(a, b) => fmt_sse_binary_expression(f, "<", a, b), Self::Less(a, b) => fmt_sse_binary_expression(f, "<", a, b),
Self::LessOrEqual(a, b) => fmt_sse_binary_expression(f, "<=", a, b), Self::LessOrEqual(a, b) => fmt_sse_binary_expression(f, "<=", a, b),
Self::In(a, b) => { Self::In(a, b) => {
write!(f, "(in ")?; f.write_str("(in ")?;
a.fmt_sse(f)?; a.fmt_sse(f)?;
for p in b { for p in b {
write!(f, " ")?; f.write_str(" ")?;
p.fmt_sse(f)?; p.fmt_sse(f)?;
} }
write!(f, ")") f.write_str(")")
} }
Self::Add(a, b) => fmt_sse_binary_expression(f, "+", a, b), Self::Add(a, b) => fmt_sse_binary_expression(f, "+", a, b),
Self::Subtract(a, b) => fmt_sse_binary_expression(f, "-", a, b), Self::Subtract(a, b) => fmt_sse_binary_expression(f, "-", a, b),
@ -177,38 +177,38 @@ impl Expression {
Self::UnaryMinus(e) => fmt_sse_unary_expression(f, "-", e), Self::UnaryMinus(e) => fmt_sse_unary_expression(f, "-", e),
Self::Not(e) => fmt_sse_unary_expression(f, "!", e), Self::Not(e) => fmt_sse_unary_expression(f, "!", e),
Self::FunctionCall(function, parameters) => { Self::FunctionCall(function, parameters) => {
write!(f, "( ")?; f.write_str("( ")?;
function.fmt_sse(f)?; function.fmt_sse(f)?;
for p in parameters { for p in parameters {
write!(f, " ")?; f.write_str(" ")?;
p.fmt_sse(f)?; p.fmt_sse(f)?;
} }
write!(f, ")") f.write_str(")")
} }
Self::Exists(p) => { Self::Exists(p) => {
write!(f, "(exists ")?; f.write_str("(exists ")?;
p.fmt_sse(f)?; p.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Bound(v) => { Self::Bound(v) => {
write!(f, "(bound {v})") write!(f, "(bound {v})")
} }
Self::If(a, b, c) => { Self::If(a, b, c) => {
write!(f, "(if ")?; f.write_str("(if ")?;
a.fmt_sse(f)?; a.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
b.fmt_sse(f)?; b.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
c.fmt_sse(f)?; c.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Coalesce(parameters) => { Self::Coalesce(parameters) => {
write!(f, "(coalesce")?; f.write_str("(coalesce")?;
for p in parameters { for p in parameters {
write!(f, " ")?; f.write_str(" ")?;
p.fmt_sse(f)?; p.fmt_sse(f)?;
} }
write!(f, ")") f.write_str(")")
} }
} }
} }
@ -239,7 +239,7 @@ impl fmt::Display for Expression {
Self::In(a, b) => { Self::In(a, b) => {
write!(f, "({a} IN ")?; write!(f, "({a} IN ")?;
write_arg_list(b, f)?; write_arg_list(b, f)?;
write!(f, ")") f.write_str(")")
} }
Self::Add(a, b) => { Self::Add(a, b) => {
write!(f, "{a} + {b}") write!(f, "{a} + {b}")
@ -267,7 +267,7 @@ impl fmt::Display for Expression {
Self::Exists(p) => write!(f, "EXISTS {{ {p} }}"), Self::Exists(p) => write!(f, "EXISTS {{ {p} }}"),
Self::If(a, b, c) => write!(f, "IF({a}, {b}, {c})"), Self::If(a, b, c) => write!(f, "IF({a}, {b}, {c})"),
Self::Coalesce(parameters) => { Self::Coalesce(parameters) => {
write!(f, "COALESCE")?; f.write_str("COALESCE")?;
write_arg_list(parameters, f) write_arg_list(parameters, f)
} }
} }
@ -305,16 +305,16 @@ fn write_arg_list(
params: impl IntoIterator<Item = impl fmt::Display>, params: impl IntoIterator<Item = impl fmt::Display>,
f: &mut fmt::Formatter<'_>, f: &mut fmt::Formatter<'_>,
) -> fmt::Result { ) -> fmt::Result {
write!(f, "(")?; f.write_str("(")?;
let mut cont = false; let mut cont = false;
for p in params { for p in params {
if cont { if cont {
write!(f, ", ")?; f.write_str(", ")?;
} }
p.fmt(f)?; p.fmt(f)?;
cont = true; cont = true;
} }
write!(f, ")") f.write_str(")")
} }
/// A function name. /// A function name.
@ -385,64 +385,64 @@ impl Function {
/// Formats using the [SPARQL S-Expression syntax](https://jena.apache.org/documentation/notes/sse.html). /// Formats using the [SPARQL S-Expression syntax](https://jena.apache.org/documentation/notes/sse.html).
pub(crate) fn fmt_sse(&self, f: &mut impl fmt::Write) -> fmt::Result { pub(crate) fn fmt_sse(&self, f: &mut impl fmt::Write) -> fmt::Result {
match self { match self {
Self::Str => write!(f, "str"), Self::Str => f.write_str("str"),
Self::Lang => write!(f, "lang"), Self::Lang => f.write_str("lang"),
Self::LangMatches => write!(f, "langmatches"), Self::LangMatches => f.write_str("langmatches"),
Self::Datatype => write!(f, "datatype"), Self::Datatype => f.write_str("datatype"),
Self::Iri => write!(f, "iri"), Self::Iri => f.write_str("iri"),
Self::BNode => write!(f, "bnode"), Self::BNode => f.write_str("bnode"),
Self::Rand => write!(f, "rand"), Self::Rand => f.write_str("rand"),
Self::Abs => write!(f, "abs"), Self::Abs => f.write_str("abs"),
Self::Ceil => write!(f, "ceil"), Self::Ceil => f.write_str("ceil"),
Self::Floor => write!(f, "floor"), Self::Floor => f.write_str("floor"),
Self::Round => write!(f, "round"), Self::Round => f.write_str("round"),
Self::Concat => write!(f, "concat"), Self::Concat => f.write_str("concat"),
Self::SubStr => write!(f, "substr"), Self::SubStr => f.write_str("substr"),
Self::StrLen => write!(f, "strlen"), Self::StrLen => f.write_str("strlen"),
Self::Replace => write!(f, "replace"), Self::Replace => f.write_str("replace"),
Self::UCase => write!(f, "ucase"), Self::UCase => f.write_str("ucase"),
Self::LCase => write!(f, "lcase"), Self::LCase => f.write_str("lcase"),
Self::EncodeForUri => write!(f, "encode_for_uri"), Self::EncodeForUri => f.write_str("encode_for_uri"),
Self::Contains => write!(f, "contains"), Self::Contains => f.write_str("contains"),
Self::StrStarts => write!(f, "strstarts"), Self::StrStarts => f.write_str("strstarts"),
Self::StrEnds => write!(f, "strends"), Self::StrEnds => f.write_str("strends"),
Self::StrBefore => write!(f, "strbefore"), Self::StrBefore => f.write_str("strbefore"),
Self::StrAfter => write!(f, "strafter"), Self::StrAfter => f.write_str("strafter"),
Self::Year => write!(f, "year"), Self::Year => f.write_str("year"),
Self::Month => write!(f, "month"), Self::Month => f.write_str("month"),
Self::Day => write!(f, "day"), Self::Day => f.write_str("day"),
Self::Hours => write!(f, "hours"), Self::Hours => f.write_str("hours"),
Self::Minutes => write!(f, "minutes"), Self::Minutes => f.write_str("minutes"),
Self::Seconds => write!(f, "seconds"), Self::Seconds => f.write_str("seconds"),
Self::Timezone => write!(f, "timezone"), Self::Timezone => f.write_str("timezone"),
Self::Tz => write!(f, "tz"), Self::Tz => f.write_str("tz"),
Self::Now => write!(f, "now"), Self::Now => f.write_str("now"),
Self::Uuid => write!(f, "uuid"), Self::Uuid => f.write_str("uuid"),
Self::StrUuid => write!(f, "struuid"), Self::StrUuid => f.write_str("struuid"),
Self::Md5 => write!(f, "md5"), Self::Md5 => f.write_str("md5"),
Self::Sha1 => write!(f, "sha1"), Self::Sha1 => f.write_str("sha1"),
Self::Sha256 => write!(f, "sha256"), Self::Sha256 => f.write_str("sha256"),
Self::Sha384 => write!(f, "sha384"), Self::Sha384 => f.write_str("sha384"),
Self::Sha512 => write!(f, "sha512"), Self::Sha512 => f.write_str("sha512"),
Self::StrLang => write!(f, "strlang"), Self::StrLang => f.write_str("strlang"),
Self::StrDt => write!(f, "strdt"), Self::StrDt => f.write_str("strdt"),
Self::IsIri => write!(f, "isiri"), Self::IsIri => f.write_str("isiri"),
Self::IsBlank => write!(f, "isblank"), Self::IsBlank => f.write_str("isblank"),
Self::IsLiteral => write!(f, "isliteral"), Self::IsLiteral => f.write_str("isliteral"),
Self::IsNumeric => write!(f, "isnumeric"), Self::IsNumeric => f.write_str("isnumeric"),
Self::Regex => write!(f, "regex"), Self::Regex => f.write_str("regex"),
#[cfg(feature = "rdf-star")] #[cfg(feature = "rdf-star")]
Self::Triple => write!(f, "triple"), Self::Triple => f.write_str("triple"),
#[cfg(feature = "rdf-star")] #[cfg(feature = "rdf-star")]
Self::Subject => write!(f, "subject"), Self::Subject => f.write_str("subject"),
#[cfg(feature = "rdf-star")] #[cfg(feature = "rdf-star")]
Self::Predicate => write!(f, "predicate"), Self::Predicate => f.write_str("predicate"),
#[cfg(feature = "rdf-star")] #[cfg(feature = "rdf-star")]
Self::Object => write!(f, "object"), Self::Object => f.write_str("object"),
#[cfg(feature = "rdf-star")] #[cfg(feature = "rdf-star")]
Self::IsTriple => write!(f, "istriple"), Self::IsTriple => f.write_str("istriple"),
#[cfg(feature = "sep-0002")] #[cfg(feature = "sep-0002")]
Self::Adjust => write!(f, "adjust"), Self::Adjust => f.write_str("adjust"),
Self::Custom(iri) => write!(f, "{iri}"), Self::Custom(iri) => write!(f, "{iri}"),
} }
} }
@ -451,64 +451,64 @@ impl Function {
impl fmt::Display for Function { impl fmt::Display for Function {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::Str => write!(f, "STR"), Self::Str => f.write_str("STR"),
Self::Lang => write!(f, "LANG"), Self::Lang => f.write_str("LANG"),
Self::LangMatches => write!(f, "LANGMATCHES"), Self::LangMatches => f.write_str("LANGMATCHES"),
Self::Datatype => write!(f, "DATATYPE"), Self::Datatype => f.write_str("DATATYPE"),
Self::Iri => write!(f, "IRI"), Self::Iri => f.write_str("IRI"),
Self::BNode => write!(f, "BNODE"), Self::BNode => f.write_str("BNODE"),
Self::Rand => write!(f, "RAND"), Self::Rand => f.write_str("RAND"),
Self::Abs => write!(f, "ABS"), Self::Abs => f.write_str("ABS"),
Self::Ceil => write!(f, "CEIL"), Self::Ceil => f.write_str("CEIL"),
Self::Floor => write!(f, "FLOOR"), Self::Floor => f.write_str("FLOOR"),
Self::Round => write!(f, "ROUND"), Self::Round => f.write_str("ROUND"),
Self::Concat => write!(f, "CONCAT"), Self::Concat => f.write_str("CONCAT"),
Self::SubStr => write!(f, "SUBSTR"), Self::SubStr => f.write_str("SUBSTR"),
Self::StrLen => write!(f, "STRLEN"), Self::StrLen => f.write_str("STRLEN"),
Self::Replace => write!(f, "REPLACE"), Self::Replace => f.write_str("REPLACE"),
Self::UCase => write!(f, "UCASE"), Self::UCase => f.write_str("UCASE"),
Self::LCase => write!(f, "LCASE"), Self::LCase => f.write_str("LCASE"),
Self::EncodeForUri => write!(f, "ENCODE_FOR_URI"), Self::EncodeForUri => f.write_str("ENCODE_FOR_URI"),
Self::Contains => write!(f, "CONTAINS"), Self::Contains => f.write_str("CONTAINS"),
Self::StrStarts => write!(f, "STRSTARTS"), Self::StrStarts => f.write_str("STRSTARTS"),
Self::StrEnds => write!(f, "STRENDS"), Self::StrEnds => f.write_str("STRENDS"),
Self::StrBefore => write!(f, "STRBEFORE"), Self::StrBefore => f.write_str("STRBEFORE"),
Self::StrAfter => write!(f, "STRAFTER"), Self::StrAfter => f.write_str("STRAFTER"),
Self::Year => write!(f, "YEAR"), Self::Year => f.write_str("YEAR"),
Self::Month => write!(f, "MONTH"), Self::Month => f.write_str("MONTH"),
Self::Day => write!(f, "DAY"), Self::Day => f.write_str("DAY"),
Self::Hours => write!(f, "HOURS"), Self::Hours => f.write_str("HOURS"),
Self::Minutes => write!(f, "MINUTES"), Self::Minutes => f.write_str("MINUTES"),
Self::Seconds => write!(f, "SECONDS"), Self::Seconds => f.write_str("SECONDS"),
Self::Timezone => write!(f, "TIMEZONE"), Self::Timezone => f.write_str("TIMEZONE"),
Self::Tz => write!(f, "TZ"), Self::Tz => f.write_str("TZ"),
Self::Now => write!(f, "NOW"), Self::Now => f.write_str("NOW"),
Self::Uuid => write!(f, "UUID"), Self::Uuid => f.write_str("UUID"),
Self::StrUuid => write!(f, "STRUUID"), Self::StrUuid => f.write_str("STRUUID"),
Self::Md5 => write!(f, "MD5"), Self::Md5 => f.write_str("MD5"),
Self::Sha1 => write!(f, "SHA1"), Self::Sha1 => f.write_str("SHA1"),
Self::Sha256 => write!(f, "SHA256"), Self::Sha256 => f.write_str("SHA256"),
Self::Sha384 => write!(f, "SHA384"), Self::Sha384 => f.write_str("SHA384"),
Self::Sha512 => write!(f, "SHA512"), Self::Sha512 => f.write_str("SHA512"),
Self::StrLang => write!(f, "STRLANG"), Self::StrLang => f.write_str("STRLANG"),
Self::StrDt => write!(f, "STRDT"), Self::StrDt => f.write_str("STRDT"),
Self::IsIri => write!(f, "isIRI"), Self::IsIri => f.write_str("isIRI"),
Self::IsBlank => write!(f, "isBLANK"), Self::IsBlank => f.write_str("isBLANK"),
Self::IsLiteral => write!(f, "isLITERAL"), Self::IsLiteral => f.write_str("isLITERAL"),
Self::IsNumeric => write!(f, "isNUMERIC"), Self::IsNumeric => f.write_str("isNUMERIC"),
Self::Regex => write!(f, "REGEX"), Self::Regex => f.write_str("REGEX"),
#[cfg(feature = "rdf-star")] #[cfg(feature = "rdf-star")]
Self::Triple => write!(f, "TRIPLE"), Self::Triple => f.write_str("TRIPLE"),
#[cfg(feature = "rdf-star")] #[cfg(feature = "rdf-star")]
Self::Subject => write!(f, "SUBJECT"), Self::Subject => f.write_str("SUBJECT"),
#[cfg(feature = "rdf-star")] #[cfg(feature = "rdf-star")]
Self::Predicate => write!(f, "PREDICATE"), Self::Predicate => f.write_str("PREDICATE"),
#[cfg(feature = "rdf-star")] #[cfg(feature = "rdf-star")]
Self::Object => write!(f, "OBJECT"), Self::Object => f.write_str("OBJECT"),
#[cfg(feature = "rdf-star")] #[cfg(feature = "rdf-star")]
Self::IsTriple => write!(f, "isTRIPLE"), Self::IsTriple => f.write_str("isTRIPLE"),
#[cfg(feature = "sep-0002")] #[cfg(feature = "sep-0002")]
Self::Adjust => write!(f, "ADJUST"), Self::Adjust => f.write_str("ADJUST"),
Self::Custom(iri) => iri.fmt(f), Self::Custom(iri) => iri.fmt(f),
} }
} }
@ -665,29 +665,29 @@ impl fmt::Display for GraphPattern {
variables, variables,
bindings, bindings,
} => { } => {
write!(f, "VALUES ( ")?; f.write_str("VALUES ( ")?;
for var in variables { for var in variables {
write!(f, "{var} ")?; write!(f, "{var} ")?;
} }
write!(f, ") {{ ")?; f.write_str(") { ")?;
for row in bindings { for row in bindings {
write!(f, "( ")?; f.write_str("( ")?;
for val in row { for val in row {
match val { match val {
Some(val) => write!(f, "{val} "), Some(val) => write!(f, "{val} "),
None => write!(f, "UNDEF "), None => f.write_str("UNDEF "),
}?; }?;
} }
write!(f, ") ")?; f.write_str(") ")?;
} }
write!(f, " }}") f.write_str(" }")
} }
Self::Group { Self::Group {
inner, inner,
variables, variables,
aggregates, aggregates,
} => { } => {
write!(f, "{{SELECT")?; f.write_str("{SELECT")?;
for (a, v) in aggregates { for (a, v) in aggregates {
write!(f, " ({v} AS {a})")?; write!(f, " ({v} AS {a})")?;
} }
@ -696,12 +696,12 @@ impl fmt::Display for GraphPattern {
} }
write!(f, " WHERE {{ {inner} }}")?; write!(f, " WHERE {{ {inner} }}")?;
if !variables.is_empty() { if !variables.is_empty() {
write!(f, " GROUP BY")?; f.write_str(" GROUP BY")?;
for v in variables { for v in variables {
write!(f, " {v}")?; write!(f, " {v}")?;
} }
} }
write!(f, "}}") f.write_str("}")
} }
p => write!( p => write!(
f, f,
@ -728,76 +728,76 @@ impl GraphPattern {
pub(crate) fn fmt_sse(&self, f: &mut impl fmt::Write) -> fmt::Result { pub(crate) fn fmt_sse(&self, f: &mut impl fmt::Write) -> fmt::Result {
match self { match self {
Self::Bgp { patterns } => { Self::Bgp { patterns } => {
write!(f, "(bgp")?; f.write_str("(bgp")?;
for pattern in patterns { for pattern in patterns {
write!(f, " ")?; f.write_str(" ")?;
pattern.fmt_sse(f)?; pattern.fmt_sse(f)?;
} }
write!(f, ")") f.write_str(")")
} }
Self::Path { Self::Path {
subject, subject,
path, path,
object, object,
} => { } => {
write!(f, "(path ")?; f.write_str("(path ")?;
subject.fmt_sse(f)?; subject.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
path.fmt_sse(f)?; path.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
object.fmt_sse(f)?; object.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Join { left, right } => { Self::Join { left, right } => {
write!(f, "(join ")?; f.write_str("(join ")?;
left.fmt_sse(f)?; left.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
right.fmt_sse(f)?; right.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::LeftJoin { Self::LeftJoin {
left, left,
right, right,
expression, expression,
} => { } => {
write!(f, "(leftjoin ")?; f.write_str("(leftjoin ")?;
left.fmt_sse(f)?; left.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
right.fmt_sse(f)?; right.fmt_sse(f)?;
if let Some(expr) = expression { if let Some(expr) = expression {
write!(f, " ")?; f.write_str(" ")?;
expr.fmt_sse(f)?; expr.fmt_sse(f)?;
} }
write!(f, ")") f.write_str(")")
} }
#[cfg(feature = "sep-0006")] #[cfg(feature = "sep-0006")]
Self::Lateral { left, right } => { Self::Lateral { left, right } => {
write!(f, "(lateral ")?; f.write_str("(lateral ")?;
left.fmt_sse(f)?; left.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
right.fmt_sse(f)?; right.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Filter { expr, inner } => { Self::Filter { expr, inner } => {
write!(f, "(filter ")?; f.write_str("(filter ")?;
expr.fmt_sse(f)?; expr.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
inner.fmt_sse(f)?; inner.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Union { left, right } => { Self::Union { left, right } => {
write!(f, "(union ")?; f.write_str("(union ")?;
left.fmt_sse(f)?; left.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
right.fmt_sse(f)?; right.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Graph { name, inner } => { Self::Graph { name, inner } => {
write!(f, "(graph ")?; f.write_str("(graph ")?;
name.fmt_sse(f)?; name.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
inner.fmt_sse(f)?; inner.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Extend { Self::Extend {
inner, inner,
@ -806,109 +806,109 @@ impl GraphPattern {
} => { } => {
write!(f, "(extend (({variable} ")?; write!(f, "(extend (({variable} ")?;
expression.fmt_sse(f)?; expression.fmt_sse(f)?;
write!(f, ")) ")?; f.write_str(")) ")?;
inner.fmt_sse(f)?; inner.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Minus { left, right } => { Self::Minus { left, right } => {
write!(f, "(minus ")?; f.write_str("(minus ")?;
left.fmt_sse(f)?; left.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
right.fmt_sse(f)?; right.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Service { Self::Service {
name, name,
inner, inner,
silent, silent,
} => { } => {
write!(f, "(service ")?; f.write_str("(service ")?;
if *silent { if *silent {
write!(f, "silent ")?; f.write_str("silent ")?;
} }
name.fmt_sse(f)?; name.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
inner.fmt_sse(f)?; inner.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Group { Self::Group {
inner, inner,
variables, variables,
aggregates, aggregates,
} => { } => {
write!(f, "(group (")?; f.write_str("(group (")?;
for (i, v) in variables.iter().enumerate() { for (i, v) in variables.iter().enumerate() {
if i > 0 { if i > 0 {
write!(f, " ")?; f.write_str(" ")?;
} }
write!(f, "{v}")?; write!(f, "{v}")?;
} }
write!(f, ") (")?; f.write_str(") (")?;
for (i, (v, a)) in aggregates.iter().enumerate() { for (i, (v, a)) in aggregates.iter().enumerate() {
if i > 0 { if i > 0 {
write!(f, " ")?; f.write_str(" ")?;
} }
write!(f, "(")?; f.write_str("(")?;
a.fmt_sse(f)?; a.fmt_sse(f)?;
write!(f, " {v})")?; write!(f, " {v})")?;
} }
write!(f, ") ")?; f.write_str(") ")?;
inner.fmt_sse(f)?; inner.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Values { Self::Values {
variables, variables,
bindings, bindings,
} => { } => {
write!(f, "(table (vars")?; f.write_str("(table (vars")?;
for var in variables { for var in variables {
write!(f, " {var}")?; write!(f, " {var}")?;
} }
write!(f, ")")?; f.write_str(")")?;
for row in bindings { for row in bindings {
write!(f, " (row")?; f.write_str(" (row")?;
for (value, var) in row.iter().zip(variables) { for (value, var) in row.iter().zip(variables) {
if let Some(value) = value { if let Some(value) = value {
write!(f, " ({var} {value})")?; write!(f, " ({var} {value})")?;
} }
} }
write!(f, ")")?; f.write_str(")")?;
} }
write!(f, ")") f.write_str(")")
} }
Self::OrderBy { inner, expression } => { Self::OrderBy { inner, expression } => {
write!(f, "(order (")?; f.write_str("(order (")?;
for (i, c) in expression.iter().enumerate() { for (i, c) in expression.iter().enumerate() {
if i > 0 { if i > 0 {
write!(f, " ")?; f.write_str(" ")?;
} }
c.fmt_sse(f)?; c.fmt_sse(f)?;
} }
write!(f, ") ")?; f.write_str(") ")?;
inner.fmt_sse(f)?; inner.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Project { inner, variables } => { Self::Project { inner, variables } => {
write!(f, "(project (")?; f.write_str("(project (")?;
for (i, v) in variables.iter().enumerate() { for (i, v) in variables.iter().enumerate() {
if i > 0 { if i > 0 {
write!(f, " ")?; f.write_str(" ")?;
} }
write!(f, "{v}")?; write!(f, "{v}")?;
} }
write!(f, ") ")?; f.write_str(") ")?;
inner.fmt_sse(f)?; inner.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Distinct { inner } => { Self::Distinct { inner } => {
write!(f, "(distinct ")?; f.write_str("(distinct ")?;
inner.fmt_sse(f)?; inner.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Reduced { inner } => { Self::Reduced { inner } => {
write!(f, "(reduced ")?; f.write_str("(reduced ")?;
inner.fmt_sse(f)?; inner.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Slice { Self::Slice {
inner, inner,
@ -921,7 +921,7 @@ impl GraphPattern {
write!(f, "(slice {start} _ ")?; write!(f, "(slice {start} _ ")?;
} }
inner.fmt_sse(f)?; inner.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
} }
} }
@ -1074,15 +1074,15 @@ impl<'a> fmt::Display for SparqlGraphRootPattern<'a> {
child = inner; child = inner;
} }
p => { p => {
write!(f, "SELECT")?; f.write_str("SELECT")?;
if distinct { if distinct {
write!(f, " DISTINCT")?; f.write_str(" DISTINCT")?;
} }
if reduced { if reduced {
write!(f, " REDUCED")?; f.write_str(" REDUCED")?;
} }
if project.is_empty() { if project.is_empty() {
write!(f, " *")?; f.write_str(" *")?;
} else { } else {
for v in project { for v in project {
write!(f, " {v}")?; write!(f, " {v}")?;
@ -1093,7 +1093,7 @@ impl<'a> fmt::Display for SparqlGraphRootPattern<'a> {
} }
write!(f, " WHERE {{ {p} }}")?; write!(f, " WHERE {{ {p} }}")?;
if let Some(order) = order { if let Some(order) = order {
write!(f, " ORDER BY")?; f.write_str(" ORDER BY")?;
for c in order { for c in order {
write!(f, " {c}")?; write!(f, " {c}")?;
} }
@ -1128,11 +1128,11 @@ impl AggregateExpression {
pub(crate) fn fmt_sse(&self, f: &mut impl fmt::Write) -> fmt::Result { pub(crate) fn fmt_sse(&self, f: &mut impl fmt::Write) -> fmt::Result {
match self { match self {
Self::CountSolutions { distinct } => { Self::CountSolutions { distinct } => {
write!(f, "(count")?; f.write_str("(count")?;
if *distinct { if *distinct {
write!(f, " distinct")?; f.write_str(" distinct")?;
} }
write!(f, ")") f.write_str(")")
} }
Self::FunctionCall { Self::FunctionCall {
name: name:
@ -1142,9 +1142,9 @@ impl AggregateExpression {
expr, expr,
distinct, distinct,
} => { } => {
write!(f, "(group_concat ")?; f.write_str("(group_concat ")?;
if *distinct { if *distinct {
write!(f, "distinct ")?; f.write_str("distinct ")?;
} }
expr.fmt_sse(f)?; expr.fmt_sse(f)?;
write!(f, " {})", LiteralRef::new_simple_literal(separator)) write!(f, " {})", LiteralRef::new_simple_literal(separator))
@ -1154,14 +1154,14 @@ impl AggregateExpression {
expr, expr,
distinct, distinct,
} => { } => {
write!(f, "(")?; f.write_str("(")?;
name.fmt_sse(f)?; name.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
if *distinct { if *distinct {
write!(f, "distinct ")?; f.write_str("distinct ")?;
} }
expr.fmt_sse(f)?; expr.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
} }
} }
@ -1172,9 +1172,9 @@ impl fmt::Display for AggregateExpression {
match self { match self {
Self::CountSolutions { distinct } => { Self::CountSolutions { distinct } => {
if *distinct { if *distinct {
write!(f, "COUNT(DISTINCT *)") f.write_str("COUNT(DISTINCT *)")
} else { } else {
write!(f, "COUNT(*)") f.write_str("COUNT(*)")
} }
} }
Self::FunctionCall { Self::FunctionCall {
@ -1242,13 +1242,13 @@ impl AggregateFunction {
/// Formats using the [SPARQL S-Expression syntax](https://jena.apache.org/documentation/notes/sse.html). /// Formats using the [SPARQL S-Expression syntax](https://jena.apache.org/documentation/notes/sse.html).
pub(crate) fn fmt_sse(&self, f: &mut impl fmt::Write) -> fmt::Result { pub(crate) fn fmt_sse(&self, f: &mut impl fmt::Write) -> fmt::Result {
match self { match self {
Self::Count => write!(f, "count"), Self::Count => f.write_str("count"),
Self::Sum => write!(f, "sum"), Self::Sum => f.write_str("sum"),
Self::Avg => write!(f, "avg"), Self::Avg => f.write_str("avg"),
Self::Min => write!(f, "min"), Self::Min => f.write_str("min"),
Self::Max => write!(f, "max"), Self::Max => f.write_str("max"),
Self::GroupConcat { .. } => write!(f, "group_concat"), Self::GroupConcat { .. } => f.write_str("group_concat"),
Self::Sample => write!(f, "sample"), Self::Sample => f.write_str("sample"),
Self::Custom(iri) => write!(f, "{iri}"), Self::Custom(iri) => write!(f, "{iri}"),
} }
} }
@ -1257,13 +1257,13 @@ impl AggregateFunction {
impl fmt::Display for AggregateFunction { impl fmt::Display for AggregateFunction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::Count => write!(f, "COUNT"), Self::Count => f.write_str("COUNT"),
Self::Sum => write!(f, "SUM"), Self::Sum => f.write_str("SUM"),
Self::Avg => write!(f, "AVG"), Self::Avg => f.write_str("AVG"),
Self::Min => write!(f, "MIN"), Self::Min => f.write_str("MIN"),
Self::Max => write!(f, "MAX"), Self::Max => f.write_str("MAX"),
Self::GroupConcat { .. } => write!(f, "GROUP_CONCAT"), Self::GroupConcat { .. } => f.write_str("GROUP_CONCAT"),
Self::Sample => write!(f, "SAMPLE"), Self::Sample => f.write_str("SAMPLE"),
Self::Custom(iri) => iri.fmt(f), Self::Custom(iri) => iri.fmt(f),
} }
} }
@ -1283,14 +1283,14 @@ impl OrderExpression {
pub(crate) fn fmt_sse(&self, f: &mut impl fmt::Write) -> fmt::Result { pub(crate) fn fmt_sse(&self, f: &mut impl fmt::Write) -> fmt::Result {
match self { match self {
Self::Asc(e) => { Self::Asc(e) => {
write!(f, "(asc ")?; f.write_str("(asc ")?;
e.fmt_sse(f)?; e.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Desc(e) => { Self::Desc(e) => {
write!(f, "(desc ")?; f.write_str("(desc ")?;
e.fmt_sse(f)?; e.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
} }
} }
@ -1315,22 +1315,22 @@ pub struct QueryDataset {
impl QueryDataset { impl QueryDataset {
/// Formats using the [SPARQL S-Expression syntax](https://jena.apache.org/documentation/notes/sse.html). /// Formats using the [SPARQL S-Expression syntax](https://jena.apache.org/documentation/notes/sse.html).
pub(crate) fn fmt_sse(&self, f: &mut impl fmt::Write) -> fmt::Result { pub(crate) fn fmt_sse(&self, f: &mut impl fmt::Write) -> fmt::Result {
write!(f, "(")?; f.write_str("(")?;
for (i, graph_name) in self.default.iter().enumerate() { for (i, graph_name) in self.default.iter().enumerate() {
if i > 0 { if i > 0 {
write!(f, " ")?; f.write_str(" ")?;
} }
write!(f, "{graph_name}")?; write!(f, "{graph_name}")?;
} }
if let Some(named) = &self.named { if let Some(named) = &self.named {
for (i, graph_name) in named.iter().enumerate() { for (i, graph_name) in named.iter().enumerate() {
if !self.default.is_empty() || i > 0 { if !self.default.is_empty() || i > 0 {
write!(f, " ")?; f.write_str(" ")?;
} }
write!(f, "(named {graph_name})")?; write!(f, "(named {graph_name})")?;
} }
} }
write!(f, ")") f.write_str(")")
} }
} }
@ -1364,9 +1364,9 @@ impl GraphTarget {
pub(crate) fn fmt_sse(&self, f: &mut impl fmt::Write) -> fmt::Result { pub(crate) fn fmt_sse(&self, f: &mut impl fmt::Write) -> fmt::Result {
match self { match self {
Self::NamedNode(node) => write!(f, "{node}"), Self::NamedNode(node) => write!(f, "{node}"),
Self::DefaultGraph => write!(f, "default"), Self::DefaultGraph => f.write_str("default"),
Self::NamedGraphs => write!(f, "named"), Self::NamedGraphs => f.write_str("named"),
Self::AllGraphs => write!(f, "all"), Self::AllGraphs => f.write_str("all"),
} }
} }
} }
@ -1375,9 +1375,9 @@ impl fmt::Display for GraphTarget {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::NamedNode(node) => write!(f, "GRAPH {node}"), Self::NamedNode(node) => write!(f, "GRAPH {node}"),
Self::DefaultGraph => write!(f, "DEFAULT"), Self::DefaultGraph => f.write_str("DEFAULT"),
Self::NamedGraphs => write!(f, "NAMED"), Self::NamedGraphs => f.write_str("NAMED"),
Self::AllGraphs => write!(f, "ALL"), Self::AllGraphs => f.write_str("ALL"),
} }
} }
} }
@ -1401,7 +1401,7 @@ impl From<GraphName> for GraphTarget {
fn fmt_sse_unary_expression(f: &mut impl fmt::Write, name: &str, e: &Expression) -> fmt::Result { fn fmt_sse_unary_expression(f: &mut impl fmt::Write, name: &str, e: &Expression) -> fmt::Result {
write!(f, "({name} ")?; write!(f, "({name} ")?;
e.fmt_sse(f)?; e.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
#[inline] #[inline]
@ -1413,7 +1413,7 @@ fn fmt_sse_binary_expression(
) -> fmt::Result { ) -> fmt::Result {
write!(f, "({name} ")?; write!(f, "({name} ")?;
a.fmt_sse(f)?; a.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
b.fmt_sse(f)?; b.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }

@ -86,16 +86,16 @@ impl Query {
write!(f, "(base <{base_iri}> ")?; write!(f, "(base <{base_iri}> ")?;
} }
if let Some(dataset) = dataset { if let Some(dataset) = dataset {
write!(f, "(dataset ")?; f.write_str("(dataset ")?;
dataset.fmt_sse(f)?; dataset.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
} }
pattern.fmt_sse(f)?; pattern.fmt_sse(f)?;
if dataset.is_some() { if dataset.is_some() {
write!(f, ")")?; f.write_str(")")?;
} }
if base_iri.is_some() { if base_iri.is_some() {
write!(f, ")")?; f.write_str(")")?;
} }
Ok(()) Ok(())
} }
@ -108,26 +108,26 @@ impl Query {
if let Some(base_iri) = base_iri { if let Some(base_iri) = base_iri {
write!(f, "(base <{base_iri}> ")?; write!(f, "(base <{base_iri}> ")?;
} }
write!(f, "(construct (")?; f.write_str("(construct (")?;
for (i, t) in template.iter().enumerate() { for (i, t) in template.iter().enumerate() {
if i > 0 { if i > 0 {
write!(f, " ")?; f.write_str(" ")?;
} }
t.fmt_sse(f)?; t.fmt_sse(f)?;
} }
write!(f, ") ")?; f.write_str(") ")?;
if let Some(dataset) = dataset { if let Some(dataset) = dataset {
write!(f, "(dataset ")?; f.write_str("(dataset ")?;
dataset.fmt_sse(f)?; dataset.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
} }
pattern.fmt_sse(f)?; pattern.fmt_sse(f)?;
if dataset.is_some() { if dataset.is_some() {
write!(f, ")")?; f.write_str(")")?;
} }
write!(f, ")")?; f.write_str(")")?;
if base_iri.is_some() { if base_iri.is_some() {
write!(f, ")")?; f.write_str(")")?;
} }
Ok(()) Ok(())
} }
@ -139,19 +139,19 @@ impl Query {
if let Some(base_iri) = base_iri { if let Some(base_iri) = base_iri {
write!(f, "(base <{base_iri}> ")?; write!(f, "(base <{base_iri}> ")?;
} }
write!(f, "(describe ")?; f.write_str("(describe ")?;
if let Some(dataset) = dataset { if let Some(dataset) = dataset {
write!(f, "(dataset ")?; f.write_str("(dataset ")?;
dataset.fmt_sse(f)?; dataset.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
} }
pattern.fmt_sse(f)?; pattern.fmt_sse(f)?;
if dataset.is_some() { if dataset.is_some() {
write!(f, ")")?; f.write_str(")")?;
} }
write!(f, ")")?; f.write_str(")")?;
if base_iri.is_some() { if base_iri.is_some() {
write!(f, ")")?; f.write_str(")")?;
} }
Ok(()) Ok(())
} }
@ -163,19 +163,19 @@ impl Query {
if let Some(base_iri) = base_iri { if let Some(base_iri) = base_iri {
write!(f, "(base <{base_iri}> ")?; write!(f, "(base <{base_iri}> ")?;
} }
write!(f, "(ask ")?; f.write_str("(ask ")?;
if let Some(dataset) = dataset { if let Some(dataset) = dataset {
write!(f, "(dataset ")?; f.write_str("(dataset ")?;
dataset.fmt_sse(f)?; dataset.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
} }
pattern.fmt_sse(f)?; pattern.fmt_sse(f)?;
if dataset.is_some() { if dataset.is_some() {
write!(f, ")")?; f.write_str(")")?;
} }
write!(f, ")")?; f.write_str(")")?;
if base_iri.is_some() { if base_iri.is_some() {
write!(f, ")")?; f.write_str(")")?;
} }
Ok(()) Ok(())
} }
@ -212,11 +212,11 @@ impl fmt::Display for Query {
if let Some(base_iri) = base_iri { if let Some(base_iri) = base_iri {
writeln!(f, "BASE <{base_iri}>")?; writeln!(f, "BASE <{base_iri}>")?;
} }
write!(f, "CONSTRUCT {{ ")?; f.write_str("CONSTRUCT { ")?;
for triple in template { for triple in template {
write!(f, "{triple} . ")?; write!(f, "{triple} . ")?;
} }
write!(f, "}}")?; f.write_str("}")?;
if let Some(dataset) = dataset { if let Some(dataset) = dataset {
dataset.fmt(f)?; dataset.fmt(f)?;
} }
@ -237,7 +237,7 @@ impl fmt::Display for Query {
if let Some(base_iri) = base_iri { if let Some(base_iri) = base_iri {
writeln!(f, "BASE <{}>", base_iri.as_str())?; writeln!(f, "BASE <{}>", base_iri.as_str())?;
} }
write!(f, "DESCRIBE *")?; f.write_str("DESCRIBE *")?;
if let Some(dataset) = dataset { if let Some(dataset) = dataset {
dataset.fmt(f)?; dataset.fmt(f)?;
} }
@ -258,7 +258,7 @@ impl fmt::Display for Query {
if let Some(base_iri) = base_iri { if let Some(base_iri) = base_iri {
writeln!(f, "BASE <{base_iri}>")?; writeln!(f, "BASE <{base_iri}>")?;
} }
write!(f, "ASK")?; f.write_str("ASK")?;
if let Some(dataset) = dataset { if let Some(dataset) = dataset {
dataset.fmt(f)?; dataset.fmt(f)?;
} }

@ -196,7 +196,7 @@ impl GraphName {
pub(crate) fn fmt_sse(&self, f: &mut impl Write) -> fmt::Result { pub(crate) fn fmt_sse(&self, f: &mut impl Write) -> fmt::Result {
match self { match self {
Self::NamedNode(node) => write!(f, "{node}"), Self::NamedNode(node) => write!(f, "{node}"),
Self::DefaultGraph => write!(f, "default"), Self::DefaultGraph => f.write_str("default"),
} }
} }
} }
@ -206,7 +206,7 @@ impl fmt::Display for GraphName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::NamedNode(node) => node.fmt(f), Self::NamedNode(node) => node.fmt(f),
Self::DefaultGraph => write!(f, "DEFAULT"), Self::DefaultGraph => f.write_str("DEFAULT"),
} }
} }
} }
@ -261,9 +261,9 @@ impl Quad {
/// Formats using the [SPARQL S-Expression syntax](https://jena.apache.org/documentation/notes/sse.html). /// Formats using the [SPARQL S-Expression syntax](https://jena.apache.org/documentation/notes/sse.html).
pub(crate) fn fmt_sse(&self, f: &mut impl Write) -> fmt::Result { pub(crate) fn fmt_sse(&self, f: &mut impl Write) -> fmt::Result {
if self.graph_name != GraphName::DefaultGraph { if self.graph_name != GraphName::DefaultGraph {
write!(f, "(graph ")?; f.write_str("(graph ")?;
self.graph_name.fmt_sse(f)?; self.graph_name.fmt_sse(f)?;
write!(f, " (")?; f.write_str(" (")?;
} }
write!( write!(
f, f,
@ -271,7 +271,7 @@ impl Quad {
self.subject, self.predicate, self.object self.subject, self.predicate, self.object
)?; )?;
if self.graph_name != GraphName::DefaultGraph { if self.graph_name != GraphName::DefaultGraph {
write!(f, "))")?; f.write_str("))")?;
} }
Ok(()) Ok(())
} }
@ -336,9 +336,9 @@ impl GroundQuad {
/// Formats using the [SPARQL S-Expression syntax](https://jena.apache.org/documentation/notes/sse.html). /// Formats using the [SPARQL S-Expression syntax](https://jena.apache.org/documentation/notes/sse.html).
pub(crate) fn fmt_sse(&self, f: &mut impl Write) -> fmt::Result { pub(crate) fn fmt_sse(&self, f: &mut impl Write) -> fmt::Result {
if self.graph_name != GraphName::DefaultGraph { if self.graph_name != GraphName::DefaultGraph {
write!(f, "(graph ")?; f.write_str("(graph ")?;
self.graph_name.fmt_sse(f)?; self.graph_name.fmt_sse(f)?;
write!(f, " (")?; f.write_str(" (")?;
} }
write!( write!(
f, f,
@ -346,7 +346,7 @@ impl GroundQuad {
self.subject, self.predicate, self.object self.subject, self.predicate, self.object
)?; )?;
if self.graph_name != GraphName::DefaultGraph { if self.graph_name != GraphName::DefaultGraph {
write!(f, "))")?; f.write_str("))")?;
} }
Ok(()) Ok(())
} }
@ -712,7 +712,7 @@ impl GraphNamePattern {
pub(crate) fn fmt_sse(&self, f: &mut impl Write) -> fmt::Result { pub(crate) fn fmt_sse(&self, f: &mut impl Write) -> fmt::Result {
match self { match self {
Self::NamedNode(node) => write!(f, "{node}"), Self::NamedNode(node) => write!(f, "{node}"),
Self::DefaultGraph => write!(f, "default"), Self::DefaultGraph => f.write_str("default"),
Self::Variable(var) => write!(f, "{var}"), Self::Variable(var) => write!(f, "{var}"),
} }
} }
@ -723,7 +723,7 @@ impl fmt::Display for GraphNamePattern {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::NamedNode(node) => node.fmt(f), Self::NamedNode(node) => node.fmt(f),
Self::DefaultGraph => write!(f, "DEFAULT"), Self::DefaultGraph => f.write_str("DEFAULT"),
Self::Variable(var) => var.fmt(f), Self::Variable(var) => var.fmt(f),
} }
} }
@ -786,13 +786,13 @@ impl TriplePattern {
/// Formats using the [SPARQL S-Expression syntax](https://jena.apache.org/documentation/notes/sse.html). /// Formats using the [SPARQL S-Expression syntax](https://jena.apache.org/documentation/notes/sse.html).
pub(crate) fn fmt_sse(&self, f: &mut impl Write) -> fmt::Result { pub(crate) fn fmt_sse(&self, f: &mut impl Write) -> fmt::Result {
write!(f, "(triple ")?; f.write_str("(triple ")?;
self.subject.fmt_sse(f)?; self.subject.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
self.predicate.fmt_sse(f)?; self.predicate.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
self.object.fmt_sse(f)?; self.object.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
} }
@ -850,13 +850,13 @@ impl GroundTriplePattern {
/// Formats using the [SPARQL S-Expression syntax](https://jena.apache.org/documentation/notes/sse.html). /// Formats using the [SPARQL S-Expression syntax](https://jena.apache.org/documentation/notes/sse.html).
#[allow(dead_code)] #[allow(dead_code)]
pub(crate) fn fmt_sse(&self, f: &mut impl Write) -> fmt::Result { pub(crate) fn fmt_sse(&self, f: &mut impl Write) -> fmt::Result {
write!(f, "(triple ")?; f.write_str("(triple ")?;
self.subject.fmt_sse(f)?; self.subject.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
self.predicate.fmt_sse(f)?; self.predicate.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
self.object.fmt_sse(f)?; self.object.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
} }
@ -918,19 +918,19 @@ impl QuadPattern {
/// Formats using the [SPARQL S-Expression syntax](https://jena.apache.org/documentation/notes/sse.html). /// Formats using the [SPARQL S-Expression syntax](https://jena.apache.org/documentation/notes/sse.html).
pub(crate) fn fmt_sse(&self, f: &mut impl Write) -> fmt::Result { pub(crate) fn fmt_sse(&self, f: &mut impl Write) -> fmt::Result {
if self.graph_name != GraphNamePattern::DefaultGraph { if self.graph_name != GraphNamePattern::DefaultGraph {
write!(f, "(graph ")?; f.write_str("(graph ")?;
self.graph_name.fmt_sse(f)?; self.graph_name.fmt_sse(f)?;
write!(f, " (")?; f.write_str(" (")?;
} }
write!(f, "(triple ")?; f.write_str("(triple ")?;
self.subject.fmt_sse(f)?; self.subject.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
self.predicate.fmt_sse(f)?; self.predicate.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
self.object.fmt_sse(f)?; self.object.fmt_sse(f)?;
write!(f, ")")?; f.write_str(")")?;
if self.graph_name != GraphNamePattern::DefaultGraph { if self.graph_name != GraphNamePattern::DefaultGraph {
write!(f, "))")?; f.write_str("))")?;
} }
Ok(()) Ok(())
} }
@ -964,19 +964,19 @@ impl GroundQuadPattern {
/// Formats using the [SPARQL S-Expression syntax](https://jena.apache.org/documentation/notes/sse.html). /// Formats using the [SPARQL S-Expression syntax](https://jena.apache.org/documentation/notes/sse.html).
pub(crate) fn fmt_sse(&self, f: &mut impl Write) -> fmt::Result { pub(crate) fn fmt_sse(&self, f: &mut impl Write) -> fmt::Result {
if self.graph_name != GraphNamePattern::DefaultGraph { if self.graph_name != GraphNamePattern::DefaultGraph {
write!(f, "(graph ")?; f.write_str("(graph ")?;
self.graph_name.fmt_sse(f)?; self.graph_name.fmt_sse(f)?;
write!(f, " (")?; f.write_str(" (")?;
} }
write!(f, "(triple ")?; f.write_str("(triple ")?;
self.subject.fmt_sse(f)?; self.subject.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
self.predicate.fmt_sse(f)?; self.predicate.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
self.object.fmt_sse(f)?; self.object.fmt_sse(f)?;
write!(f, ")")?; f.write_str(")")?;
if self.graph_name != GraphNamePattern::DefaultGraph { if self.graph_name != GraphNamePattern::DefaultGraph {
write!(f, "))")?; f.write_str("))")?;
} }
Ok(()) Ok(())
} }

@ -42,14 +42,14 @@ impl Update {
if let Some(base_iri) = &self.base_iri { if let Some(base_iri) = &self.base_iri {
write!(f, "(base <{base_iri}> ")?; write!(f, "(base <{base_iri}> ")?;
} }
write!(f, "(update")?; f.write_str("(update")?;
for op in &self.operations { for op in &self.operations {
write!(f, " ")?; f.write_str(" ")?;
op.fmt_sse(f)?; op.fmt_sse(f)?;
} }
write!(f, ")")?; f.write_str(")")?;
if self.base_iri.is_some() { if self.base_iri.is_some() {
write!(f, ")")?; f.write_str(")")?;
} }
Ok(()) Ok(())
} }
@ -124,24 +124,24 @@ impl GraphUpdateOperation {
fn fmt_sse(&self, f: &mut impl fmt::Write) -> fmt::Result { fn fmt_sse(&self, f: &mut impl fmt::Write) -> fmt::Result {
match self { match self {
Self::InsertData { data } => { Self::InsertData { data } => {
write!(f, "(insertData (")?; f.write_str("(insertData (")?;
for (i, t) in data.iter().enumerate() { for (i, t) in data.iter().enumerate() {
if i > 0 { if i > 0 {
write!(f, " ")?; f.write_str(" ")?;
} }
t.fmt_sse(f)?; t.fmt_sse(f)?;
} }
write!(f, "))") f.write_str("))")
} }
Self::DeleteData { data } => { Self::DeleteData { data } => {
write!(f, "(deleteData (")?; f.write_str("(deleteData (")?;
for (i, t) in data.iter().enumerate() { for (i, t) in data.iter().enumerate() {
if i > 0 { if i > 0 {
write!(f, " ")?; f.write_str(" ")?;
} }
t.fmt_sse(f)?; t.fmt_sse(f)?;
} }
write!(f, "))") f.write_str("))")
} }
Self::DeleteInsert { Self::DeleteInsert {
delete, delete,
@ -149,73 +149,73 @@ impl GraphUpdateOperation {
using, using,
pattern, pattern,
} => { } => {
write!(f, "(modify ")?; f.write_str("(modify ")?;
if let Some(using) = using { if let Some(using) = using {
write!(f, " (using ")?; f.write_str(" (using ")?;
using.fmt_sse(f)?; using.fmt_sse(f)?;
write!(f, " ")?; f.write_str(" ")?;
pattern.fmt_sse(f)?; pattern.fmt_sse(f)?;
write!(f, ")")?; f.write_str(")")?;
} else { } else {
pattern.fmt_sse(f)?; pattern.fmt_sse(f)?;
} }
if !delete.is_empty() { if !delete.is_empty() {
write!(f, " (delete (")?; f.write_str(" (delete (")?;
for (i, t) in delete.iter().enumerate() { for (i, t) in delete.iter().enumerate() {
if i > 0 { if i > 0 {
write!(f, " ")?; f.write_str(" ")?;
} }
t.fmt_sse(f)?; t.fmt_sse(f)?;
} }
write!(f, "))")?; f.write_str("))")?;
} }
if !insert.is_empty() { if !insert.is_empty() {
write!(f, " (insert (")?; f.write_str(" (insert (")?;
for (i, t) in insert.iter().enumerate() { for (i, t) in insert.iter().enumerate() {
if i > 0 { if i > 0 {
write!(f, " ")?; f.write_str(" ")?;
} }
t.fmt_sse(f)?; t.fmt_sse(f)?;
} }
write!(f, "))")?; f.write_str("))")?;
} }
write!(f, ")") f.write_str(")")
} }
Self::Load { Self::Load {
silent, silent,
source, source,
destination, destination,
} => { } => {
write!(f, "(load ")?; f.write_str("(load ")?;
if *silent { if *silent {
write!(f, "silent ")?; f.write_str("silent ")?;
} }
write!(f, "{source} ")?; write!(f, "{source} ")?;
destination.fmt_sse(f)?; destination.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Clear { silent, graph } => { Self::Clear { silent, graph } => {
write!(f, "(clear ")?; f.write_str("(clear ")?;
if *silent { if *silent {
write!(f, "silent ")?; f.write_str("silent ")?;
} }
graph.fmt_sse(f)?; graph.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
Self::Create { silent, graph } => { Self::Create { silent, graph } => {
write!(f, "(create ")?; f.write_str("(create ")?;
if *silent { if *silent {
write!(f, "silent ")?; f.write_str("silent ")?;
} }
write!(f, "{graph})") write!(f, "{graph})")
} }
Self::Drop { silent, graph } => { Self::Drop { silent, graph } => {
write!(f, "(drop ")?; f.write_str("(drop ")?;
if *silent { if *silent {
write!(f, "silent ")?; f.write_str("silent ")?;
} }
graph.fmt_sse(f)?; graph.fmt_sse(f)?;
write!(f, ")") f.write_str(")")
} }
} }
} }
@ -227,12 +227,12 @@ impl fmt::Display for GraphUpdateOperation {
Self::InsertData { data } => { Self::InsertData { data } => {
writeln!(f, "INSERT DATA {{")?; writeln!(f, "INSERT DATA {{")?;
write_quads(data, f)?; write_quads(data, f)?;
write!(f, "}}") f.write_str("}")
} }
Self::DeleteData { data } => { Self::DeleteData { data } => {
writeln!(f, "DELETE DATA {{")?; writeln!(f, "DELETE DATA {{")?;
write_ground_quads(data, f)?; write_ground_quads(data, f)?;
write!(f, "}}") f.write_str("}")
} }
Self::DeleteInsert { Self::DeleteInsert {
delete, delete,
@ -278,9 +278,9 @@ impl fmt::Display for GraphUpdateOperation {
source, source,
destination, destination,
} => { } => {
write!(f, "LOAD ")?; f.write_str("LOAD ")?;
if *silent { if *silent {
write!(f, "SILENT ")?; f.write_str("SILENT ")?;
} }
write!(f, "{source}")?; write!(f, "{source}")?;
if destination != &GraphName::DefaultGraph { if destination != &GraphName::DefaultGraph {
@ -289,23 +289,23 @@ impl fmt::Display for GraphUpdateOperation {
Ok(()) Ok(())
} }
Self::Clear { silent, graph } => { Self::Clear { silent, graph } => {
write!(f, "CLEAR ")?; f.write_str("CLEAR ")?;
if *silent { if *silent {
write!(f, "SILENT ")?; f.write_str("SILENT ")?;
} }
write!(f, "{graph}") write!(f, "{graph}")
} }
Self::Create { silent, graph } => { Self::Create { silent, graph } => {
write!(f, "CREATE ")?; f.write_str("CREATE ")?;
if *silent { if *silent {
write!(f, "SILENT ")?; f.write_str("SILENT ")?;
} }
write!(f, "GRAPH {graph}") write!(f, "GRAPH {graph}")
} }
Self::Drop { silent, graph } => { Self::Drop { silent, graph } => {
write!(f, "DROP ")?; f.write_str("DROP ")?;
if *silent { if *silent {
write!(f, "SILENT ")?; f.write_str("SILENT ")?;
} }
write!(f, "{graph}") write!(f, "{graph}")
} }

@ -147,15 +147,15 @@ enum SelectProjection {
impl fmt::Display for SelectClause { impl fmt::Display for SelectClause {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "SELECT")?; f.write_str("SELECT")?;
if let Some(option) = &self.option { if let Some(option) = &self.option {
match option { match option {
SelectOption::Distinct => write!(f, " DISTINCT"), SelectOption::Distinct => f.write_str(" DISTINCT"),
SelectOption::Reduced => write!(f, " REDUCED"), SelectOption::Reduced => f.write_str(" REDUCED"),
}?; }?;
} }
match &self.values { match &self.values {
SelectValues::Star => write!(f, " *"), SelectValues::Star => f.write_str(" *"),
SelectValues::Projection { start, others } => { SelectValues::Projection { start, others } => {
for e in once(start).chain(others) { for e in once(start).chain(others) {
match e { match e {
@ -179,7 +179,7 @@ struct WhereClause {
impl fmt::Display for WhereClause { impl fmt::Display for WhereClause {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.with_where { if self.with_where {
write!(f, " WHERE ")?; f.write_str(" WHERE ")?;
} }
write!(f, "{}", self.group_graph_pattern) write!(f, "{}", self.group_graph_pattern)
} }
@ -400,12 +400,12 @@ enum GroupGraphPattern {
impl fmt::Display for GroupGraphPattern { impl fmt::Display for GroupGraphPattern {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, " {{ ")?; f.write_str(" { ")?;
match self { match self {
Self::GroupGraphPatternSub(p) => write!(f, "{p}"), Self::GroupGraphPatternSub(p) => write!(f, "{p}"),
Self::SubSelect(s) => write!(f, "{s}"), Self::SubSelect(s) => write!(f, "{s}"),
}?; }?;
write!(f, " }} ") f.write_str(" } ")
} }
} }
@ -431,7 +431,7 @@ impl fmt::Display for GroupGraphPatternSub {
for other in &self.others { for other in &self.others {
write!(f, "{}", other.start)?; write!(f, "{}", other.start)?;
if other.with_dot { if other.with_dot {
write!(f, " . ")?; f.write_str(" . ")?;
} }
if let Some(end) = &other.end { if let Some(end) = &other.end {
write!(f, "{end}")?; write!(f, "{end}")?;
@ -452,7 +452,7 @@ impl fmt::Display for TriplesBlock {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.start)?; write!(f, "{}", self.start)?;
if let Some(end) = &self.end { if let Some(end) = &self.end {
write!(f, " . ")?; f.write_str(" . ")?;
if let Some(end) = end { if let Some(end) = end {
write!(f, "{end}")?; write!(f, "{end}")?;
} }
@ -617,19 +617,19 @@ impl<'a> Arbitrary<'a> for InlineDataFull {
impl fmt::Display for InlineDataFull { impl fmt::Display for InlineDataFull {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "( ")?; f.write_str("( ")?;
for v in &self.vars { for v in &self.vars {
write!(f, " {v}")?; write!(f, " {v}")?;
} }
write!(f, " ) {{")?; f.write_str(" ) {")?;
for vs in &self.values { for vs in &self.values {
write!(f, " (")?; f.write_str(" (")?;
for v in vs { for v in vs {
write!(f, " {v}")?; write!(f, " {v}")?;
} }
write!(f, " )")?; f.write_str(" )")?;
} }
write!(f, " }}") f.write_str(" }")
} }
} }
@ -646,7 +646,7 @@ impl fmt::Display for DataBlockValue {
match self { match self {
Self::Iri(i) => write!(f, "{i}"), Self::Iri(i) => write!(f, "{i}"),
Self::Literal(l) => write!(f, "{l}"), Self::Literal(l) => write!(f, "{l}"),
Self::Undef => write!(f, "UNDEF"), Self::Undef => f.write_str("UNDEF"),
} }
} }
} }
@ -736,14 +736,14 @@ enum ArgList {
impl fmt::Display for ArgList { impl fmt::Display for ArgList {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "(")?; f.write_str("(")?;
if let Self::NotNil { start, others } = self { if let Self::NotNil { start, others } = self {
write!(f, "{start}")?; write!(f, "{start}")?;
for e in others { for e in others {
write!(f, ", {e}")?; write!(f, ", {e}")?;
} }
} }
write!(f, ")") f.write_str(")")
} }
} }
@ -755,14 +755,14 @@ struct ExpressionList {
impl fmt::Display for ExpressionList { impl fmt::Display for ExpressionList {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "(")?; f.write_str("(")?;
for (i, e) in self.inner.iter().enumerate() { for (i, e) in self.inner.iter().enumerate() {
if i > 0 { if i > 0 {
write!(f, ", ")?; f.write_str(", ")?;
} }
write!(f, "{e}")?; write!(f, "{e}")?;
} }
write!(f, ")") f.write_str(")")
} }
} }
@ -784,7 +784,7 @@ impl fmt::Display for PropertyListNotEmpty {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} {}", self.start_predicate, self.start_object)?; write!(f, "{} {}", self.start_predicate, self.start_object)?;
for other in &self.others { for other in &self.others {
write!(f, " ; ")?; f.write_str(" ; ")?;
if let Some(e) = other { if let Some(e) = other {
write!(f, "{} {}", e.predicate, e.object)?; write!(f, "{} {}", e.predicate, e.object)?;
} }
@ -804,7 +804,7 @@ impl fmt::Display for Verb {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::VarOrIri(iri) => write!(f, "{iri}"), Self::VarOrIri(iri) => write!(f, "{iri}"),
Self::A => write!(f, " a "), Self::A => f.write_str(" a "),
} }
} }
} }
@ -820,7 +820,7 @@ impl fmt::Display for ObjectList {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.start)?; write!(f, "{}", self.start)?;
for other in &self.others { for other in &self.others {
write!(f, " , ")?; f.write_str(" , ")?;
write!(f, "{other}")?; write!(f, "{other}")?;
} }
Ok(()) Ok(())
@ -906,7 +906,7 @@ impl fmt::Display for PropertyListPathNotEmpty {
}?; }?;
write!(f, "{}", self.start_object)?; write!(f, "{}", self.start_object)?;
for other in &self.others { for other in &self.others {
write!(f, " ; ")?; f.write_str(" ; ")?;
if let Some(e) = other { if let Some(e) = other {
match &e.predicate { match &e.predicate {
PropertyListPathNotEmptyVerb::VerbPath(p) => write!(f, "{p}"), PropertyListPathNotEmptyVerb::VerbPath(p) => write!(f, "{p}"),
@ -1026,9 +1026,9 @@ enum PathMod {
impl fmt::Display for PathMod { impl fmt::Display for PathMod {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::ZeroOrOne => write!(f, " ? "), Self::ZeroOrOne => f.write_str(" ? "),
Self::ZeroOrMore => write!(f, " * "), Self::ZeroOrMore => f.write_str(" * "),
Self::OneOrMore => write!(f, " + "), Self::OneOrMore => f.write_str(" + "),
} }
} }
} }
@ -1046,7 +1046,7 @@ impl fmt::Display for PathPrimary {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::Iri(iri) => write!(f, "{iri}"), Self::Iri(iri) => write!(f, "{iri}"),
Self::A => write!(f, " a "), Self::A => f.write_str(" a "),
Self::Negated(n) => write!(f, "!{n}"), Self::Negated(n) => write!(f, "!{n}"),
Self::Child(c) => write!(f, "({c})"), Self::Child(c) => write!(f, "({c})"),
} }
@ -1072,7 +1072,7 @@ impl fmt::Display for PathNegatedPropertySet {
for other in others { for other in others {
write!(f, " | {other}")?; write!(f, " | {other}")?;
} }
write!(f, " ) ") f.write_str(" ) ")
} }
} }
} }
@ -1091,9 +1091,9 @@ impl fmt::Display for PathOneInPropertySet {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::Iri(iri) => write!(f, "{iri}"), Self::Iri(iri) => write!(f, "{iri}"),
Self::A => write!(f, " a "), Self::A => f.write_str(" a "),
Self::NegatedIri(iri) => write!(f, "^{iri}"), Self::NegatedIri(iri) => write!(f, "^{iri}"),
Self::NegatedA => write!(f, " ^a "), Self::NegatedA => f.write_str(" ^a "),
} }
} }
} }
@ -1167,7 +1167,7 @@ impl fmt::Display for Collection {
for e in &self.others { for e in &self.others {
write!(f, " {e}")?; write!(f, " {e}")?;
} }
write!(f, " )") f.write_str(" )")
} }
} }
@ -1184,7 +1184,7 @@ impl fmt::Display for CollectionPath {
for e in &self.others { for e in &self.others {
write!(f, " {e}")?; write!(f, " {e}")?;
} }
write!(f, " )") f.write_str(" )")
} }
} }
@ -1289,7 +1289,7 @@ impl fmt::Display for GraphTerm {
match self { match self {
Self::Iri(iri) => write!(f, "{iri}"), Self::Iri(iri) => write!(f, "{iri}"),
Self::Literal(l) => write!(f, "{l}"), Self::Literal(l) => write!(f, "{l}"),
Self::Nil => write!(f, " () "), Self::Nil => f.write_str(" () "),
} }
} }
} }

@ -51,7 +51,9 @@ impl fmt::Display for EvaluationError {
Self::Service(error) => error.fmt(f), Self::Service(error) => error.fmt(f),
Self::GraphAlreadyExists(graph) => write!(f, "The graph {graph} already exists"), Self::GraphAlreadyExists(graph) => write!(f, "The graph {graph} already exists"),
Self::GraphDoesNotExist(graph) => write!(f, "The graph {graph} does not exist"), Self::GraphDoesNotExist(graph) => write!(f, "The graph {graph} does not exist"),
Self::UnboundService => write!(f, "The variable encoding the service name is unbound"), Self::UnboundService => {
f.write_str("The variable encoding the service name is unbound")
}
Self::UnsupportedService(service) => { Self::UnsupportedService(service) => {
write!(f, "The service {service} is not supported") write!(f, "The service {service} is not supported")
} }
@ -62,7 +64,7 @@ impl fmt::Display for EvaluationError {
f, f,
"The service is not returning solutions but a boolean or a graph" "The service is not returning solutions but a boolean or a graph"
), ),
Self::NotAGraph => write!(f, "The query results are not a RDF graph"), Self::NotAGraph => f.write_str("The query results are not a RDF graph"),
} }
} }
} }

@ -629,12 +629,12 @@ fn solutions_to_string(solutions: Vec<Vec<(Variable, Term)>>, ordered: bool) ->
.into_iter() .into_iter()
.map(|mut s| { .map(|mut s| {
let mut out = String::new(); let mut out = String::new();
write!(&mut out, "{{").unwrap(); out.write_str("{").unwrap();
s.sort_unstable_by(|(v1, _), (v2, _)| v1.cmp(v2)); s.sort_unstable_by(|(v1, _), (v2, _)| v1.cmp(v2));
for (variable, value) in s { for (variable, value) in s {
write!(&mut out, "{variable} = {value} ").unwrap(); write!(&mut out, "{variable} = {value} ").unwrap();
} }
write!(&mut out, "}}").unwrap(); out.write_str("}").unwrap();
out out
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();

Loading…
Cancel
Save