[tracker] rasqal: Support predefining and redefining prefixes
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker] rasqal: Support predefining and redefining prefixes
- Date: Thu, 16 Apr 2009 10:18:07 -0400 (EDT)
commit a128358c66df2c303d7dc56c639f3ae751ecd2bf
Author: Jürg Billeter <j bitron ch>
Date: Thu Mar 12 17:57:58 2009 +0100
rasqal: Support predefining and redefining prefixes
---
src/rasqal/rasqal.h | 2 ++
src/rasqal/rasqal_internal.h | 1 -
src/rasqal/rasqal_query.c | 5 ++++-
src/rasqal/sparql_parser.y | 34 ++++++++--------------------------
4 files changed, 14 insertions(+), 28 deletions(-)
diff --git a/src/rasqal/rasqal.h b/src/rasqal/rasqal.h
index 5dfbae3..324c330 100644
--- a/src/rasqal/rasqal.h
+++ b/src/rasqal/rasqal.h
@@ -779,6 +779,8 @@ raptor_sequence* rasqal_query_get_prefix_sequence(rasqal_query* query);
RASQAL_API
rasqal_prefix* rasqal_query_get_prefix(rasqal_query* query, int idx);
RASQAL_API
+int rasqal_query_declare_prefixes(rasqal_query* rq);
+RASQAL_API
raptor_sequence* rasqal_query_get_order_conditions_sequence(rasqal_query* query);
RASQAL_API
rasqal_expression* rasqal_query_get_order_condition(rasqal_query* query, int idx);
diff --git a/src/rasqal/rasqal_internal.h b/src/rasqal/rasqal_internal.h
index f0e7a14..82ad445 100644
--- a/src/rasqal/rasqal_internal.h
+++ b/src/rasqal/rasqal_internal.h
@@ -884,7 +884,6 @@ void rasqal_map_print(rasqal_map* map, FILE* fh);
rasqal_query_results* rasqal_query_execute_with_engine(rasqal_query* query, const rasqal_query_execution_factory* engine);
void rasqal_query_remove_query_result(rasqal_query* query, rasqal_query_results* query_results);
int rasqal_query_declare_prefix(rasqal_query* rq, rasqal_prefix* prefix);
-int rasqal_query_declare_prefixes(rasqal_query* rq);
unsigned char* rasqal_query_get_genid(rasqal_query* query, const unsigned char* base, int counter);
void rasqal_query_set_base_uri(rasqal_query* rq, raptor_uri* base_uri);
void rasqal_query_set_store_results(rasqal_query* query, int store_results);
diff --git a/src/rasqal/rasqal_query.c b/src/rasqal/rasqal_query.c
index 1635685..ba9a37d 100644
--- a/src/rasqal/rasqal_query.c
+++ b/src/rasqal/rasqal_query.c
@@ -963,7 +963,10 @@ rasqal_query_add_prefix(rasqal_query* query, rasqal_prefix* prefix)
for(i = 0; i< raptor_sequence_size(query->prefixes); i++) {
rasqal_prefix* p;
p = (rasqal_prefix*)raptor_sequence_get_at(query->prefixes, i);
- if(!strcmp((const char*)p->prefix, (const char*)prefix->prefix)) {
+ /* ->prefix can be NULL for default prefix */
+ if((p->prefix == prefix->prefix) ||
+ (p->prefix != NULL && prefix->prefix != NULL &&
+ !strcmp((const char*)p->prefix, (const char*)prefix->prefix))) {
rasqal_query_undeclare_prefix(query, p);
break;
}
diff --git a/src/rasqal/sparql_parser.y b/src/rasqal/sparql_parser.y
index 15e5b53..ab83e58 100644
--- a/src/rasqal/sparql_parser.y
+++ b/src/rasqal/sparql_parser.y
@@ -403,33 +403,15 @@ BaseDeclOpt: BASE URI_LITERAL
/* SPARQL Grammar: [4] PrefixDecl renamed to include optional list */
PrefixDeclListOpt: PrefixDeclListOpt PREFIX IDENTIFIER URI_LITERAL
{
- raptor_sequence *seq=((rasqal_query*)rq)->prefixes;
unsigned const char* prefix_string=$3;
- size_t l=0;
- if(prefix_string)
- l=strlen((const char*)prefix_string);
-
- if(raptor_namespaces_find_namespace(((rasqal_query*)rq)->namespaces, prefix_string, l)) {
- /* A prefix may be defined only once */
- sparql_syntax_warning(((rasqal_query*)rq),
- "PREFIX %s can be defined only once.",
- prefix_string ? (const char*)prefix_string : ":");
- RASQAL_FREE(cstring, prefix_string);
-#ifdef RAPTOR_V2_AVAILABLE
- raptor_free_uri_v2(((rasqal_query*)rq)->world->raptor_world_ptr, $4);
-#else
- raptor_free_uri($4);
-#endif
- } else {
- rasqal_prefix *p=rasqal_new_prefix(((rasqal_query*)rq)->world, prefix_string, $4);
- if(!p)
- YYERROR_MSG("PrefixDeclOpt: failed to create new prefix");
- if(raptor_sequence_push(seq, p))
- YYERROR_MSG("PrefixDeclOpt: cannot push prefix to seq");
- if(rasqal_query_declare_prefix(((rasqal_query*)rq), p)) {
- YYERROR_MSG("PrefixDeclOpt: cannot declare prefix");
- }
+ rasqal_prefix *p=rasqal_new_prefix(((rasqal_query*)rq)->world, prefix_string, $4);
+ if(!p)
+ YYERROR_MSG("PrefixDeclOpt: failed to create new prefix");
+ if(rasqal_query_add_prefix(((rasqal_query*)rq), p))
+ YYERROR_MSG("PrefixDeclOpt: cannot add prefix");
+ if(rasqal_query_declare_prefix(((rasqal_query*)rq), p)) {
+ YYERROR_MSG("PrefixDeclOpt: cannot declare prefix");
}
}
| /* empty */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]