diff options
author | David Robillard <d@drobilla.net> | 2021-08-12 22:33:47 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-01-28 21:57:07 -0500 |
commit | 196db2ef0cd44c3fb542b86be7929bd01d83e138 (patch) | |
tree | 97ad345394e394c0d42b43fcf3d464794f719ccb /tools | |
parent | fdf837b4b3baffc65e429c2e6ecc2e764bfed0ac (diff) | |
download | serd-196db2ef0cd44c3fb542b86be7929bd01d83e138.tar.gz serd-196db2ef0cd44c3fb542b86be7929bd01d83e138.tar.bz2 serd-196db2ef0cd44c3fb542b86be7929bd01d83e138.zip |
Put rdf:type properties first when pretty-printing
This is a common convention in Turtle and TriG because the special "a" syntax
for rdf type as the first property looks nice, makes things easier to read, and
can be useful for streaming implementations because the type of the instance is
known before reading its properties.
Also significantly clean up the pretty-printing implementation in the process.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/console.c | 1 | ||||
-rw-r--r-- | tools/serd-sort.c | 8 |
2 files changed, 8 insertions, 1 deletions
diff --git a/tools/console.c b/tools/console.c index f1e78d75..d7f67c35 100644 --- a/tools/console.c +++ b/tools/console.c @@ -218,6 +218,7 @@ serd_set_output_option(const SerdStringView name, {"verbatim", SERD_WRITE_VERBATIM}, {"terse", SERD_WRITE_TERSE}, {"lax", SERD_WRITE_LAX}, + {"rdf_type", SERD_WRITE_RDF_TYPE}, {NULL, SERD_WRITE_ASCII}, }; diff --git a/tools/serd-sort.c b/tools/serd-sort.c index 8ba99445..5e71e95e 100644 --- a/tools/serd-sort.c +++ b/tools/serd-sort.c @@ -176,7 +176,8 @@ print_usage(const char* const name, const bool error) " -c COLLATION An optional \"G\" then the letters \"SPO\" in any order.\n" " -h Display this help and exit.\n" " -k BYTES Parser stack size.\n" - " -o FILENAME Write output to FILENAME instead of stdout.\n"; + " -o FILENAME Write output to FILENAME instead of stdout.\n" + " -t Do not write type as \"a\" before other properties.\n"; FILE* const os = error ? stderr : stdout; fprintf(os, "%s", error ? "\n" : ""); @@ -221,6 +222,11 @@ parse_option(OptionIter* const iter, Options* const opts) case 's': return serd_get_argument(iter, &opts->input_string); + case 't': + opts->common.output.flags |= SERD_WRITE_RDF_TYPE; + opts->flags |= SERD_NO_TYPE_FIRST; + return serd_option_iter_advance(iter); + default: break; } |