aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-01-21 19:26:00 +0000
committerDavid Robillard <d@drobilla.net>2011-01-21 19:26:00 +0000
commit2a45d353d555e65087d7ce623da42d1ac10f2493 (patch)
treecd3799bbf179b4a820c4d067b37c47e0c11855bf
parente3b0d874872c77876988385b72f652e367ce669a (diff)
downloadserd-2a45d353d555e65087d7ce623da42d1ac10f2493.tar.gz
serd-2a45d353d555e65087d7ce623da42d1ac10f2493.tar.bz2
serd-2a45d353d555e65087d7ce623da42d1ac10f2493.zip
Clean up whitespace handling (properly deal with errors while expecting whitespace).
git-svn-id: http://svn.drobilla.net/serd/trunk@24 490d8e77-9747-427b-9fa3-0b8f29cee8a0
-rw-r--r--src/reader.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/src/reader.c b/src/reader.c
index b23a604a..10175d45 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -578,13 +578,10 @@ read_comment(SerdReader parser)
// [24] ws ::= #x9 | #xA | #xD | #x20 | comment
static inline bool
-read_ws(SerdReader parser, bool required)
+read_ws(SerdReader parser)
{
const uint8_t c = peek_byte(parser);
switch (c) {
- case '\0':
- assert(parser->eof);
- return false;
case 0x9: case 0xA: case 0xD: case 0x20:
eat_byte(parser, c);
return true;
@@ -592,27 +589,22 @@ read_ws(SerdReader parser, bool required)
read_comment(parser);
return true;
default:
- if (required) {
- error(parser, "expected whitespace\n");
- }
return false;
}
}
-static inline bool
-read_ws_plus(SerdReader parser)
+static inline void
+read_ws_star(SerdReader parser)
{
- if (read_ws(parser, true)) {
- while (read_ws(parser, false)) {}
- return true;
- }
- return false;
+ while (read_ws(parser)) {}
}
-static inline void
-read_ws_star(SerdReader parser)
+static inline bool
+read_ws_plus(SerdReader parser)
{
- while (read_ws(parser, false)) {}
+ TRY_RET(read_ws(parser));
+ read_ws_star(parser);
+ return true;
}
// [37] longSerdString ::= #x22 #x22 #x22 lcharacter* #x22 #x22 #x22
@@ -1114,7 +1106,7 @@ read_predicateObjectList(SerdReader parser, const Node* subject)
}
Node predicate = SERD_NODE_NULL;
TRY_RET(read_verb(parser, &predicate));
- read_ws_plus(parser);
+ TRY_THROW(read_ws_plus(parser));
TRY_THROW(read_objectList(parser, subject, &predicate));
pop_string(parser, predicate.value);
predicate.value = 0;
@@ -1127,7 +1119,7 @@ read_predicateObjectList(SerdReader parser, const Node* subject)
return true;
default:
TRY_THROW(read_verb(parser, &predicate));
- read_ws_plus(parser);
+ TRY_THROW(read_ws_plus(parser));
TRY_THROW(read_objectList(parser, subject, &predicate));
pop_string(parser, predicate.value);
predicate.value = 0;
@@ -1236,7 +1228,7 @@ read_prefixID(SerdReader parser)
{
// `@' is already eaten in read_directive
eat_string(parser, "prefix", 6);
- read_ws_plus(parser);
+ TRY_RET(read_ws_plus(parser));
bool ret = false;
Ref name = read_prefixName(parser);
if (!name) {