[tracker/wip/carlosg/sparql-parser-ng: 277/306] libtracker-data: Bring back custom sparql syntax



commit d3e7e0be0e8e432d4d7be1f17bded38d90205d53
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Apr 1 13:05:56 2018 +0200

    libtracker-data: Bring back custom sparql syntax
    
    Tracker used to accept SubSelect in BrackettedExpression, bring
    that back.

 src/libtracker-data/tracker-sparql-grammar.h |  7 ++++++-
 src/libtracker-data/tracker-sparql.c         | 20 +++++++++++++++++++-
 2 files changed, 25 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-grammar.h b/src/libtracker-data/tracker-sparql-grammar.h
index e649acf54..50c32afe7 100644
--- a/src/libtracker-data/tracker-sparql-grammar.h
+++ b/src/libtracker-data/tracker-sparql-grammar.h
@@ -765,8 +765,13 @@ static const TrackerGrammarRule helper_BuiltInCall_or_2[] = { S(helper_BuiltInCa
 static const TrackerGrammarRule rule_BuiltInCall[] = { OR(helper_BuiltInCall_or_2), NIL };
 
 /* BrackettedExpression ::= '(' Expression ')'
+ *
+ * TRACKER EXTENSION:
+ * SubSelect is accepted too, thus the grammar results in:
+ * '(' ( Expression | SubSelect) ')'
  */
-static const TrackerGrammarRule rule_BrackettedExpression[] = { L(OPEN_PARENS), R(Expression), 
L(CLOSE_PARENS), NIL };
+static const TrackerGrammarRule ext_BrackettedExpression_or[] = { R(Expression), R(SubSelect), NIL };
+static const TrackerGrammarRule rule_BrackettedExpression[] = { L(OPEN_PARENS), 
OR(ext_BrackettedExpression_or), L(CLOSE_PARENS), NIL };
 
 /* iriOrFunction ::= iri ArgList?
  */
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index e0778b68a..a6e766bc0 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -4715,11 +4715,29 @@ static gboolean
 translate_BrackettedExpression (TrackerSparql  *sparql,
                                 GError        **error)
 {
+       TrackerGrammarNamedRule rule;
+
        /* BrackettedExpression ::= '(' Expression ')'
+        *
+        * TRACKER EXTENSION:
+        * SubSelect is accepted too, thus the grammar results in:
+        * '(' ( Expression | SubSelect) ')'
         */
        _expect (sparql, RULE_TYPE_LITERAL, LITERAL_OPEN_PARENS);
-       _call_rule (sparql, NAMED_RULE_Expression, error);
+       _append_string (sparql, "(");
+       rule = _current_rule (sparql);
+
+       switch (rule) {
+       case NAMED_RULE_Expression:
+       case NAMED_RULE_SubSelect:
+               _call_rule (sparql, rule, error);
+               break;
+       default:
+               g_assert_not_reached ();
+       }
+
        _expect (sparql, RULE_TYPE_LITERAL, LITERAL_CLOSE_PARENS);
+       _append_string (sparql, ") ");
 
        return TRUE;
 }


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