|
|
@ -1,8 +1,10 @@ |
|
|
|
use crate::vocab::xsd; |
|
|
|
use crate::vocab::xsd; |
|
|
|
use crate::{ |
|
|
|
use crate::{ |
|
|
|
BlankNode, BlankNodeIdParseError, IriParseError, LanguageTagParseError, Literal, NamedNode, |
|
|
|
BlankNode, BlankNodeIdParseError, IriParseError, LanguageTagParseError, Literal, NamedNode, |
|
|
|
Subject, Term, Triple, Variable, VariableNameParseError, |
|
|
|
Term, Variable, VariableNameParseError, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
#[cfg(feature = "rdf-star")] |
|
|
|
|
|
|
|
use crate::{Subject, Triple}; |
|
|
|
use std::char; |
|
|
|
use std::char; |
|
|
|
use std::error::Error; |
|
|
|
use std::error::Error; |
|
|
|
use std::fmt; |
|
|
|
use std::fmt; |
|
|
@ -298,20 +300,21 @@ fn read_literal(s: &str) -> Result<(Literal, &str), TermParseError> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn read_term(s: &str, number_of_recursive_calls: usize) -> Result<(Term, &str), TermParseError> { |
|
|
|
fn read_term(s: &str, number_of_recursive_calls: usize) -> Result<(Term, &str), TermParseError> { |
|
|
|
let s = s.trim(); |
|
|
|
|
|
|
|
if let Some(remain) = s.strip_prefix("<<") { |
|
|
|
|
|
|
|
if number_of_recursive_calls == MAX_NUMBER_OF_NESTED_TRIPLES { |
|
|
|
if number_of_recursive_calls == MAX_NUMBER_OF_NESTED_TRIPLES { |
|
|
|
return Err(TermParseError::msg( |
|
|
|
return Err(TermParseError::msg( |
|
|
|
"Too many nested triples. The parser fails here to avoid a stack overflow.", |
|
|
|
"Too many nested triples. The parser fails here to avoid a stack overflow.", |
|
|
|
)); |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
let s = s.trim(); |
|
|
|
|
|
|
|
#[allow(unused_variables)] |
|
|
|
|
|
|
|
if let Some(remain) = s.strip_prefix("<<") { |
|
|
|
|
|
|
|
#[cfg(feature = "rdf-star")] |
|
|
|
|
|
|
|
{ |
|
|
|
let (subject, remain) = read_term(remain, number_of_recursive_calls + 1)?; |
|
|
|
let (subject, remain) = read_term(remain, number_of_recursive_calls + 1)?; |
|
|
|
let (predicate, remain) = read_named_node(remain)?; |
|
|
|
let (predicate, remain) = read_named_node(remain)?; |
|
|
|
let (object, remain) = read_term(remain, number_of_recursive_calls + 1)?; |
|
|
|
let (object, remain) = read_term(remain, number_of_recursive_calls + 1)?; |
|
|
|
let remain = remain.trim_start(); |
|
|
|
let remain = remain.trim_start(); |
|
|
|
if let Some(remain) = remain.strip_prefix(">>") { |
|
|
|
if let Some(remain) = remain.strip_prefix(">>") { |
|
|
|
#[cfg(feature = "rdf-star")] |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Ok(( |
|
|
|
Ok(( |
|
|
|
Triple { |
|
|
|
Triple { |
|
|
|
subject: match subject { |
|
|
|
subject: match subject { |
|
|
@ -330,16 +333,16 @@ fn read_term(s: &str, number_of_recursive_calls: usize) -> Result<(Term, &str), |
|
|
|
.into(), |
|
|
|
.into(), |
|
|
|
remain, |
|
|
|
remain, |
|
|
|
)) |
|
|
|
)) |
|
|
|
} |
|
|
|
|
|
|
|
#[cfg(not(feature = "rdf-star"))] |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Err(TermParseError::msg("RDF-star is not supported")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Err(TermParseError::msg( |
|
|
|
Err(TermParseError::msg( |
|
|
|
"Nested triple serialization should be enclosed between << and >>", |
|
|
|
"Nested triple serialization should be enclosed between << and >>", |
|
|
|
)) |
|
|
|
)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#[cfg(not(feature = "rdf-star"))] |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Err(TermParseError::msg("RDF-star is not supported")) |
|
|
|
|
|
|
|
} |
|
|
|
} else if s.starts_with('<') { |
|
|
|
} else if s.starts_with('<') { |
|
|
|
let (term, remain) = read_named_node(s)?; |
|
|
|
let (term, remain) = read_named_node(s)?; |
|
|
|
Ok((term.into(), remain)) |
|
|
|
Ok((term.into(), remain)) |
|
|
|