aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-08-09 18:28:35 -0400
committerDavid Robillard <d@drobilla.net>2022-01-28 21:57:07 -0500
commit385a612b3bab9c5b177d7a400b72cb7fe3e3a299 (patch)
treefde30cdeaf13c85a1a9d0873193a7625d8e8097b
parent3ddbb5da6ac249638151a4570747500610b5c07c (diff)
downloadserd-385a612b3bab9c5b177d7a400b72cb7fe3e3a299.tar.gz
serd-385a612b3bab9c5b177d7a400b72cb7fe3e3a299.tar.bz2
serd-385a612b3bab9c5b177d7a400b72cb7fe3e3a299.zip
Preserve anonymous graph syntax in TriG
-rw-r--r--NEWS3
-rw-r--r--include/serd/serd.h13
-rw-r--r--src/n3.c1
-rw-r--r--src/writer.c3
4 files changed, 12 insertions, 8 deletions
diff --git a/NEWS b/NEWS
index e3524b41..43beefdd 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ serd (1.0.1) unstable;
* Bring read/write interface closer to C standard
* Improve error handling
* Make nodes opaque
+ * Preserve anonymous graph syntax in TriG
* Preserve long or short quoting from input documents
* Remove serd_uri_to_path()
* Remove support for Turtle named inline nodes extension
@@ -23,7 +24,7 @@ serd (1.0.1) unstable;
* Use a fixed-size reader stack
* Use char* for strings in public API
- -- David Robillard <d@drobilla.net> Sat, 31 Jul 2021 23:27:35 +0000
+ -- David Robillard <d@drobilla.net> Mon, 09 Aug 2021 22:28:20 +0000
serd (0.30.11) unstable;
diff --git a/include/serd/serd.h b/include/serd/serd.h
index 3655f0b4..f30026ca 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -1814,12 +1814,13 @@ typedef enum {
/// Flags indicating inline abbreviation information for a statement
typedef enum {
SERD_EMPTY_S = 1u << 0u, ///< Empty blank node subject
- SERD_ANON_S = 1u << 1u, ///< Start of anonymous subject
- SERD_ANON_O = 1u << 2u, ///< Start of anonymous object
- SERD_LIST_S = 1u << 3u, ///< Start of list subject
- SERD_LIST_O = 1u << 4u, ///< Start of list object
- SERD_TERSE_S = 1u << 5u, ///< Start of terse subject
- SERD_TERSE_O = 1u << 6u ///< Start of terse object
+ SERD_EMPTY_G = 1u << 1u, ///< Empty blank node graph
+ SERD_ANON_S = 1u << 2u, ///< Start of anonymous subject
+ SERD_ANON_O = 1u << 3u, ///< Start of anonymous object
+ SERD_LIST_S = 1u << 4u, ///< Start of list subject
+ SERD_LIST_O = 1u << 5u, ///< Start of list object
+ SERD_TERSE_S = 1u << 6u, ///< Start of terse subject
+ SERD_TERSE_O = 1u << 7u ///< Start of terse object
} SerdStatementFlag;
/// Bitwise OR of SerdStatementFlag values
diff --git a/src/n3.c b/src/n3.c
index 7e913d8b..6d4210b4 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -1198,6 +1198,7 @@ read_block(SerdReader* const reader, ReadContext* const ctx)
}
ctx->graph = token;
+ (*ctx->flags) |= (s_type == '[' ? SERD_EMPTY_G : 0u);
return read_wrappedGraph(reader, ctx);
}
diff --git a/src/writer.c b/src/writer.c
index 968d1a9f..5f178a6f 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -884,7 +884,8 @@ write_blank(SerdWriter* const writer,
return write_sep(writer, flags, SEP_LIST_BEGIN);
}
- if (field == SERD_SUBJECT && (flags & SERD_EMPTY_S)) {
+ if ((field == SERD_SUBJECT && (flags & SERD_EMPTY_S)) ||
+ (field == SERD_GRAPH && (flags & SERD_EMPTY_G))) {
writer->last_sep = SEP_NONE; // Treat "[]" like a node
return esink("[]", 2, writer);
}