From f31a7a981043ab874c20d0699e361b196a9308ba Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 6 May 2023 18:42:10 -0700 Subject: [PATCH] future --- src/scan.re.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/src/scan.re.c b/src/scan.re.c index 26d500d..c983d3d 100644 --- a/src/scan.re.c +++ b/src/scan.re.c @@ -177,11 +177,10 @@ static int scan_day(struct scan *const scan, union date32 date, "document: " :=> document_title * { fail = "document title"; goto catch; } - @s0 bralabel @s1 "]" => text_input { + @s0 bralabel @s1 "]" => future { const union line64 key = { { (uint32_t)line, date } }; size_t *pi; struct source *doc; - fprintf(stderr, "document: <<%.*s>>\n", (int)(s1 - s0), s0); if(!(doc = source_array_new(&scan->documents.array))) goto catch; doc->name.a = s0, doc->name.b = s1; doc->desc.a = 0, doc->desc.b = 0; @@ -193,7 +192,6 @@ static int scan_day(struct scan *const scan, union date32 date, } fprintf(stderr, "%s[%zu]: new document <<%.*s>> stored at %zu.\n", datestr, line, (int)(s1 - s0), s0, *pi); - assert(future); continue; } @@ -270,9 +268,8 @@ static int scan_day(struct scan *const scan, union date32 date, fprintf(stderr, "%s[%zu]: source <<%.*s>>\n", datestr, line, (int)(s1 - s0), s0); } continue; } - /* New source. fixme: desc not set. */ -//////// - @s0 keyword @s1 ":" [^\x00\n]+ / "\n" => skip { + /* New source. */ + @s0 keyword @s1 ":" => future { struct pair keyword = pair(s0, s1); size_t *idx; struct source *source; @@ -284,7 +281,8 @@ static int scan_day(struct scan *const scan, union date32 date, if(!(source = source_array_new(&scan->sources.array))) goto catch; *idx = (size_t)(source - scan->sources.array.data); source->name.a = s0, source->name.b = s1; - source->desc.a = 0, source->desc.b = 0; /* fixme */ + source->desc.a = 0, source->desc.b = 0; + assert(!future), future = &source->desc; fprintf(stderr, "%s[%zu]: new source <<%.*s>> stored at %zu.\n", datestr, line, (int)(s1 - s0), s0, *idx); goto also_source; @@ -625,39 +623,38 @@ static int scan_day(struct scan *const scan, union date32 date, } - /* "<<\ntext\n>>" or "text\n" used by several. - Must have future and */ - * { fail = "text input"; goto catch; } - ws+ { continue; } - "\n" => line { // empty is okay + /* "<<\ntext\n>>" or "text\n" used by several. Must have pointers to + future input. */ + * { fail = "text input"; goto catch; } + ws+ { continue; } + "\n" => line { // empty is okay line++; assert(future); future->a = future->b = 0, future = 0; continue; } - "<<\n" @s0 => text_multi { // multi-line + "<<\n" @s0 => future_multi { // multi-line line++; - fprintf(stderr, "$$$ multi-line!\n"); assert(future); future->a = s0; continue; } - @s0 anylabel @s1 "\n" => line { // one line - // @s0 semilabel @s1 "\n" => line { // one line + @s0 anylabel @s1 "\n" => line { // one line line++; - fprintf(stderr, "text: [[%.*s]]\n", (int)(s1 - s0), s0); + fprintf(stderr, "text: <<%.*s>>\n", (int)(s1 - s0), s0); assert(future); future->a = s0, future->b = s1, future = 0; continue; } - [^\x00\n] { continue; } - [\x00] { fail = "missing closing \">>\""; goto catch; } - "\n" { line++; continue; } - @s1 ">>\n" => line { + [^\x00\n] { continue; } + [\x00] { fail = "missing closing \">>\""; goto catch; } + "\n" { line++; continue; } + /* Restricts this to be the last one; you could imagine that it would + be more flexible, "<<\n>>; <<\n>>\n". */ + @s1 ">>\n" => line { line++; assert(future && future->a); - future->b = s1; - future = 0; + future->b = s1, future = 0; continue; }