|
|
@ -126,15 +126,6 @@ impl FromStr for Term { |
|
|
|
/// Term::from_str("\"ex\"").unwrap(),
|
|
|
|
/// Term::from_str("\"ex\"").unwrap(),
|
|
|
|
/// Literal::new_simple_literal("ex").into()
|
|
|
|
/// Literal::new_simple_literal("ex").into()
|
|
|
|
/// );
|
|
|
|
/// );
|
|
|
|
/// assert_eq!(
|
|
|
|
|
|
|
|
/// Term::from_str("<< _:s <http://example.com/p> \"o\" >>").unwrap(),
|
|
|
|
|
|
|
|
/// Triple::new(
|
|
|
|
|
|
|
|
/// BlankNode::new("s").unwrap(),
|
|
|
|
|
|
|
|
/// NamedNode::new("http://example.com/p").unwrap(),
|
|
|
|
|
|
|
|
/// Literal::new_simple_literal("o")
|
|
|
|
|
|
|
|
/// )
|
|
|
|
|
|
|
|
/// .into()
|
|
|
|
|
|
|
|
/// );
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> { |
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> { |
|
|
|
let (term, left) = read_term(s, 0)?; |
|
|
|
let (term, left) = read_term(s, 0)?; |
|
|
@ -365,7 +356,7 @@ fn read_term(s: &str, number_of_recursive_calls: usize) -> Result<(Term, &str), |
|
|
|
Term::Literal(_) => { |
|
|
|
Term::Literal(_) => { |
|
|
|
return Err(TermParseError::msg( |
|
|
|
return Err(TermParseError::msg( |
|
|
|
"Literals are not allowed in subject position", |
|
|
|
"Literals are not allowed in subject position", |
|
|
|
)) |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
Term::Triple(s) => Subject::Triple(s), |
|
|
|
Term::Triple(s) => Subject::Triple(s), |
|
|
|
}, |
|
|
|
}, |
|
|
@ -409,7 +400,7 @@ fn read_hexa_char(input: &mut Chars<'_>, len: usize) -> Result<char, TermParseEr |
|
|
|
_ => { |
|
|
|
_ => { |
|
|
|
return Err(TermParseError::msg( |
|
|
|
return Err(TermParseError::msg( |
|
|
|
"Unexpected character in a unicode escape", |
|
|
|
"Unexpected character in a unicode escape", |
|
|
|
)) |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -453,3 +444,25 @@ impl TermParseError { |
|
|
|
Self(TermParseErrorKind::Msg(msg)) |
|
|
|
Self(TermParseErrorKind::Msg(msg)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(all(test, feature = "rdf-star"))] |
|
|
|
|
|
|
|
mod tests { |
|
|
|
|
|
|
|
use super::*; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn triple_term_parsing() { |
|
|
|
|
|
|
|
assert_eq!( |
|
|
|
|
|
|
|
Term::from_str("\"ex\"").unwrap(), |
|
|
|
|
|
|
|
Literal::new_simple_literal("ex").into() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
assert_eq!( |
|
|
|
|
|
|
|
Term::from_str("<< _:s <http://example.com/p> \"o\" >>").unwrap(), |
|
|
|
|
|
|
|
Triple::new( |
|
|
|
|
|
|
|
BlankNode::new("s").unwrap(), |
|
|
|
|
|
|
|
NamedNode::new("http://example.com/p").unwrap(), |
|
|
|
|
|
|
|
Literal::new_simple_literal("o"), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|