[tracker/wip/carlosg/sparql-parser-ng: 291/306] libtracker-data: Add "INSERT INTO iri" syntax back



commit f3dde140e01a750d62fb104c812f08fdda34df7a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Sep 2 16:07:09 2018 +0200

    libtracker-data: Add "INSERT INTO iri" syntax back
    
    This is a Tracker extension to SPARQL.

 src/libtracker-data/tracker-sparql-grammar.h |  6 ++++--
 src/libtracker-data/tracker-sparql.c         | 14 +++++++++++++-
 2 files changed, 17 insertions(+), 3 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-grammar.h b/src/libtracker-data/tracker-sparql-grammar.h
index caf54b8d5..88592d106 100644
--- a/src/libtracker-data/tracker-sparql-grammar.h
+++ b/src/libtracker-data/tracker-sparql-grammar.h
@@ -1228,12 +1228,14 @@ static const TrackerGrammarRule rule_UsingClause[] = { L(USING), OR(helper_Using
  *
  * TRACKER EXTENSION:
  * Clause may start with:
- * 'INSERT' ('OR' 'REPLACE')? ('SILENT')?
+ * 'INSERT' ('OR' 'REPLACE')? ('SILENT')? ('INTO' iri)?
  */
 static const TrackerGrammarRule helper_InsertClause_seq_1[] = { L(OR), L(REPLACE), NIL };
 static const TrackerGrammarRule helper_InsertClause_opt_1[] = { S(helper_InsertClause_seq_1), NIL };
 static const TrackerGrammarRule helper_InsertClause_opt_2[] = { L(SILENT), NIL };
-static const TrackerGrammarRule rule_InsertClause[] = { L(INSERT), OPT(helper_InsertClause_opt_1), 
OPT(helper_InsertClause_opt_2), R(QuadPattern), NIL };
+static const TrackerGrammarRule helper_InsertClause_seq_2[] = { L(INTO), R(iri), NIL };
+static const TrackerGrammarRule helper_InsertClause_opt_3[] = { S(helper_InsertClause_seq_2), NIL };
+static const TrackerGrammarRule rule_InsertClause[] = { L(INSERT), OPT(helper_InsertClause_opt_1), 
OPT(helper_InsertClause_opt_2), OPT(helper_InsertClause_opt_3), R(QuadPattern), NIL };
 
 /* DeleteClause ::= 'DELETE' QuadPattern
  *
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index db8d74222..72a601b95 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -2790,15 +2790,18 @@ static gboolean
 translate_InsertClause (TrackerSparql  *sparql,
                         GError        **error)
 {
+       TrackerToken old_graph;
+
        /* InsertClause ::= 'INSERT' QuadPattern
         *
         * TRACKER EXTENSION:
         * Clause may start with:
-        * 'INSERT' ('OR' 'REPLACE')? ('SILENT')?
+        * 'INSERT' ('OR' 'REPLACE')? ('SILENT')? ('INTO' iri)?
         */
        sparql->current_state.blank_node_map =
                g_hash_table_new_full (g_str_hash, g_str_equal,
                                       g_free, g_free);
+       old_graph = sparql->current_state.graph;
 
        sparql->current_state.type = TRACKER_SPARQL_TYPE_INSERT;
        _expect (sparql, RULE_TYPE_LITERAL, LITERAL_INSERT);
@@ -2812,8 +2815,17 @@ translate_InsertClause (TrackerSparql  *sparql,
 
        sparql->silent = _accept (sparql, RULE_TYPE_LITERAL, LITERAL_SILENT);
 
+       if (_accept (sparql, RULE_TYPE_LITERAL, LITERAL_INTO)) {
+               _call_rule (sparql, NAMED_RULE_iri, error);
+               _init_token (&sparql->current_state.graph,
+                            sparql->current_state.prev_node, sparql);
+       }
+
        _call_rule (sparql, NAMED_RULE_QuadPattern, error);
 
+       tracker_token_unset (&sparql->current_state.graph);
+       sparql->current_state.graph = old_graph;
+
        if (sparql->blank_nodes) {
                GHashTableIter iter;
                gpointer key, value;


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