|
|
|
@ -17,13 +17,13 @@ use std::str::FromStr; |
|
|
|
|
/// Parses a SPARQL query with an optional base IRI to resolve relative IRIs in the query.
|
|
|
|
|
pub fn parse_query(query: &str, base_iri: Option<&str>) -> Result<Query, ParseError> { |
|
|
|
|
let mut state = ParserState::from_base_iri(base_iri)?; |
|
|
|
|
parser::QueryUnit(query, &mut state).map_err(|e| ParseError::Parser(e)) |
|
|
|
|
parser::QueryUnit(query, &mut state).map_err(ParseError::Parser) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Parses a SPARQL update with an optional base IRI to resolve relative IRIs in the query.
|
|
|
|
|
pub fn parse_update(update: &str, base_iri: Option<&str>) -> Result<Update, ParseError> { |
|
|
|
|
let mut state = ParserState::from_base_iri(base_iri)?; |
|
|
|
|
let operations = parser::UpdateInit(update, &mut state).map_err(|e| ParseError::Parser(e))?; |
|
|
|
|
let operations = parser::UpdateInit(update, &mut state).map_err(ParseError::Parser)?; |
|
|
|
|
Ok(Update { |
|
|
|
|
operations, |
|
|
|
|
base_iri: state.base_iri, |
|
|
|
@ -667,7 +667,7 @@ impl ParserState { |
|
|
|
|
pub(crate) fn from_base_iri(base_iri: Option<&str>) -> Result<Self, ParseError> { |
|
|
|
|
Ok(Self { |
|
|
|
|
base_iri: if let Some(base_iri) = base_iri { |
|
|
|
|
Some(Iri::parse(base_iri.to_owned()).map_err(|e| ParseError::InvalidBaseIri(e))?) |
|
|
|
|
Some(Iri::parse(base_iri.to_owned()).map_err(ParseError::InvalidBaseIri)?) |
|
|
|
|
} else { |
|
|
|
|
None |
|
|
|
|
}, |
|
|
|
|