[tracker/parser] SPARQL: Add type information for multiplicative expressions
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/parser] SPARQL: Add type information for multiplicative expressions
- Date: Wed, 12 Aug 2009 12:49:05 +0000 (UTC)
commit e5b8409ff86880e0009b0ede6d70536498dd8d8d
Author: Jürg Billeter <j bitron ch>
Date: Wed Aug 12 14:08:05 2009 +0200
SPARQL: Add type information for multiplicative expressions
src/libtracker-data/tracker-sparql-query.vala | 25 ++++++++++++++++++++-----
1 files changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index 7edb90b..90e6719 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -36,7 +36,11 @@ public class Tracker.SparqlQuery : Object {
DECIMAL,
DATE,
DATETIME,
- RESOURCE
+ RESOURCE;
+
+ public bool maybe_numeric () {
+ return (this == INTEGER || this == DOUBLE || this == DATETIME || this == UNKNOWN);
+ }
}
// Represents a SQL table
@@ -1254,24 +1258,35 @@ public class Tracker.SparqlQuery : Object {
return translate_primary_expression (sql);
}
- void translate_multiplicative_expression (StringBuilder sql) throws SparqlError {
+ DataType translate_multiplicative_expression (StringBuilder sql) throws SparqlError {
long begin = sql.len;
- translate_unary_expression (sql);
+ var optype = translate_unary_expression (sql);
while (true) {
if (accept (SparqlTokenType.STAR)) {
+ if (!optype.maybe_numeric ()) {
+ throw new SparqlError.PARSE ("expected numeric operand");
+ }
sql.insert (begin, "(");
sql.append (" * ");
- translate_unary_expression (sql);
+ if (!translate_unary_expression (sql).maybe_numeric ()) {
+ throw new SparqlError.PARSE ("expected numeric operand");
+ }
sql.append (")");
} else if (accept (SparqlTokenType.DIV)) {
+ if (!optype.maybe_numeric ()) {
+ throw new SparqlError.PARSE ("expected numeric operand");
+ }
sql.insert (begin, "(");
sql.append (" / ");
- translate_unary_expression (sql);
+ if (!translate_unary_expression (sql).maybe_numeric ()) {
+ throw new SparqlError.PARSE ("expected numeric operand");
+ }
sql.append (")");
} else {
break;
}
}
+ return optype;
}
void translate_additive_expression (StringBuilder sql) throws SparqlError {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]