[tracker/tracker-0.10] SPARQL: Support SELECT (Expression AS Var) syntax
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/tracker-0.10] SPARQL: Support SELECT (Expression AS Var) syntax
- Date: Wed, 12 Oct 2011 13:33:49 +0000 (UTC)
commit 6beff0b2751cd6d3e1ff330903d4f9ae0134e18b
Author: JÃrg Billeter <j bitron ch>
Date: Tue Oct 11 14:31:26 2011 +0200
SPARQL: Support SELECT (Expression AS Var) syntax
Syntax specified in current SPARQL 1.1 Query draft.
src/libtracker-data/tracker-sparql-expression.vala | 28 ++++++++++++++++++++
1 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-expression.vala b/src/libtracker-data/tracker-sparql-expression.vala
index 1205adb..c04a5d1 100644
--- a/src/libtracker-data/tracker-sparql-expression.vala
+++ b/src/libtracker-data/tracker-sparql-expression.vala
@@ -123,6 +123,7 @@ class Tracker.Sparql.Expression : Object {
internal PropertyType translate_select_expression (StringBuilder sql, bool subquery, int variable_index) throws Sparql.Error {
Variable variable = null;
+ bool expect_close_parens = false;
long begin = sql.len;
var type = PropertyType.UNKNOWN;
@@ -134,7 +135,30 @@ class Tracker.Sparql.Expression : Object {
if (variable.binding == null) {
throw get_error ("use of undefined variable `%s'".printf (variable.name));
}
+ } else if (accept (SparqlTokenType.OPEN_PARENS)) {
+ if (current () == SparqlTokenType.SELECT) {
+ // no parenthesis around expression
+ // deprecated but supported for backward compatibility
+ sql.append ("(");
+ var select_context = pattern.translate_select (sql, true, true);
+ sql.append (")");
+
+ expect (SparqlTokenType.CLOSE_PARENS);
+ type = select_context.type;
+ } else {
+ type = translate_expression (sql);
+ if (accept (SparqlTokenType.CLOSE_PARENS)) {
+ // missing AS
+ // deprecated but supported for backward compatibility
+ } else {
+ // syntax from SPARQL 1.1 Draft
+ // (Expression AS Var)
+ expect_close_parens = true;
+ }
+ }
} else {
+ // no parenthesis around expression
+ // deprecated but supported for backward compatibility
type = translate_expression (sql);
}
@@ -164,6 +188,10 @@ class Tracker.Sparql.Expression : Object {
}
}
+ if (expect_close_parens) {
+ expect (SparqlTokenType.CLOSE_PARENS);
+ }
+
if (variable != null) {
int state = context.var_set.lookup (variable);
if (state == 0) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]