on master help sign in
More work getting towards a workable state
6f52e35Neil Mitchell
gen/test.c+20−7
@@ -254,8 +254,17 @@ static inline str gap(const char* ref, const char* start, const char* end)
254}
254}
255
255
256#define P_Abort(x) return x
256#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);
257#define P_NameStart name_start = p
261#define P_NameStart name_start = p
258#define P_NameEnd name_end = p
262#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);
259#define P_QuoteStart quote_start = p
268#define P_QuoteStart quote_start = p
260#define P_QuoteEnd \
269#define P_QuoteEnd \
261 quote_end = p; \
270 quote_end = p; \
@@ -263,20 +272,21 @@ static inline str gap(const char* ref, const char* start, const char* end)
263 d->attrs.attrs[d->attrs.used].name = gap(d->body, name_start, name_end); \
272 d->attrs.attrs[d->attrs.used].name = gap(d->body, name_start, name_end); \
264 d->attrs.attrs[d->attrs.used].value = gap(d->body, quote_start, quote_end); \
273 d->attrs.attrs[d->attrs.used].value = gap(d->body, quote_start, quote_end); \
265 d->attrs.used++;
274 d->attrs.used++;
266−#define P_Tag tag_start = p
267#define P_TagComment printf("TagComment %s\n", p)
275#define P_TagComment printf("TagComment %s\n", p)
268#define P_TagOpen printf("TagOpen %s\n", p)
276#define P_TagOpen printf("TagOpen %s\n", p)
269#define P_TagClose printf("TagClose %s\n", p)
277#define P_TagClose printf("TagClose %s\n", p)
270#define P_TagOpenClose \
278#define P_TagOpenClose \
279+ me->nodes = start_end(0, 0); \
280+ printf("TagOpenClose %s\n", p)
271− d->nodes.nodes[d->nodes.used_front].outer = gap(d->body, tag_start, p); \
281+// d->nodes.nodes[d->nodes.used_front].outer = gap(d->body, tag_start, p); \
272− printf("TagOpenClose %s\n", p)
282+
273
283
274// Given the parsed string, return either NULL (success) or an error message (failure)
284// Given the parsed string, return either NULL (success) or an error message (failure)
275static const char* parser(const char* p, document* d)
285static const char* parser(const char* p, document* d)
276{
286{
277− const char *tag_start; // Where the entire tag starts [<foo
278 const char *name_start, *name_end; // Where a name is <[foo] or <foo [bar]=
287 const char *name_start, *name_end; // Where a name is <[foo] or <foo [bar]=
279 const char *quote_start, *quote_end; // Where an attribute quote is <foo bar='[123]'>
288 const char *quote_start, *quote_end; // Where an attribute quote is <foo bar='[123]'>
289+ node* me; // The current node I'm working on
280# include "test.h"
290# include "test.h"
281 return NULL;
291 return NULL;
282}
292}
@@ -322,7 +332,8 @@ document* hexml_document_parse(const char* s, int slen)
322 const char* res = parser(s, d);
332 const char* res = parser(s, d);
323 if (res != NULL)
333 if (res != NULL)
324 d->error_message = strdup(res);
334 d->error_message = strdup(res);
335+ else
325− // d->nodes.nodes[0].nodes = content;
336+ d->nodes.nodes[0].nodes = start_end(1, d->nodes.used_front);
326 return d;
337 return d;
327}
338}
328
339
@@ -331,12 +342,14 @@ document* hexml_document_parse(const char* s, int slen)
331
342
332int main()
343int main()
333{
344{
345+ setbuf(stdout, NULL);
334− const document* d = hexml_document_parse("<test foo='123 xyz'><inner /> value</test>", -1);
346+ const char* example = "<bob />"; // "<test foo='123 xyz' bar='t'><inner /> value</test>";
347+ const document* d = hexml_document_parse(example, -1);
335 char buf[1000];
348 char buf[1000];
336 int len = hexml_node_render(d, hexml_document_node(d), buf, sizeof(buf));
349 int len = hexml_node_render(d, hexml_document_node(d), buf, sizeof(buf));
337 buf[len] = 0;
350 buf[len] = 0;
338 printf("Result = %s\n", buf);
351 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);
340 return 0;
353 return 0;
341}
354}
342
355