@@ -254,8 +254,17 @@ static inline str gap(const char* ref, const char* start, const char* end)
254254}
255255
256256#define P_Abort(x) return x
257+#define P_Tag \
258+ node_alloc(&d->nodes, 1); \
259+ me = &d->nodes.nodes[d->nodes.size - d->nodes.used_back]; \
260+ me->outer = gap(d->body, p, p);
257261#define P_NameStart name_start = p
258262#define P_NameEnd name_end = p
263+#define P_AttribsStart \
264+ me->attrs.start = d->attrs.used; \
265+ me->name = gap(d->body, name_start, name_end);
266+#define P_AttribsEnd \
267+ me->attrs = start_end(me->attrs.start, d->attrs.used);
259268#define P_QuoteStart quote_start = p
260269#define P_QuoteEnd \
261270 quote_end = p; \
@@ -263,20 +272,21 @@ static inline str gap(const char* ref, const char* start, const char* end)
263272 d->attrs.attrs[d->attrs.used].name = gap(d->body, name_start, name_end); \
264273 d->attrs.attrs[d->attrs.used].value = gap(d->body, quote_start, quote_end); \
265274 d->attrs.used++;
266−#define P_Tag tag_start = p
267275#define P_TagComment printf("TagComment %s\n", p)
268276#define P_TagOpen printf("TagOpen %s\n", p)
269277#define P_TagClose printf("TagClose %s\n", p)
270278#define P_TagOpenClose \
271− d->nodes.nodes[d->nodes.used_front].outer = gap(d->body, tag_start, p); \
272− printf("TagOpenClose %s\n", p)
279+ me->nodes = start_end(0, 0); \
280+ printf("TagOpenClose %s\n", p)
281+// d->nodes.nodes[d->nodes.used_front].outer = gap(d->body, tag_start, p); \
282+
273283
274284// Given the parsed string, return either NULL (success) or an error message (failure)
275285static const char* parser(const char* p, document* d)
276286{
277− const char *tag_start; // Where the entire tag starts [<foo
278287 const char *name_start, *name_end; // Where a name is <[foo] or <foo [bar]=
279288 const char *quote_start, *quote_end; // Where an attribute quote is <foo bar='[123]'>
289+ node* me; // The current node I'm working on
280290# include "test.h"
281291 return NULL;
282292}
@@ -322,7 +332,8 @@ document* hexml_document_parse(const char* s, int slen)
322332 const char* res = parser(s, d);
323333 if (res != NULL)
324334 d->error_message = strdup(res);
325− // d->nodes.nodes[0].nodes = content;
335+ else
336+ d->nodes.nodes[0].nodes = start_end(1, d->nodes.used_front);
326337 return d;
327338}
328339
@@ -331,12 +342,14 @@ document* hexml_document_parse(const char* s, int slen)
331342
332343int main()
333344{
334− const document* d = hexml_document_parse("<test foo='123 xyz'><inner /> value</test>", -1);
345+ setbuf(stdout, NULL);
346+ const char* example = "<bob />"; // "<test foo='123 xyz' bar='t'><inner /> value</test>";
347+ const document* d = hexml_document_parse(example, -1);
335348 char buf[1000];
336349 int len = hexml_node_render(d, hexml_document_node(d), buf, sizeof(buf));
337350 buf[len] = 0;
338351 printf("Result = %s\n", buf);
339− printf("Used nodes = %i, attribtes = %i\n", d->nodes.used_front, d->attrs.used);
352+ printf("Used nodes = %i, attributes = %i\n", d->nodes.used_front, d->attrs.used);
340353 return 0;
341354}
342355