Adds From<Iri> to NamedNode

pull/588/head
Tpt 1 year ago committed by Thomas Tanon
parent b06d6506cb
commit 73af297b4c
  1. 18
      lib/oxrdf/src/named_node.rs
  2. 20
      lib/oxrdfxml/src/parser.rs
  3. 10
      lib/oxttl/src/line_formats.rs
  4. 6
      lib/oxttl/src/n3.rs
  5. 16
      lib/oxttl/src/terse.rs
  6. 2
      lib/spargebra/src/parser.rs
  7. 12
      server/src/main.rs

@ -216,3 +216,21 @@ impl PartialOrd<NamedNodeRef<'_>> for NamedNode {
self.as_ref().partial_cmp(other) self.as_ref().partial_cmp(other)
} }
} }
impl From<Iri<String>> for NamedNode {
#[inline]
fn from(iri: Iri<String>) -> Self {
Self {
iri: iri.into_inner(),
}
}
}
impl<'a> From<Iri<&'a str>> for NamedNodeRef<'a> {
#[inline]
fn from(iri: Iri<&'a str>) -> Self {
Self {
iri: iri.into_inner(),
}
}
}

@ -1157,17 +1157,15 @@ impl<R> RdfXmlReader<R> {
fn resolve(base_iri: &Option<Iri<String>>, relative_iri: String) -> Result<NamedNode, SyntaxError> { fn resolve(base_iri: &Option<Iri<String>>, relative_iri: String) -> Result<NamedNode, SyntaxError> {
if let Some(base_iri) = base_iri { if let Some(base_iri) = base_iri {
Ok(NamedNode::new_unchecked( Ok(base_iri
base_iri .resolve(&relative_iri)
.resolve(&relative_iri) .map_err(|error| SyntaxError {
.map_err(|error| SyntaxError { inner: SyntaxErrorKind::InvalidIri {
inner: SyntaxErrorKind::InvalidIri { iri: relative_iri,
iri: relative_iri, error,
error, },
}, })?
})? .into())
.into_inner(),
))
} else { } else {
NamedNode::new(relative_iri.clone()).map_err(|error| SyntaxError { NamedNode::new(relative_iri.clone()).map_err(|error| SyntaxError {
inner: SyntaxErrorKind::InvalidIri { inner: SyntaxErrorKind::InvalidIri {

@ -59,7 +59,7 @@ impl RuleRecognizer for NQuadsRecognizer {
NQuadsState::ExpectSubject => match token { NQuadsState::ExpectSubject => match token {
N3Token::IriRef(s) => { N3Token::IriRef(s) => {
self.subjects self.subjects
.push(NamedNode::new_unchecked(s.into_inner()).into()); .push(NamedNode::from(s).into());
self.stack.push(NQuadsState::ExpectPredicate); self.stack.push(NQuadsState::ExpectPredicate);
self self
} }
@ -82,7 +82,7 @@ impl RuleRecognizer for NQuadsRecognizer {
NQuadsState::ExpectPredicate => match token { NQuadsState::ExpectPredicate => match token {
N3Token::IriRef(p) => { N3Token::IriRef(p) => {
self.predicates self.predicates
.push(NamedNode::new_unchecked(p.into_inner())); .push(p.into());
self.stack.push(NQuadsState::ExpectedObject); self.stack.push(NQuadsState::ExpectedObject);
self self
} }
@ -94,7 +94,7 @@ impl RuleRecognizer for NQuadsRecognizer {
NQuadsState::ExpectedObject => match token { NQuadsState::ExpectedObject => match token {
N3Token::IriRef(o) => { N3Token::IriRef(o) => {
self.objects self.objects
.push(NamedNode::new_unchecked(o.into_inner()).into()); .push(NamedNode::from(o).into());
self.stack self.stack
.push(NQuadsState::ExpectPossibleGraphOrEndOfQuotedTriple); .push(NQuadsState::ExpectPossibleGraphOrEndOfQuotedTriple);
self self
@ -151,7 +151,7 @@ impl RuleRecognizer for NQuadsRecognizer {
self.objects.push( self.objects.push(
Literal::new_typed_literal( Literal::new_typed_literal(
value, value,
NamedNode::new_unchecked(d.into_inner()), d
) )
.into(), .into(),
); );
@ -167,7 +167,7 @@ impl RuleRecognizer for NQuadsRecognizer {
N3Token::IriRef(g) if self.with_graph_name => { N3Token::IriRef(g) if self.with_graph_name => {
self.emit_quad( self.emit_quad(
results, results,
NamedNode::new_unchecked(g.into_inner()).into(), NamedNode::from(g).into(),
); );
self.stack.push(NQuadsState::ExpectDot); self.stack.push(NQuadsState::ExpectDot);
self self

@ -778,7 +778,7 @@ impl RuleRecognizer for N3Recognizer {
N3State::PathItem => { N3State::PathItem => {
match token { match token {
N3Token::IriRef(iri) => { N3Token::IriRef(iri) => {
self.terms.push(NamedNode::new_unchecked(iri.into_inner()).into()); self.terms.push(NamedNode::from(iri).into());
self self
} }
N3Token::PrefixedName { prefix, local, might_be_invalid_iri } => match resolve_local_name(prefix, &local, might_be_invalid_iri, &self.prefixes) { N3Token::PrefixedName { prefix, local, might_be_invalid_iri } => match resolve_local_name(prefix, &local, might_be_invalid_iri, &self.prefixes) {
@ -860,7 +860,7 @@ impl RuleRecognizer for N3Recognizer {
} }
N3State::IriPropertyList => match token { N3State::IriPropertyList => match token {
N3Token::IriRef(id) => { N3Token::IriRef(id) => {
self.terms.push(NamedNode::new_unchecked(id.into_inner()).into()); self.terms.push(NamedNode::from(id).into());
self.stack.push(N3State::PropertyListEnd); self.stack.push(N3State::PropertyListEnd);
self.stack.push(N3State::PredicateObjectList); self.stack.push(N3State::PredicateObjectList);
self self
@ -940,7 +940,7 @@ impl RuleRecognizer for N3Recognizer {
N3State::LiteralExpectDatatype { value } => { N3State::LiteralExpectDatatype { value } => {
match token { match token {
N3Token::IriRef(datatype) => { N3Token::IriRef(datatype) => {
self.terms.push(Literal::new_typed_literal(value, NamedNode::new_unchecked(datatype.into_inner())).into()); self.terms.push(Literal::new_typed_literal(value, datatype).into());
self self
}, },
N3Token::PrefixedName { prefix, local, might_be_invalid_iri } => match resolve_local_name(prefix, &local, might_be_invalid_iri, &self.prefixes) { N3Token::PrefixedName { prefix, local, might_be_invalid_iri } => match resolve_local_name(prefix, &local, might_be_invalid_iri, &self.prefixes) {

@ -127,7 +127,7 @@ impl RuleRecognizer for TriGRecognizer {
TriGState::TriplesOrGraph => match token { TriGState::TriplesOrGraph => match token {
N3Token::IriRef(iri) => { N3Token::IriRef(iri) => {
self.stack.push(TriGState::WrappedGraphOrPredicateObjectList { self.stack.push(TriGState::WrappedGraphOrPredicateObjectList {
term: NamedNode::new_unchecked(iri.into_inner()).into() term: NamedNode::from(iri).into()
}); });
self self
} }
@ -291,7 +291,7 @@ impl RuleRecognizer for TriGRecognizer {
self self
} }
N3Token::IriRef(iri) => { N3Token::IriRef(iri) => {
self.cur_subject.push(NamedNode::new_unchecked(iri.into_inner()).into()); self.cur_subject.push(NamedNode::from(iri).into());
self.stack.push(TriGState::PredicateObjectList); self.stack.push(TriGState::PredicateObjectList);
self self
} }
@ -337,7 +337,7 @@ impl RuleRecognizer for TriGRecognizer {
// [7g] labelOrSubject ::= iri | BlankNode // [7g] labelOrSubject ::= iri | BlankNode
TriGState::GraphName => match token { TriGState::GraphName => match token {
N3Token::IriRef(iri) => { N3Token::IriRef(iri) => {
self.cur_graph = NamedNode::new_unchecked(iri.into_inner()).into(); self.cur_graph = NamedNode::from(iri).into();
self self
} }
N3Token::PrefixedName { prefix, local, might_be_invalid_iri } => match resolve_local_name(prefix, &local, might_be_invalid_iri, &self.prefixes) { N3Token::PrefixedName { prefix, local, might_be_invalid_iri } => match resolve_local_name(prefix, &local, might_be_invalid_iri, &self.prefixes) {
@ -451,7 +451,7 @@ impl RuleRecognizer for TriGRecognizer {
self self
} }
N3Token::IriRef(iri) => { N3Token::IriRef(iri) => {
self.cur_predicate.push(NamedNode::new_unchecked(iri.into_inner())); self.cur_predicate.push(NamedNode::from(iri));
self self
} }
N3Token::PrefixedName { prefix, local, might_be_invalid_iri } => match resolve_local_name(prefix, &local, might_be_invalid_iri, &self.prefixes) { N3Token::PrefixedName { prefix, local, might_be_invalid_iri } => match resolve_local_name(prefix, &local, might_be_invalid_iri, &self.prefixes) {
@ -479,7 +479,7 @@ impl RuleRecognizer for TriGRecognizer {
// [137s] BlankNode ::= BLANK_NODE_LABEL | ANON // [137s] BlankNode ::= BLANK_NODE_LABEL | ANON
TriGState::Object => match token { TriGState::Object => match token {
N3Token::IriRef(iri) => { N3Token::IriRef(iri) => {
self.cur_object.push(NamedNode::new_unchecked(iri.into_inner()).into()); self.cur_object.push(NamedNode::from(iri).into());
self.emit_quad(results); self.emit_quad(results);
self self
} }
@ -632,7 +632,7 @@ impl RuleRecognizer for TriGRecognizer {
TriGState::LiteralExpectDatatype { value, emit } => { TriGState::LiteralExpectDatatype { value, emit } => {
match token { match token {
N3Token::IriRef(datatype) => { N3Token::IriRef(datatype) => {
self.cur_object.push(Literal::new_typed_literal(value, NamedNode::new_unchecked(datatype.into_inner())).into()); self.cur_object.push(Literal::new_typed_literal(value, datatype).into());
if emit { if emit {
self.emit_quad(results); self.emit_quad(results);
} }
@ -694,7 +694,7 @@ impl RuleRecognizer for TriGRecognizer {
self self
} }
N3Token::IriRef(iri) => { N3Token::IriRef(iri) => {
self.cur_subject.push(NamedNode::new_unchecked(iri.into_inner()).into()); self.cur_subject.push(NamedNode::from(iri).into());
self self
} }
N3Token::PrefixedName { prefix, local, might_be_invalid_iri } => match resolve_local_name(prefix, &local, might_be_invalid_iri, &self.prefixes) { N3Token::PrefixedName { prefix, local, might_be_invalid_iri } => match resolve_local_name(prefix, &local, might_be_invalid_iri, &self.prefixes) {
@ -726,7 +726,7 @@ impl RuleRecognizer for TriGRecognizer {
self self
} }
N3Token::IriRef(iri) => { N3Token::IriRef(iri) => {
self.cur_object.push(NamedNode::new_unchecked(iri.into_inner()).into()); self.cur_object.push(NamedNode::from(iri).into());
self self
} }
N3Token::PrefixedName { prefix, local, might_be_invalid_iri } => match resolve_local_name(prefix, &local, might_be_invalid_iri, &self.prefixes) { N3Token::PrefixedName { prefix, local, might_be_invalid_iri } => match resolve_local_name(prefix, &local, might_be_invalid_iri, &self.prefixes) {

@ -1975,7 +1975,7 @@ parser! {
rule String() -> String = STRING_LITERAL_LONG1() / STRING_LITERAL_LONG2() / STRING_LITERAL1() / STRING_LITERAL2() rule String() -> String = STRING_LITERAL_LONG1() / STRING_LITERAL_LONG2() / STRING_LITERAL1() / STRING_LITERAL2()
rule iri() -> NamedNode = i:(IRIREF() / PrefixedName()) { rule iri() -> NamedNode = i:(IRIREF() / PrefixedName()) {
NamedNode::new_unchecked(i.into_inner()) NamedNode::from(i)
} }
rule PrefixedName() -> Iri<String> = PNAME_LN() / rule PrefixedName() -> Iri<String> = PNAME_LN() /

@ -1102,13 +1102,11 @@ fn base_url(request: &Request) -> String {
} }
fn resolve_with_base(request: &Request, url: &str) -> Result<NamedNode, HttpError> { fn resolve_with_base(request: &Request, url: &str) -> Result<NamedNode, HttpError> {
Ok(NamedNode::new_unchecked( Ok(Iri::parse(base_url(request))
Iri::parse(base_url(request)) .map_err(bad_request)?
.map_err(bad_request)? .resolve(url)
.resolve(url) .map_err(bad_request)?
.map_err(bad_request)? .into())
.into_inner(),
))
} }
fn url_query(request: &Request) -> &[u8] { fn url_query(request: &Request) -> &[u8] {

Loading…
Cancel
Save