From e30293e66ea24fce58c3458d05c30a3714f99bf4 Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 29 Dec 2022 14:01:10 -0800 Subject: [PATCH] Hopefully we see some errors if the syntax. --- src/scan_kjv.re.c | 91 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 71 insertions(+), 20 deletions(-) diff --git a/src/scan_kjv.re.c b/src/scan_kjv.re.c index f02867d..14261ef 100644 --- a/src/scan_kjv.re.c +++ b/src/scan_kjv.re.c @@ -6,6 +6,7 @@ #include "../src/journal.h" #include "../src/kjv.h" #include "../src/helper.h" +#include /* C99 */ #include #include #include @@ -15,14 +16,16 @@ static int scan(union date32 date, const char *const buffer, struct kjv *const kj) { - const char *YYCURSOR, *YYMARKER, *yyt1, *yyt2, *yyt3, *s0, *s1, *t0, *t1; + const char *YYCURSOR, *YYMARKER, *yyt1, *yyt2, *yyt3, + *s0, *s1, *t0, *t1, *line_start, *line_end; enum kjv_book book = Revelation; - uint32_t chapter, verse; + uint32_t chapter = 0, verse = 0, verse_end = 0; enum YYCONDTYPE condition = yycline; size_t line = 1; char datestr[12] = {0}; + int is_found = 0; assert(buffer && kj); - YYCURSOR = YYMARKER = yyt1 = buffer; + YYCURSOR = YYMARKER = yyt1 = line_start = buffer; /*!re2c /**/ re2c:define:YYCTYPE = char; re2c:yyfill:enable = 0; @@ -35,14 +38,19 @@ static int scan(union date32 date, const char *const buffer, ws = [ \t]; glyph = [^] \ ("\x00" | "\n" | unix_control | ws); natural = [1-9][0-9]*; + engage = ws+ "--" ws+; lookat = ws* natural ":" natural [ab]? - ("-" (natural ":")? natural [ab]?)? ws* "--"; + ("-" (natural ":")? natural [ab]?)? engage; */ for( ; ; ) { /*!re2c /**/ * { goto catch; } "\x00" { return 1; } - "\n" { line++; continue; } - * :=> skip + "\n" @line_start { + fprintf(stderr, "\033[0;37m" "%4zu" "\033[0m" "\n", line); + line++; + continue; + } + * :=> skip /* Guess it can't be simplified? */ "Genesis" / lookat => book { book = Genesis; continue; } "Exodus" / lookat => book { book = Exodus; continue; } /*| "Leviticus" | "Numbers" | "Deuteronomy" @@ -60,22 +68,50 @@ static int scan(union date32 date, const char *const buffer, | "Hebrews" | "James" | "I"{1,2} " Peter" | "I"{1,3} " John" | "Jude" | "Revelation") @s1 ws* / bible_ref ws+ "--" ws+ "``" */ // [^\n\x00]* newline { printf("throw\n"); line++; continue; } - ws+ @s0 natural @s1 ":" @t0 natural @t1 [ab]? => skip { - if(!helper_natural(s0, s1, &chapter) + ws+ @s0 natural @s1 ":" @t0 natural @t1 [ab]? { + if(chapter || verse || verse_end + || !helper_natural(s0, s1, &chapter) || !helper_natural(t0, t1, &verse)) goto catch; - union kjvcite cite - = { .book = book, .chapter = chapter, .verse = verse }; - const size_t old_set_words = kj->set_words; - char citestr[12]; - if(!kjv_add(kj, cite)) goto catch; - if(!*datestr) date32_to_string(date, &datestr); - kjvcite_to_string(cite, &citestr); - printf("%s\t%zu\t%zu\t# %s\n", - datestr, old_set_words, kj->set_words, citestr); continue; } - [^\n\x00]* "\n" => line { line++; continue; } - //=> bible { x->s0 = s0, x->s1 = s1; return x->symbol = KJV_BOOK, 1; } + "-" @s0 natural @s1 [ab]? { /* Verse range. */ + if(!chapter || !verse || verse_end + || !helper_natural(s0, s1, &verse_end)) goto catch; + continue; + } + engage => skip { + const size_t old_set_words = kj->set_words; + char citestr[12]; + if(!chapter || !verse || verse_end && verse_end <= verse) + goto catch; + union kjvcite cite + = { .book = book, .chapter = chapter, .verse = verse }; + if(!datestr[0]) date32_to_string(date, &datestr); /* Only once. */ + kjvcite_to_string(cite, &citestr); + for( ; ; verse++, cite.verse++) { + if(!kjv_add(kj, cite)) goto catch; + if(!verse_end || verse_end <= verse) break; + } + if(verse_end) { + printf("%s\t%zu\t%zu\t# %s-%" PRIu32 "\n", + datestr, old_set_words, kj->set_words, citestr, verse_end); + } else { + printf("%s\t%zu\t%zu\t# %s\n", + datestr, old_set_words, kj->set_words, citestr); + } + book = Revelation, chapter = 0, verse = 0, verse_end = 0; + is_found = 1; + continue; + } + [^\n\x00]* @line_end "\n" @s0 => line { + const size_t size = (size_t)(line_end - line_start); + int intsize = size > 40 ? 40 : (int)size; + fprintf(stderr, "%s%4zu: %.*s%s\n", is_found ? "\033[1;35m" : "", + line, intsize, line_start, is_found ? "\033[0m" : ""); + line_start = s0, is_found = 0; + line++; + continue; + } */ } catch: if(!errno) errno = EILSEQ; @@ -101,11 +137,26 @@ int main(void) { j = journal(); if(!journal_is_valid(&j)) goto catch; fprintf(stderr, "Journal: %s.\n", journal_to_string(&j)); - printf("# date\told\tnew / %zu\n", kj.total_words); + printf("set term postscript eps enhanced\n" + "set output \"kjv.eps\"\n" + "$Data <text, &kj)) goto catch; if(++i > 32) break; } + printf("EOD\n" + "set monochrome\n" + "set xdata time\n" + "set timefmt \"%%Y-%%m-%%d\"\n" + "set xtics format \"%%Y-%%m-%%d\" rotate by -30\n" + "set ylabel \"KJV memorized\"\n" + "set format y \"%%g%%%%\"\n" + "unset key #set key bottom right\n" + "set grid\n" + "unset border\n" + "plot $Data using 1:($3-$2)*100/%zu smooth cumulative " + "with steps lw 2\n", kj.total_words); goto finally; catch: success = EXIT_FAILURE;