[tracker/wip/carlosg/sparql-parser-ng: 51/56] libtracker-data: Support sequence property path



commit 204ff72f6a9b1411fdf52d55700f8f74d07c9406
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Nov 3 13:16:59 2018 +0100

    libtracker-data: Support sequence property path
    
    "?a :foo/:bar ?b" is equivalent to "?a :foo ?gen . ?gen :bar ?b",
    make the parser make up those generated variables before processing
    the current predicate property.

 src/libtracker-data/tracker-sparql.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index 1961e6dad..9a2732a80 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -4078,14 +4078,35 @@ static gboolean
 translate_PathSequence (TrackerSparql  *sparql,
                         GError        **error)
 {
+       TrackerToken old_object, old_subject;
+       TrackerVariable *var;
+       TrackerParserNode *rule;
+
        /* PathSequence ::= PathEltOrInverse ( '/' PathEltOrInverse )*
         */
-       _call_rule (sparql, NAMED_RULE_PathEltOrInverse, error);
+       old_object = sparql->current_state.object;
+       old_subject = sparql->current_state.subject;
 
-       if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_PATH_SEQUENCE)) {
-               _unimplemented ("Property paths");
+       rule = _skip_rule (sparql, NAMED_RULE_PathEltOrInverse);
+
+       while (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_PATH_SEQUENCE)) {
+               var = tracker_select_context_add_generated_variable (TRACKER_SELECT_CONTEXT 
(sparql->context));
+               tracker_token_variable_init (&sparql->current_state.object, var);
+
+               if (!_postprocess_rule (sparql, rule, NULL, error))
+                       return FALSE;
+
+               rule = _skip_rule (sparql, NAMED_RULE_PathEltOrInverse);
+               sparql->current_state.subject = sparql->current_state.object;
+               tracker_token_unset (&sparql->current_state.object);
        }
 
+       if (!_postprocess_rule (sparql, rule, NULL, error))
+               return FALSE;
+
+       sparql->current_state.subject = old_subject;
+       sparql->current_state.object = old_object;
+
        return TRUE;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]