|
|
@ -1,8 +1,9 @@ |
|
|
|
//See https://www.w3.org/TR/turtle/#sec-grammar |
|
|
|
//See https://www.w3.org/TR/turtle/#sec-grammar |
|
|
|
|
|
|
|
|
|
|
|
use std::char; |
|
|
|
use std::char; |
|
|
|
use std::iter; |
|
|
|
use url::Url; |
|
|
|
use model::data::*; |
|
|
|
use model::data::*; |
|
|
|
|
|
|
|
use std::iter; |
|
|
|
use rio::turtle::ParserState; |
|
|
|
use rio::turtle::ParserState; |
|
|
|
|
|
|
|
|
|
|
|
#![arguments(state: &mut ParserState, buffer: &mut Vec<Triple>, data_factory: &DataFactory)] |
|
|
|
#![arguments(state: &mut ParserState, buffer: &mut Vec<Triple>, data_factory: &DataFactory)] |
|
|
@ -23,13 +24,25 @@ prefixID -> () = "@prefix" _ ns:PNAME_NS _ i:IRIREF _ "." { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//[5] |
|
|
|
//[5] |
|
|
|
base -> () = "@base" _ i:IRIREF _ "." { |
|
|
|
base -> () = "@base" _ i:IRIREF _ "." {? |
|
|
|
state.base_uri = i.into(); |
|
|
|
match Url::parse(&i) { |
|
|
|
|
|
|
|
Ok(url) => { |
|
|
|
|
|
|
|
state.base_uri = Some(url); |
|
|
|
|
|
|
|
Ok(()) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
Err(error) => Err("IRI parsing failed") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//[5s] |
|
|
|
//[5s] |
|
|
|
sparqlBase -> () = "BASE"i _ i:IRIREF { |
|
|
|
sparqlBase -> () = "BASE"i _ i:IRIREF {? |
|
|
|
state.base_uri = i.into(); |
|
|
|
match Url::parse(&i) { |
|
|
|
|
|
|
|
Ok(url) => { |
|
|
|
|
|
|
|
state.base_uri = Some(url); |
|
|
|
|
|
|
|
Ok(()) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
Err(error) => Err("IRI parsing failed") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//[6s] |
|
|
|
//[6s] |
|
|
@ -57,7 +70,7 @@ objectList -> () = object _ ("," _ object _)* |
|
|
|
|
|
|
|
|
|
|
|
//[9] |
|
|
|
//[9] |
|
|
|
verb -> NamedNode = predicate / |
|
|
|
verb -> NamedNode = predicate / |
|
|
|
"a" { data_factory.named_node("http://www.w3.org/1999/02/22-rdf-syntax-ns#type") } |
|
|
|
"a" { data_factory.named_node(Url::parse("http://www.w3.org/1999/02/22-rdf-syntax-ns#type").unwrap()) } |
|
|
|
|
|
|
|
|
|
|
|
// [10] |
|
|
|
// [10] |
|
|
|
subject -> NamedOrBlankNode = |
|
|
|
subject -> NamedOrBlankNode = |
|
|
@ -102,11 +115,13 @@ blankNodePropertyList_open -> () = "[" { |
|
|
|
|
|
|
|
|
|
|
|
//[15] |
|
|
|
//[15] |
|
|
|
collection -> NamedOrBlankNode = '(' _ o:(collection_value*) ')' { |
|
|
|
collection -> NamedOrBlankNode = '(' _ o:(collection_value*) ')' { |
|
|
|
let mut current_list_node = NamedOrBlankNode::from(data_factory.named_node("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil")); |
|
|
|
let first = data_factory.named_node(Url::parse("http://www.w3.org/1999/02/22-rdf-syntax-ns#first").unwrap()); |
|
|
|
|
|
|
|
let rest = data_factory.named_node(Url::parse("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest").unwrap()); |
|
|
|
|
|
|
|
let mut current_list_node = NamedOrBlankNode::from(data_factory.named_node(Url::parse("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil").unwrap())); |
|
|
|
for obj in o.into_iter().rev() { |
|
|
|
for obj in o.into_iter().rev() { |
|
|
|
let new_blank_node = NamedOrBlankNode::from(data_factory.new_blank_node()); |
|
|
|
let new_blank_node = NamedOrBlankNode::from(data_factory.new_blank_node()); |
|
|
|
buffer.push(data_factory.triple(new_blank_node.clone(), data_factory.named_node("http://www.w3.org/1999/02/22-rdf-syntax-ns#first"), obj)); |
|
|
|
buffer.push(data_factory.triple(new_blank_node.clone(), first.clone(), obj)); |
|
|
|
buffer.push(data_factory.triple(new_blank_node.clone(), data_factory.named_node("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"), current_list_node)); |
|
|
|
buffer.push(data_factory.triple(new_blank_node.clone(), rest.clone(), current_list_node)); |
|
|
|
current_list_node = new_blank_node; |
|
|
|
current_list_node = new_blank_node; |
|
|
|
} |
|
|
|
} |
|
|
|
current_list_node |
|
|
|
current_list_node |
|
|
@ -115,9 +130,9 @@ collection_value -> Term = o:object_value _ { o } |
|
|
|
|
|
|
|
|
|
|
|
//[16] |
|
|
|
//[16] |
|
|
|
NumericLiteral -> Literal = |
|
|
|
NumericLiteral -> Literal = |
|
|
|
d:$(DOUBLE) { data_factory.typed_literal(d, data_factory.named_node("http://www.w3.org/2001/XMLSchema#double")) } / |
|
|
|
d:$(DOUBLE) { data_factory.typed_literal(d, data_factory.named_node(Url::parse("http://www.w3.org/2001/XMLSchema#double").unwrap())) } / |
|
|
|
d:$(DECIMAL) { data_factory.typed_literal(d, data_factory.named_node("http://www.w3.org/2001/XMLSchema#decimal")) } / |
|
|
|
d:$(DECIMAL) { data_factory.typed_literal(d, data_factory.named_node(Url::parse("http://www.w3.org/2001/XMLSchema#decimal").unwrap())) } / |
|
|
|
i:$(INTEGER) { data_factory.typed_literal(i, data_factory.named_node("http://www.w3.org/2001/XMLSchema#integer")) } |
|
|
|
i:$(INTEGER) { data_factory.typed_literal(i, data_factory.named_node(Url::parse("http://www.w3.org/2001/XMLSchema#integer").unwrap())) } |
|
|
|
|
|
|
|
|
|
|
|
//[128s] |
|
|
|
//[128s] |
|
|
|
RDFLiteral -> Literal = |
|
|
|
RDFLiteral -> Literal = |
|
|
@ -127,15 +142,18 @@ RDFLiteral -> Literal = |
|
|
|
|
|
|
|
|
|
|
|
//[133s] |
|
|
|
//[133s] |
|
|
|
BooleanLiteral -> Literal = |
|
|
|
BooleanLiteral -> Literal = |
|
|
|
"true" { data_factory.typed_literal("true", data_factory.named_node("http://www.w3.org/2001/XMLSchema#boolean")) } / |
|
|
|
"true" { data_factory.typed_literal("true", data_factory.named_node(Url::parse("http://www.w3.org/2001/XMLSchema#boolean").unwrap())) } / |
|
|
|
"false" { data_factory.typed_literal("false", data_factory.named_node("http://www.w3.org/2001/XMLSchema#boolean")) } |
|
|
|
"false" { data_factory.typed_literal("false", data_factory.named_node(Url::parse("http://www.w3.org/2001/XMLSchema#boolean").unwrap())) } |
|
|
|
|
|
|
|
|
|
|
|
//[17] |
|
|
|
//[17] |
|
|
|
String -> String = STRING_LITERAL_LONG_SINGLE_QUOTE / STRING_LITERAL_LONG_QUOTE / STRING_LITERAL_QUOTE / STRING_LITERAL_SINGLE_QUOTE |
|
|
|
String -> String = STRING_LITERAL_LONG_SINGLE_QUOTE / STRING_LITERAL_LONG_QUOTE / STRING_LITERAL_QUOTE / STRING_LITERAL_SINGLE_QUOTE |
|
|
|
|
|
|
|
|
|
|
|
//[135s] |
|
|
|
//[135s] |
|
|
|
iri -> NamedNode = i:(IRIREF / PrefixedName) { |
|
|
|
iri -> NamedNode = i:(IRIREF / PrefixedName) {? |
|
|
|
data_factory.named_node(i) |
|
|
|
match state.url_parser().parse(&i) { |
|
|
|
|
|
|
|
Ok(url) => Ok(data_factory.named_node(url)), |
|
|
|
|
|
|
|
Err(error) => Err("IRI parsing failed") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//[136s] |
|
|
|
//[136s] |
|
|
@ -149,7 +167,6 @@ BlankNode -> BlankNode = |
|
|
|
|
|
|
|
|
|
|
|
//[18] |
|
|
|
//[18] |
|
|
|
IRIREF -> String = "<" i:((_IRIREF_simple_char / UCHAR)*) ">" { |
|
|
|
IRIREF -> String = "<" i:((_IRIREF_simple_char / UCHAR)*) ">" { |
|
|
|
//TODO: relative URIs resolution |
|
|
|
|
|
|
|
i.into_iter().collect() |
|
|
|
i.into_iter().collect() |
|
|
|
} |
|
|
|
} |
|
|
|
_IRIREF_simple_char -> char = c:$([^\u{00}-\u{20}<>"{}|^\u{60}\u{5c}]) { c.chars().next().unwrap() } |
|
|
|
_IRIREF_simple_char -> char = c:$([^\u{00}-\u{20}<>"{}|^\u{60}\u{5c}]) { c.chars().next().unwrap() } |
|
|
|