[tracker/wip/carlosg/sparql-parser-ng: 40/43] libtracker-data: Prepare for property paths
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/sparql-parser-ng: 40/43] libtracker-data: Prepare for property paths
- Date: Sat, 3 Nov 2018 13:10:53 +0000 (UTC)
commit 762204429853c26f95f4e211afc13c0c64099a09
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Nov 3 13:07:04 2018 +0100
libtracker-data: Prepare for property paths
Property paths may introduce intermediate anonymous resources, or
shuffle subject/object. We still do the bulk of the job while parsing
the predicate, so prepare for the predicate being pre-filled, and
the Path grammar element to alter the next parsed token.
src/libtracker-data/tracker-sparql.c | 39 ++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 15 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index 54e48a1d2..10ba7b2ca 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -3761,21 +3761,23 @@ translate_TriplesSameSubject (TrackerSparql *sparql,
/* TriplesSameSubject ::= VarOrTerm PropertyListNotEmpty | TriplesNode PropertyList
*/
rule = _current_rule (sparql);
+ sparql->current_state.token = &sparql->current_state.subject;
if (rule == NAMED_RULE_VarOrTerm) {
- sparql->current_state.token = &sparql->current_state.subject;
_call_rule (sparql, rule, error);
g_assert (!tracker_token_is_empty (&sparql->current_state.subject));
+ sparql->current_state.token = &sparql->current_state.object;
_call_rule (sparql, NAMED_RULE_PropertyListNotEmpty, error);
} else if (rule == NAMED_RULE_TriplesNode) {
- sparql->current_state.token = &sparql->current_state.subject;
_call_rule (sparql, rule, error);
g_assert (!tracker_token_is_empty (&sparql->current_state.subject));
+ sparql->current_state.token = &sparql->current_state.object;
_call_rule (sparql, NAMED_RULE_PropertyList, error);
}
tracker_token_unset (&sparql->current_state.subject);
sparql->current_state.subject = old_subject;
+ sparql->current_state.token = NULL;
return TRUE;
}
@@ -3906,23 +3908,23 @@ translate_TriplesSameSubjectPath (TrackerSparql *sparql,
/* TriplesSameSubjectPath ::= VarOrTerm PropertyListPathNotEmpty | TriplesNodePath PropertyListPath
*/
rule = _current_rule (sparql);
+ sparql->current_state.token = &sparql->current_state.subject;
if (rule == NAMED_RULE_VarOrTerm) {
- sparql->current_state.token = &sparql->current_state.subject;
_call_rule (sparql, rule, error);
g_assert (!tracker_token_is_empty (&sparql->current_state.subject));
-
+ sparql->current_state.token = &sparql->current_state.object;
_call_rule (sparql, NAMED_RULE_PropertyListPathNotEmpty, error);
} else if (rule == NAMED_RULE_TriplesNodePath) {
- sparql->current_state.token = &sparql->current_state.subject;
_call_rule (sparql, rule, error);
g_assert (!tracker_token_is_empty (&sparql->current_state.subject));
-
+ sparql->current_state.token = &sparql->current_state.object;
_call_rule (sparql, NAMED_RULE_PropertyListPath, error);
}
tracker_token_unset (&sparql->current_state.subject);
sparql->current_state.subject = old_subject;
+ sparql->current_state.token = NULL;
return TRUE;
}
@@ -4044,9 +4046,14 @@ static gboolean
translate_Path (TrackerSparql *sparql,
GError **error)
{
+ TrackerToken *prev_token;
+
/* Path ::= PathAlternative
*/
+ prev_token = sparql->current_state.token;
+ sparql->current_state.token = &sparql->current_state.object;
_call_rule (sparql, NAMED_RULE_PathAlternative, error);
+ sparql->current_state.token = prev_token;
return TRUE;
}
@@ -4109,11 +4116,17 @@ translate_PathElt (TrackerSparql *sparql,
_call_rule (sparql, NAMED_RULE_PathMod, error);
}
- if (!_postprocess_rule (sparql, sparql->current_state.object_list,
- NULL, error))
- return FALSE;
-
- return TRUE;
+ if (!tracker_token_is_empty (sparql->current_state.token)) {
+ return _add_quad (sparql,
+ &sparql->current_state.graph,
+ &sparql->current_state.subject,
+ &sparql->current_state.predicate,
+ &sparql->current_state.object,
+ error);
+ } else {
+ return _postprocess_rule (sparql, sparql->current_state.object_list,
+ NULL, error);
+ }
}
static gboolean
@@ -4320,11 +4333,9 @@ translate_GraphNode (TrackerSparql *sparql,
* VarOrTerm | TriplesNode | 'NULL'
*/
if (_check_in_rule (sparql, NAMED_RULE_VarOrTerm)) {
- sparql->current_state.token = &sparql->current_state.object;
_call_rule (sparql, NAMED_RULE_VarOrTerm, error);
g_assert (!tracker_token_is_empty (&sparql->current_state.object));
} else if (_check_in_rule (sparql, NAMED_RULE_TriplesNode)) {
- sparql->current_state.token = &sparql->current_state.object;
_call_rule (sparql, NAMED_RULE_TriplesNode, error);
g_assert (!tracker_token_is_empty (&sparql->current_state.object));
} else if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_NULL)) {
@@ -4390,11 +4401,9 @@ translate_GraphNodePath (TrackerSparql *sparql,
/* GraphNodePath ::= VarOrTerm | TriplesNodePath
*/
if (_check_in_rule (sparql, NAMED_RULE_VarOrTerm)) {
- sparql->current_state.token = &sparql->current_state.object;
_call_rule (sparql, NAMED_RULE_VarOrTerm, error);
g_assert (!tracker_token_is_empty (&sparql->current_state.object));
} else if (_check_in_rule (sparql, NAMED_RULE_TriplesNodePath)) {
- sparql->current_state.token = &sparql->current_state.object;
_call_rule (sparql, NAMED_RULE_TriplesNodePath, error);
g_assert (!tracker_token_is_empty (&sparql->current_state.object));
} else {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]