SPARQL: Fixes parsing of nested anonymous blank nodes

pull/230/head
Tpt 2 years ago committed by Thomas Tanon
parent 2db906350d
commit ba9f6528e7
  1. 8
      lib/spargebra/src/parser.rs
  2. 8
      testsuite/oxigraph-tests/sparql/manifest.ttl
  3. 5
      testsuite/oxigraph-tests/sparql/nested_anonymous.rq
  4. 13
      testsuite/oxigraph-tests/sparql/nested_anonymous.srx
  5. 4
      testsuite/oxigraph-tests/sparql/nested_anonymous.ttl

@ -128,7 +128,7 @@ impl<F> From<FocusedTriplePattern<F>> for FocusedTriplePattern<Vec<F>> {
} }
} }
#[derive(Clone)] #[derive(Clone, Debug)]
enum VariableOrPropertyPath { enum VariableOrPropertyPath {
Variable(Variable), Variable(Variable),
PropertyPath(PropertyPathExpression), PropertyPath(PropertyPathExpression),
@ -289,6 +289,7 @@ fn build_bgp(patterns: Vec<TripleOrPathPattern>) -> GraphPattern {
elements.into_iter().reduce(new_join).unwrap_or_default() elements.into_iter().reduce(new_join).unwrap_or_default()
} }
#[derive(Debug)]
enum TripleOrPathPattern { enum TripleOrPathPattern {
Triple(TriplePattern), Triple(TriplePattern),
Path { Path {
@ -304,6 +305,7 @@ impl From<TriplePattern> for TripleOrPathPattern {
} }
} }
#[derive(Debug)]
struct AnnotatedTermPath { struct AnnotatedTermPath {
term: TermPattern, term: TermPattern,
annotations: Vec<(VariableOrPropertyPath, Vec<AnnotatedTermPath>)>, annotations: Vec<(VariableOrPropertyPath, Vec<AnnotatedTermPath>)>,
@ -322,7 +324,7 @@ impl From<AnnotatedTerm> for AnnotatedTermPath {
} }
} }
#[derive(Default)] #[derive(Debug, Default)]
struct FocusedTripleOrPathPattern<F> { struct FocusedTripleOrPathPattern<F> {
focus: F, focus: F,
patterns: Vec<TripleOrPathPattern>, patterns: Vec<TripleOrPathPattern>,
@ -1780,7 +1782,7 @@ parser! {
//[101] //[101]
rule BlankNodePropertyListPath() -> FocusedTripleOrPathPattern<TermPattern> = "[" _ po:PropertyListPathNotEmpty() _ "]" {? rule BlankNodePropertyListPath() -> FocusedTripleOrPathPattern<TermPattern> = "[" _ po:PropertyListPathNotEmpty() _ "]" {?
let mut patterns: Vec<TripleOrPathPattern> = Vec::new(); let mut patterns = po.patterns;
let mut bnode = TermPattern::from(BlankNode::default()); let mut bnode = TermPattern::from(BlankNode::default());
for (p, os) in po.focus { for (p, os) in po.focus {
for o in os { for o in os {

@ -26,6 +26,7 @@
:nested_path :nested_path
:nested_expression :nested_expression
:order_terms :order_terms
:nested_anonymous
) . ) .
:small_unicode_escape_with_multibytes_char rdf:type mf:NegativeSyntaxTest ; :small_unicode_escape_with_multibytes_char rdf:type mf:NegativeSyntaxTest ;
@ -114,3 +115,10 @@
mf:name "literals have an order for ORDER BY" ; mf:name "literals have an order for ORDER BY" ;
mf:action [ qt:query <order_terms.rq> ] ; mf:action [ qt:query <order_terms.rq> ] ;
mf:result <order_terms.ttl> . mf:result <order_terms.ttl> .
:nested_anonymous rdf:type mf:QueryEvaluationTest ;
mf:name "Nested anonymous" ;
mf:action
[ qt:query <nested_anonymous.rq> ;
qt:data <nested_anonymous.ttl> ] ;
mf:result <nested_anonymous.srx> .

@ -0,0 +1,5 @@
PREFIX : <http://example.com/>
SELECT ?a WHERE {
[ :p1 ?a ; :p2 [ :p3 :foo ] ]
}

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head>
<variable name="a"/>
</head>
<results>
<result>
<binding name="a">
<literal>t1</literal>
</binding>
</result>
</results>
</sparql>

@ -0,0 +1,4 @@
PREFIX : <http://example.com/>
[ :p1 "t1" ; :p2 [ :p3 :foo ] ] .
[ :p1 "t2" ; :p2 [ :p3 :bar ] ] .
Loading…
Cancel
Save